Files
myquant/CLAUDE-agents.md
T
simon 6ec198687c feat(djapi): 新增日报查询 API(news/reports + news/events)及文档
- api/report/ 包:query(连库+SQL)/ views(2 视图)/ serializers(OpenAPI)/ tests(17 单测)
- urls.py 注册 news/reports/、news/events/;settings.py SPECTACULAR 加「日报」tag
- .env.example 补 NEWS_DB_* 占位配置;README/continuation.md 更新
- docs/news_report_api.md 使用手册;CLAUDE*.md 修正 CLI 路径为 finance/ 前缀
2026-08-05 20:51:42 +08:00

85 lines
3.6 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-agents.md — Agent 系统 + CLI
## Agent 架构
4 个 Agent,通过依赖注入复用已有引擎(不重建轮子)。
```python
from agents.orchestrator import AgentOrchestrator
orch = AgentOrchestrator(dm=dm, fe=fe, bt=bt, opt=opt, sent=sent)
orch.setup() # 注册 4 个 Agent
results = orch.run_daily() # 5 步流程
```
## 5 步每日流程
```
[Step 1/5] 增量同步 → 只更新已缓存股票 (0.04s/只)
[Step 2/5] 风险评估 → RiskAgent: high/medium/low + 仓位
[Step 3/5] 股票打分 → SelectionAgent: 多因子等权打分
[Step 4/5] 情绪因子 → SentimentEngine.compute()
[Step 5/5] 生成日报 → ReportAgent: .md + .html + 解读
```
## 各 Agent 职责
| Agent | 文件 | 职责 |
|-------|------|------|
| ResearchAgent | `research_agent.py` | 因子 IC/IC_IR 评估 |
| SelectionAgent | `selection_agent.py` | 多因子股票打分(等权) |
| RiskAgent | `risk_agent.py` | 波动率+回撤→仓位建议 |
| ReportAgent | `report_agent.py` | 市场+选股+情绪+风险→日报 |
## CLI (`finance/cli/agent_cli.py`)
```bash
python finance/cli/agent_cli.py daily # 5 步流程
python finance/cli/agent_cli.py picks 15 # 选股
python finance/cli/agent_cli.py risk # 风险评估
python finance/cli/agent_cli.py research # 因子研究
python finance/cli/agent_cli.py report 20260603 # 生成日报
python finance/cli/agent_cli.py warmup 50 # 首次预热缓存
```
## Demo 脚本 (`finance/cli/demo_*.py`)
全部支持 `--ts_code` `--date` 等参数。
| 脚本 | 用途 |
|------|------|
| `demo_data_manager.py` | Sprint 0: DB→建表→日线→同步 |
| `demo_factor_engine.py` | Sprint 1: 34因子→NaN检查→截面 |
| `demo_backtest.py` | Sprint 2: 5策略回测 |
| `demo_optimizer.py` | Sprint 3: Optuna寻优+Walk-Forward |
| `demo_ml.py` | Sprint 4: LightGBM+CatBoost+回测 |
| `demo_sentiment.py` | Sprint 5: 情绪因子快速验证 |
| `demo_sentiment_detail.py` | Sprint 5: 情绪因子详细演示(14参数) |
## 报告 (`finance/reports/`)
- `daily_YYYYMMDD.md` + `.html` — 每日双格式输出
- `storage.py``save_report()` / `query_reports()` → 存入 mac_report 表
- 日报包含"昨日对比"区块:标注数据是否与前一日相同
## ⚠️ 已知 Bug 速查(避免重复踩坑)
### B6: 5 日/20 日涨跌幅恒为 0
- **症状**: 日报中 `| +0.00% | +0.00% |`,实际数据应该有非零值
- **根因**: `idx = daily.index.get_loc(date) if date in daily.index else -1`,目标日期不在索引时 `-1 >= 5` → False,计算被短路
- **修复**: 用 `pos = len(daily) - 1` 替代 `idx = -1`,确保位置值非负
### B7: 两日报告完全一致
- **症状**: 20260604 和 20260605 报告的 TOP 15、风险评估完全一样
- **根因**: ① T+1 数据未产出,两份报告基于同一份 DB 快照 ② 多因子在 1 天内变化极小(非 bug,是特性)
- **缓解**: 日报增加"昨日对比"区块 + 数据截止标注
### B8: 风险回撤恒为 -52%
- **症状**: 不管哪天看,风险等级一直是 high,回撤一直是 -52%
- **根因**: RiskAgent 默认用 `market_index="000001.SZ"`(平安银行个股),其 2020 年历史高价导致永远极端回撤
- **修复**: 改为 `"000001.SH"`(上证指数)
### B9: report 命令只 sync 一只股票
- **症状**: generate_report 只调了 `dm.sync_daily("000001.SZ")`,其他 279 只不变
- **影响**: 日报的选股排名不会反映最新行情
- **状态**: 已加 sync 调用,范围仍为单只(全量 sync 走 `daily` 命令或 `warmup`