前面 8 讲把研究跑通了;
今晚把它们收成能打开、能一起管的 HTML 报告。
CSV、PNG、短 README 都在,公开示例也有薄 HTML,但没有一份打开就能读完的九章报告。
reports/
├── strategy_examples/
│ ├── *.html
│ └── *_performance.png
├── lesson_06_multifactor_blind_validation/
│ ├── validation_report.md
│ ├── combination_performance_summary.csv
│ └── target_weights_*.parquet
├── lesson_07_etf18_logdiff_pca_ml/
│ ├── fold_metrics_lasso.csv
│ ├── overall_metrics.csv
│ └── README.md
├── lesson_07_etf18_horizon_sensitivity/
│ ├── comparison.csv
│ └── fold_metrics_h5_*.csv
同事发来一张净值图和一份指标 CSV,但没有写研究问题、样本和执行约定。
模板里就是这九个标题。少一章,别人就没法复核。
一份报告还没有与基准策略比较。作者想删掉“对照与稳健性”整章。
别的 skill 只交结果。图用 charts 画,网页用 ReportRenderer 拼。预览页只看指标,九章报告才能交出去。
%%{init: {"theme":"base","themeVariables":{"fontFamily":"PingFang SC, Microsoft YaHei, sans-serif","fontSize":"15px","primaryColor":"#d5e6ea","primaryTextColor":"#1a2a30","primaryBorderColor":"#2a4a54","lineColor":"#2a4a54","secondaryColor":"#fff8e8","tertiaryColor":"#f8e6e8"}}}%%
flowchart LR
IN["研究结果"] --> CH["charts 画图"]
CH --> P{"要哪种网页?"}
P -->|只要指标和曲线| D["自己调渲染器"]
D --> D1["预览页"]
P -->|要交得出去的研究| R["write_research_bundle"]
R --> R1["九章 index.html"]
R1 --> C["write_research_catalog"]
C --> C1["目录页"]
classDef ok fill:#d5e6ea,stroke:#2a4a54,stroke-width:2px,color:#1a2a30
classDef ask fill:#fff8e8,stroke:#2a4a54,stroke-width:2px,color:#1a2a30
classDef focus fill:#c5d9de,stroke:#2a4a54,stroke-width:2px,color:#1a2a30
class IN,CH,D,D1 ok
class P ask
class R,R1,C,C1 focus
| 约束 | 做法 | 漏了会怎样 |
|---|---|---|
| 字段 | 缺 question 或 metrics_source 就报错 | 写不出 HTML |
| 版式 | 九个中文 <h2> 写在同一份模板里 | 测试会检查标题齐不齐 |
| 图 | 只收 PNG,嵌进页面 | 不会出现有的图要外链才能看 |
| 路径 | 函数自己拼 reports/<namespace>/<slug>/index.html | 目录页才能稳定扫到 |
| 编目 | 同时有 index.html 和 params.json 才算一份 study | 旧的 CSV 堆不会混进总览 |
params.json,不上数据库。默认 private,不要提交。公开示例是薄 HTML 卡片,不是九章档案。write_research_bundle(report: ResearchReport, reports_root=None) -> Path
# 传入内存里填好的 ResearchReport。
# 不要丢一堆 CSV 路径,也不要自己指定 index.html 叫什么。
visibility。有图就要 png 或路径,有表就要 frame 或 htmlReportRenderer.render("research_report", …),再保存write_research_catalog()index.html 是九章正文,图已经嵌进去。params.json 给目录页用:标题、样本、指标摘要、数字来源。有指标时还会写出 artifacts/metrics.csv。question;metrics 和 metrics_source;成交约定 execution。图和表都可以空。reports/lesson_09/if_ma10_atr/index.html。一份报告用 bundle,全部报告用 catalog。%%{init: {"theme":"base","themeVariables":{"fontFamily":"PingFang SC, Microsoft YaHei, sans-serif","fontSize":"15px","primaryColor":"#d5e6ea","primaryTextColor":"#1a2a30","primaryBorderColor":"#2a4a54","lineColor":"#2a4a54","secondaryColor":"#fff8e8","tertiaryColor":"#f8e6e8"}}}%%
flowchart LR
U["上游只交结果"] --> A["填 ResearchReport"]
A -->|自己写 HTML| X["不允许"]
A -->|只交对象| Q{"字段齐全?"}
Q -->|缺了| E["报错,不写文件"]
Q -->|齐全| B["write_research_bundle"]
B --> F["index.html + params.json"]
F --> C{"要总览?"}
C -->|另调一次| CAT["catalog.html"]
C -->|先看这一份| H["打开 HTML"]
classDef ok fill:#d5e6ea,stroke:#2a4a54,stroke-width:2px,color:#1a2a30
classDef err fill:#f8e6e8,stroke:#7a3a42,stroke-width:2px,color:#7a3a42
classDef ask fill:#fff8e8,stroke:#2a4a54,stroke-width:2px,color:#1a2a30
class U,A,B,F,CAT,H ok
class X,E err
class Q,C ask
write_research_bundle。report skill 不算因子、不跑回测。回测 skill 已得到指标和图,团队准备让它自己拼出研究报告 HTML。
AGENTS.md 和 skills/report/SKILL.md。ResearchReport,走 write_research_bundle 写出九章 HTML,图嵌进页面。reports/lesson_09/if_ma10_atr/index.html,再另调一次编目。index.html 和 params.json。catalog.html 能点进这份报告;不要把 private 报告 git add 进去。这课不新开研究,不调参,也不报具体收益。规则第 5 课已经讲过。
空仓、且 MA10 / ATR14 算得出来时,close < MA10 就满仓;
止损只上移;close 跌破止损就空仓。
| 字段 | 课堂上怎么填 |
|---|---|
| 路径 | namespace=lesson_09,slug=if_ma10_atr → reports/lesson_09/if_ma10_atr/index.html |
| 品种 / 频率 | ["CFFEX.IF99"] · 1d |
| 成交约定 | 和第 5 课课堂上说的一致,写进报告正文 |
| visibility | private(默认不要提交) |
| metrics_source | BacktestResult.metrics,或写清 parquet / csv 路径 |
metrics_source 或 params.json 里找到同一来源。index.html 单独拷到桌面再打开。图还在,才算嵌进去了。AI 已根据第 5 课 IF 回测生成 index.html,却没说明报告中指标的来源。
做完 8 讲,本地会有一堆实验文件夹。没有总览,就只能凭记忆去翻。
write_research_catalog()
→ 扫描 reports/(跳过 README、catalog 自己)
→ 同时有 params.json 和 index.html → 收成一条
→ 只有 CSV/PNG → 还没写成报告,不进目录
→ 写出 reports/catalog.html 和 reports/catalog.json
index.html 的链接。catalog.json 只是把扫描结果存成文件,方便 Agent 读。下次生成会整份覆盖。报告几十到几百份时,扫目录足够快。index.html 的 CSV 堆,不会混进总览。有人补写成报告之后才会出现。strategy_examples 没有 params.json 和 index.html,不会自动编进来。某实验目录只有 comparison.csv 和 performance.png。现在运行 write_research_catalog()。