Files
finance-talk/CLAUDE.md
T

89 lines
2.4 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
## Project Overview
AI 协助分析交易数据和回测的仓库。主要用来做策略回测、行情分析、期权定价、资产配置等量化相关操作。
## Python 执行环境
**仅允许使用 Docker 运行 Python**,严禁使用设备本地 Python
- **⚠️ 严禁直接 `docker run python:3.11-slim`**,必须先执行 `docker images` 确认本地已有镜像,优先复用
- 无可用镜像时才允许拉取,默认拉取 `python:3.11-slim`
- 示例: `docker images | grep python` 查看已有镜像,再用已有镜像执行
## 环境搭建(首次使用)
### 1. 创建容器
检查是否已有 `finance-talk` 容器(名称固定,在终端中运行):
```bash
docker ps -a --filter "name=finance-talk" --format "{{.Names}}"
```
若无输出,则按以下步骤创建:
```bash
# 查看已有 Python 镜像,优先复用
docker images | grep python
# 无可用镜像时才拉取(默认 python:3.11-slim
docker pull python:3.11-slim
# 创建并启动容器(映射当前目录到 /workspace)
docker run -d \
--name finance-talk \
-v $(pwd):/workspace \
-w /workspace \
python:3.13.11-slim \
sleep infinity
```
### 2. 安装依赖包
```bash
docker exec finance-talk pip install tushare akshare
```
### 3. 验证
```bash
docker exec finance-talk python -c "import tushare; import akshare; print('OK')"
```
### 4. 日常使用
Python 脚本通过 `docker exec` 在容器中执行:
```bash
docker exec finance-talk python your_script.py
```
若容器已存在但未运行,先启动:
```bash
docker start finance-talk
```
## Data Sources
按优先级排序:
1. **Tushare Pro** — 优先使用,数据最全(股票、期货、指数、期权等)
- Token: `76efd8465f9f2591aa42a385268e06acf6b80b7a15be2267ad2281b7`
- 用法: `import tushare as ts; ts.set_token('...'); pro = ts.pro_api()`
2. **akshare** — 备选,无需 token,覆盖面广
- A股指数: `ak.stock_zh_index_daily(symbol="sh000300")`
- 全球指数: `ak.index_global_hist_em(symbol="纳斯达克")`
- 个股: `ak.stock_zh_a_hist(symbol="600030", adjust="qfq")`
- 期货主连: `ak.futures_main_sina(symbol="FG0")`
3. **yfinance** — 海外市场(注意频次限制,需加 sleep)
## Conventions
- 期货主连代码格式: `FG0` (品种代码 + "0")
- A股个股复权方式: 前复权 (`adjust="qfq"`)