从PandaAI获取全市场股票日频数据教程
  18958283423 10天前 62 0

GitHub 网址:https://github.com/PandaAI-Tech/panda_factor?tab=readme-ov-file

一、环境准备

1.Python 3.9及以上

2.从GitHub上克隆项目到本地

 git clone https://github.com/your_org/panda_factor.git
 cd panda_factor

二、MongoDB 数据库安装

1.安装 MongoDB 8.x

数据库网盘链接: https://pan.baidu.com/s/1qnUFy7dw6O2yxa_0rE_2MQ?pwd=iayk 提取码: iayk
把下载好的数据库解压,与第一步获得的文件放在同个文件夹下,无需对文件进行改动。

三、运行数据库

  1. 在终端中进入 bin 目录,注意路径里有空格,一定要用引号或反斜杠
    cd “/your path/mongodb-macos-aarch64-8.0.8 2/bin”
  2. 给脚本加可执行权限(只需一次)
    chmod +x start_db.sh
  3. 后台启动
    ./start_db.sh start # macOS
    bin/db_start.bat # Windows

四、代码示范(在数据库运行时才可成功运行代码)

from panda_common.config import config as cfg
from panda_data.market_data.market_data_reader import MarketDataReader

reader = MarketDataReader(cfg)

# 1. 获取全市场股票代码
symbols = reader.get_all_symbols()
print("股票总数:", len(symbols))

# 2. 查询某一段日线行情
df = reader.get_market_data(
    symbols=['000001.SZ', '600519.SH'],
    start_date='20240101',
    end_date='20240630',
    fields=['open', 'high', 'low', 'close', 'volume']
)
print(df.head())

# 3. 取某月末沪深300成分股
csi300 = reader.get_market_data(
    start_date='20240531', end_date='20240531',
    indicator='000300', fields=['symbol']
)
print("2024-05-31 沪深300 数量:", csi300['symbol'].nunique())

五、数据库数据样式

image.png

最后一次编辑于 10天前 0

暂无评论