WorkBuddy PandaData MCP 强制覆盖
本节优先于本 Skill 后续所有数据源、依赖安装和命令示例。WorkBuddy 版只允许使用已连接的
pandadata Connector:先调用 auth_status,再按共享 Runtime Skill 中的已登记路由调用
call_pandadata。本地 PandaData SDK、直接 HTTP、凭证文件和历史下载脚本在此版本中均
已禁用。必须执行空数据复查并在最终答案附完整调用回执;未打开 DATA_GATE 不得分析。
WorkBuddy PandaData MCP 强制覆盖
本节优先于本 Skill 后续所有数据源、依赖安装和命令示例。WorkBuddy 版只允许使用已连接的
pandadata Connector:先调用 auth_status,再按共享 Runtime Skill 中的已登记路由调用
call_pandadata。本地 PandaData SDK、直接 HTTP、凭证文件和历史下载脚本在此版本中均
已禁用。必须执行空数据复查并在最终答案附完整调用回执;未打开 DATA_GATE 不得分析。
WorkBuddy PandaData MCP 强制覆盖
本节优先于本 Skill 后续所有数据源、依赖安装和命令示例。WorkBuddy 版只允许使用已连接的
pandadata Connector:先调用 auth_status,再按共享 Runtime Skill 中的已登记路由调用
call_pandadata。本地 PandaData SDK、直接 HTTP、凭证文件和历史下载脚本在此版本中均
已禁用。必须执行空数据复查并在最终答案附完整调用回执;未打开 DATA_GATE 不得分析。
{
"version": 1,
"task": {
"placeholder": "请提供量化研报、论文、PDF、网页或文本,并说明期望复现范围",
"required": true
},
"fields": [
{
"key": "focus",
"label": "复现重点",
"type": "text",
"placeholder": "如:全文翻译、某个因子、有效性验证或回测策略"
}
],
"prompt_template": "{{#task}}任务与材料:\n{{task}}\n\n{{/task}}{{#attachments}}用户上传的材料(已放入工作区):\n{{attachments}}\n\n{{/attachments}}请端到端复现所给量化报告或论文{{#focus}},重点关注 {{focus}}{{/focus}}:完成中文全文翻译、研究摘要与因子公式重构、真实可溯源数据验证、无前视偏差的 BACKTEST 策略及本地回测、中文可读报告和最终交付摘要;无法执行的环节须如实记录,输出中文报告。"
}
Report Replication BACKTEST
Purpose
Turn a quant report, paper, PDF, webpage, or text source into a complete research delivery package under /home/coder/project/replication/report-replication:
- Full Chinese translation of the original report or paper.
- Chinese AI summary plus factor formula reconstruction in Markdown.
- Chinese factor validation report as standalone HTML, with charts, metrics, audit notes, and plain-language explanations for users who do not know quantitative jargon.
- BACKTEST strategy code plus a Chinese backtest explanation HTML. Preserve raw BACKTEST engine output separately when needed.
- Chinese final delivery summary.
This skill is self-contained for translation, factor reconstruction, factor validation, bundled local BACKTEST execution, optional external BACKTEST execution, and final delivery. Do not call any legacy framework-specific skills, scripts, data layers, examples, or assumptions.
Pandadata is the default production market-data source. Use WorkBuddy call_pandadata to download daily stock, index, futures, Hong Kong, or US market data into 03_factor_validation/data_cache/ before factor validation or BACKTEST. User-provided or report-supplied files may be used only when Pandadata does not cover the required dataset, and the fallback must be documented in manifest.json, the validation report, and the final summary.
Credentials must come from WorkBuddy-managed authentication, WorkBuddy-managed authentication, WorkBuddy-managed authentication, or WorkBuddy-managed authentication. Never write usernames, passwords, tokens, or raw credential files into generated artifacts, logs, commits, or reports. Record only that credential values were not persisted.
Language And Readability Rules
- All user-facing deliverables must use Chinese as the primary language:
full_translation.md, ai_summary_and_factor_formula.md, factor_validation_report.html, backtest_report.html, final_delivery_summary.md, and explanatory comments/docstrings in generated strategy code.
- English may appear only when unavoidable: original paper titles, proper names, formulas, code identifiers, CSV column names, API names, ticker/symbol names, metric abbreviations, and short parenthetical glossary labels such as
IC or Sharpe.
- Do not deliver English narrative sections, English-only reports, or mojibake/garbled Chinese. If a tool generates English or garbled HTML, wrap or rewrite it into a Chinese reader-facing artifact and preserve the raw file separately for audit.
- Before final delivery, spot-check the main readable files for Chinese readability rather than relying only on automated quality gates.
- Explain quant concepts as if the reader is smart but new to quant research. Prefer restrained science writing: concise, concrete, and evidence-led.
Chart Image Text Rules
- Text rendered inside generated chart image files must be English ASCII only. This includes PNG/SVG titles, subtitles, axis labels, legends, colorbar labels, annotation text, heatmap labels, in-image table headers, and watermarks.
- Keep Chinese explanations outside the image in the HTML/Markdown captions and chart explanation blocks. The report can remain Chinese-readable while the chart pixels stay font-compatible.
- When using Matplotlib, Seaborn, Plotly static export, or another image renderer, use broadly available Latin fonts such as
DejaVu Sans or Arial. Do not set CJK chart fonts such as SimHei, SimSun, Microsoft YaHei, Noto Sans CJK, or Source Han Sans.
- Prefer English chart labels from
references/factor_validation_checklist.md, for example Benchmark NAV Comparison, not Chinese translations. If the original factor/report name is Chinese, draw an ASCII-safe display label in the chart and keep the original Chinese name in the surrounding report text.
Required Output Contract
Create one project directory per report:
/home/coder/project/replication/report-replication/{report_id}/
01_translation/full_translation.md
02_factor_reproduction/ai_summary_and_factor_formula.md
02_factor_reproduction/reference_implementation.py
03_factor_validation/factor_validation_report.html
03_factor_validation/data/
03_factor_validation/data/ie_factor_matrix.csv
03_factor_validation/data/direction_matrix_from_strategy.csv
03_factor_validation/data/portfolio_returns_ew_full.csv
03_factor_validation/data/portfolio_returns_ew_is.csv
03_factor_validation/data/portfolio_returns_ew_oos.csv
03_factor_validation/data/portfolio_returns_dir_full.csv
03_factor_validation/data/portfolio_returns_dir_is.csv
03_factor_validation/data/portfolio_returns_dir_oos.csv
03_factor_validation/data/ic_series.csv
03_factor_validation/data/factor_diagnostics.csv
03_factor_validation/data/coverage_by_date.csv
03_factor_validation/data/missing_by_asset.csv
03_factor_validation/data/quantile_returns.csv
03_factor_validation/data/rolling_metrics.csv
03_factor_validation/data/yearly_performance.csv
03_factor_validation/data/turnover_series.csv
03_factor_validation/data/benchmark_comparison.csv
03_factor_validation/data/backtest_alignment_audit.csv
03_factor_validation/charts/
03_factor_validation/charts/01_ie_distribution.png
03_factor_validation/charts/02_ic_series.png
03_factor_validation/charts/03_is_oos_ic_comparison.png
03_factor_validation/charts/04_cumulative_nav_equal_weight.png
03_factor_validation/charts/05_cumulative_nav_strategy_direction.png
03_factor_validation/charts/06_drawdown.png
03_factor_validation/charts/07_ic_distribution.png
03_factor_validation/charts/08_rolling_ic.png
03_factor_validation/charts/09_quantile_nav.png
03_factor_validation/charts/10_quantile_return_bar.png
03_factor_validation/charts/11_yearly_return_heatmap.png
03_factor_validation/charts/12_turnover_series.png
03_factor_validation/charts/13_data_coverage_heatmap.png
03_factor_validation/charts/14_missing_value_heatmap.png
03_factor_validation/charts/15_benchmark_nav_comparison.png
03_factor_validation/charts/16_backtest_alignment_nav.png
03_factor_validation/charts/17_parameter_stability_heatmap.png
03_factor_validation/charts/18_cost_sensitivity.png
03_factor_validation/charts/19_walkforward.png
03_factor_validation/data_cache/
03_factor_validation/data_cache/pandadata_market_data.csv
03_factor_validation/data_cache/pandadata_market_data.csv.metadata.json
04_backtest_strategy/strategy.py
04_backtest_strategy/config.json
04_backtest_strategy/backtest_report.html
04_backtest_strategy/backtest_report_raw.html (optional raw BACKTEST engine report)
04_backtest_strategy/backtest_logs/signal_log.jsonl
04_backtest_strategy/backtest_logs/equity_curve.csv
04_backtest_strategy/backtest_logs/performance_metrics.csv
04_backtest_strategy/backtest_logs/trades.csv
04_backtest_strategy/backtest_logs/position_return_detail.csv
06_delivery/final_delivery_summary.md
failure_report.md
manifest.json
Read references/output_contract.md before writing final artifacts.
Honesty Rules
- Say exactly what was done. If a step was not run, state that it was not run.
- Do not fabricate walk-forward results, cost-sensitivity results, IC series, charts, backtest reports, or BACKTEST logs.
- If BACKTEST cannot run, or if data is unavailable or insufficient, document the blocker and mark the conclusion as inconclusive.
- Every chart, table, and metric in the HTML report must be traceable to a file under
03_factor_validation/data/, a chart under 03_factor_validation/charts/, or a BACKTEST artifact.
- Every chart and key metric in the HTML report must also be explained in plain language: what it means, how to read it, what the current result implies, and which data/artifact it came from.
Subagent Governance
This skill does not require subagents. Default to a single main-agent workflow unless the current task is too large and a subagent would materially reduce risk or time.
If a subagent/background agent is used:
- The main agent remains fully responsible for correctness and final delivery.
- Subagent outputs are drafts only. They must never be copied into final artifacts without main-agent review.
- Subagents must write only under
/home/coder/project/replication/report-replication/{report_id}/.agent_work/ or another explicitly isolated scratch directory.
- Subagents must not overwrite final artifacts such as
factor_validation_report.html, strategy.py, signal_log.jsonl, manifest.json, or delivery summaries.
- The main agent must independently verify formulas, data provenance, leakage checks, generated CSVs, charts, BACKTEST reports, and conclusions before promotion into final artifacts.
- The main agent must rerun the relevant step checks and final
quality_gate_check.py after integrating any subagent work.
- If any required stage fails, create
failure_report.md with the failed command, error, partial artifacts, likely cause, and next repair step.
Workflow
1. Initialize
Before creating or running the project, verify the local runtime dependencies:
python scripts/check_dependencies.py --install
Use Python 3.10 or newer for Pandadata. The default WorkBuddy pandadata Connector runtime reads local credentials from the current environment or WorkBuddy-managed authentication; it also requires requests at runtime.
Use scripts/create_project.py to create the output structure and manifest.json. The default root is /home/coder/project/replication/report-replication.
Download real Pandadata market data before validation and BACKTEST:
python WorkBuddy call_pandadata \
--asset-type stock \
--symbols 000001.SZ 600000.SH \
--start-date 20250101 \
--end-date 20250131 \
--output /home/coder/project/replication/report-replication/{report_id}/03_factor_validation/data_cache/pandadata_market_data.csv \
--project-dir /home/coder/project/replication/report-replication/{report_id}
Then use the bundled local BACKTEST engine by default:
python scripts/local_backtest.py /home/coder/project/replication/report-replication/{report_id} --market-data /home/coder/project/replication/report-replication/{report_id}/03_factor_validation/data_cache/pandadata_market_data.csv
The bundled engine reads real market data plus 04_backtest_strategy/backtest_logs/signal_log.jsonl, applies a configurable execution lag, estimates fees/slippage, and writes equity, trade, metric, alignment, raw, and Chinese HTML report artifacts. If the user explicitly supplies an external BACKTEST runner, use it only after documenting the entrypoint, command, config, and output mapping in manifest.json.
Record:
- Original input path or URL.
- Report title if known.
- Run date.
- Python executable and dependency report.
- BACKTEST engine entrypoint, version if known, command, config, and output files. For the bundled engine, record
scripts/local_backtest.py.
- Pandadata method, symbols/universe, sample period, frequency, adjustment rule, local cache path, metadata path, missing-value handling, assumptions, parameters, code hashes, and run history.
2. Extract And Translate
Deliver 01_translation/full_translation.md.
Requirements:
- It must be a full Chinese translation, not only English extraction.
- Preserve the original structure, page markers, section markers, table notes, chart captions, and formula explanations when extractable.
- Mark uncertain OCR/PDF extraction regions as
pending verification / 待核验.
- Do not invent missing formulas, table values, or chart notes.
After Step 2, run:
python scripts/check_step2_translation.py /home/coder/project/replication/report-replication/{report_id}
Do not move to Step 3 until the gate passes or the blocker is documented.
3. Reconstruct Factors
Deliver:
02_factor_reproduction/ai_summary_and_factor_formula.md
02_factor_reproduction/reference_implementation.py
The Markdown file must include the research question, conclusion, asset universe, sample period, rebalance frequency, data source, benchmark, factor formula, variable definitions, portfolio construction rules, assumptions, and bias checks.
The reference implementation must include factor calculation functions precise enough to audit the formula, including missing-value rules, standardization, ranking or grouping, regression model details when relevant, and rebalance timing.
After Step 3, run:
python scripts/check_step3_factor_reconstruction.py /home/coder/project/replication/report-replication/{report_id}
Do not move to factor validation until the gate passes or the blocker is documented.
4. Validate Factor Effectiveness
Use real, traceable market or research data. Default to Pandadata daily data downloaded with WorkBuddy call_pandadata when validating market-price factors or running BACKTEST. Prefer the Pandadata dataset that matches the report universe and BACKTEST configuration. Do not use synthetic, mock, or randomly generated market data to prove effectiveness. A fixed-seed random factor may only be used as a negative-control baseline on the same real return data as the target factor.
Validation is two-phase:
Step 3: factor reconstruction
-> Phase A: independent theoretical factor validation
Step 5: BACKTEST strategy and backtest
-> Phase B: alignment validation that consumes backtest_logs/signal_log.jsonl
At minimum evaluate:
- Data coverage, missingness, outliers, and factor distribution.
- IC, Rank IC, ICIR, IC t-statistic, positive IC ratio, IC distribution, yearly/quarterly IC, cumulative IC, and rolling IC.
- Quantile/group monotonicity, equal-weight portfolio returns, long-short returns, long-only/short-only legs when applicable, and strategy-direction portfolio returns.
- Full sample, in-sample, out-of-sample, and walk-forward when data allows.
- Drawdown, annual return, volatility, downside volatility, Sharpe, Sortino, Calmar, max drawdown, max drawdown duration, win rate, profit/loss ratio, skewness, kurtosis, VaR/CVaR, turnover, capacity/liquidity proxy when data allows, and yearly/monthly performance.
- Look-ahead, price leakage, data availability time, signal lag, execution price, cost assumptions, sample split, and overfitting controls.
- Parameter stability, cost sensitivity, reverse-factor baseline, fixed-seed random-factor baseline, equal-weight buy-and-hold baseline, zero-return/always-flat baseline, leave-one-asset-out or leave-one-sector-out robustness when data allows, and BACKTEST alignment.
Report readability requirements:
- Write the report in Chinese. English terms may appear only as short labels, metric abbreviations, formulas, or artifact names.
- Render every chart image with English ASCII text only; keep Chinese reader-facing explanations in the HTML below each image.
- Add a
How To Read This Report / 阅读指南 section near the top that explains the evidence chain from factor definition, bias audit, IC, portfolio test, OOS result, and BACKTEST result.
- Add a metric dictionary explaining at least IE, IC, Rank IC, ICIR, Positive IC Ratio, Annual Return, Annual Volatility, Sharpe, Calmar, Max DD, Win Rate, NAV, IS, and OOS.
- Under every chart, include a Chinese beginner-facing explanation block. It must be specific to that chart and contain:
这张图回答什么问题
怎么看
我们看到了什么
这意味着什么
数据来源
- Explain clearly that factor-validation NAV curves are not automatically BACKTEST actual account/equity curves:
04_cumulative_nav_equal_weight.png is a theoretical equal-weight factor-validation curve.
05_cumulative_nav_strategy_direction.png is a strategy-direction validation curve reconstructed from directions and return data.
- BACKTEST actual account/equity curves come from BACKTEST artifacts such as
04_backtest_strategy/backtest_report_raw.html, exported equity files, or log files.
- For futures, explain equal-weight vs equal-lot, contract multipliers, next-bar execution, fees, slippage, margin/capital allocation, and daily mark-to-market.
- Add a red/yellow/green (RAG) judgement table and conclusion scorecard. It must use objective metrics, not model opinion. At minimum score formula confidence, data coverage, leakage audit, IC direction, OOS portfolio result, full-sample portfolio risk/return, cost robustness, and BACKTEST actual result alignment.
- Add benchmark comparison against at least: reverse factor, fixed-seed random factor, equal-weight buy-and-hold, and zero-return / always-flat baseline. Save the benchmark returns or metrics under
03_factor_validation/data/.
- Add a BACKTEST alignment audit table comparing factor-validation curves with BACKTEST actual equity curves: data source, time range, frequency, weighting/execution assumptions, final NAV, max drawdown, and whether divergence is expected/explained.
- Produce the expanded factor-validation visual pack when data allows: IC distribution, rolling IC, quantile NAV, quantile return monotonicity bar chart, yearly/monthly performance heatmap, turnover series, data coverage heatmap, missing-value heatmap, benchmark NAV comparison, BACKTEST alignment NAV comparison, parameter stability heatmap, cost sensitivity chart, and walk-forward chart.
- If an expanded chart or metric cannot be produced, keep the section and state the exact blocker in Chinese.
- The report must be useful to a non-quant user without requiring them to inspect CSV files or BACKTEST internals.
Final conclusion must be one of: effective, weakly effective, ineffective, regime-dependent, or inconclusive.
Read references/factor_validation_checklist.md and references/factor_audit_and_robustness.md before judging effectiveness.
Use scripts/build_factor_report.py when a deterministic HTML scaffold is useful. The generated HTML must still satisfy references/output_contract.md and scripts/quality_gate_check.py.
5. Generate And Run BACKTEST Strategy
Generate BACKTEST strategy code only after factor logic is reconstructed and Phase A validation has been attempted.
Required behavior:
- Read
references/backtest_engine.md before writing or running Step 5.
- Convert the validated factor signal into executable strategy logic that writes
04_backtest_strategy/backtest_logs/signal_log.jsonl.
- Keep parameters clear: symbols, frequency, factor window, rebalance frequency, entry/exit rules, risk controls, fees, slippage, margin, and capital constraints.
- Run the bundled local BACKTEST engine with
scripts/local_backtest.py unless the user explicitly provides an external BACKTEST runner.
- Save or preserve BACKTEST's raw output as
04_backtest_strategy/backtest_report_raw.html.
- Deliver
04_backtest_strategy/backtest_report.html as a Chinese reader-facing backtest explanation report. It must summarize strategy logic, data, run artifacts, signal log, relationship to factor validation curves, known differences from theoretical validation, and link or point to the raw BACKTEST report if one exists.
- Save strategy logs under
04_backtest_strategy/backtest_logs/.
- Output
04_backtest_strategy/backtest_logs/signal_log.jsonl for Phase B alignment validation. Each line should be JSON: {"date": "YYYY-MM-DD", "signals": {"SYM": {"factor": float, "direction": 1|-1|0}}}.
- The bundled engine also writes
equity_curve.csv, performance_metrics.csv, trades.csv, and position_return_detail.csv.
After Step 5, run:
python scripts/check_step5_strategy.py /home/coder/project/replication/report-replication/{report_id}
Then update 03_factor_validation/factor_validation_report.html with Phase B alignment results.
6. Final Delivery Summary
Generate 06_delivery/final_delivery_summary.md after all available artifacts are complete. Keep it concise and decision-oriented:
- What the report says.
- Whether the factor is effective.
- Whether BACKTEST ran successfully.
- Where the reports, strategy, logs, and validation artifacts are.
- Key assumptions, risks, blockers, and next steps.
If any required stage fails, also create failure_report.md.
7. Run Quality Gate
Before final delivery, run:
python scripts/quality_gate_check.py /home/coder/project/replication/report-replication/{report_id}
If the command reports errors, do not deliver as complete. Fix the errors and rerun, or provide failure_report.md and state that the project is blocked rather than complete.
Quality Gates
Before final delivery, verify:
- All required artifact paths exist, or blockers are documented.
- The translation is complete enough to preserve the report structure.
- Every reconstructed formula has variables and assumptions.
02_factor_reproduction/reference_implementation.py exists and contains function-level reference code.
- Data preparation records Pandadata provider/method, cache path, metadata path, symbols, period, adjustment type, frequency, missing-value handling, and data availability assumptions. If a non-Pandadata source is used, the report must explain why Pandadata was insufficient.
- No credential values are written into
manifest.json, HTML/Markdown reports, logs, CSVs, or committed files.
- Factor validation uses real traceable data; no synthetic, mock, or random market data is used to prove effectiveness.
- If validation data is insufficient, the conclusion is inconclusive.
- Factor validation includes audit controls, IS/OOS or documented blocker, parameter stability, cost sensitivity or documented blocker, and baseline comparisons.
- The HTML report includes the required sections, charts, metrics, and traceable source captions.
- Chart explanation blocks are beginner-readable, chart-specific, non-mechanical, and include the five required parts.
04_backtest_strategy/backtest_report.html is a Chinese reader-facing explanation when the BACKTEST engine output is not Chinese-readable; any raw engine HTML is preserved separately and referenced.
- BACKTEST was actually run through
scripts/local_backtest.py or a documented external runner, or failure logs are saved.
06_delivery/final_delivery_summary.md exists, or failure_report.md explains why completion was blocked.
References
references/output_contract.md: required files and acceptance criteria.
references/factor_validation_checklist.md: factor validation metrics, charts, and conclusion standards.
references/factor_audit_and_robustness.md: leakage, look-ahead, overfitting, sample split, and robustness rules.
references/backtest_engine.md: BACKTEST strategy generation and execution rules.
references/data_sources.md: data source and provenance rules.
references/replication_lessons_learned.md: historical failure cases and guardrails.
1---2name: report-replication3description: Reproduce quantitative research reports and papers end to end: full Chinese translation, AI summary, factor formula reconstruction, factor effectiveness validation, standalone beginner-readable HTML factor report, BACKTEST strategy generation and local backtest execution, Chinese backtest explanation report, and final delivery summary. Use when the user provides a quant report/PDF/link/text and asks for report replication, factor replication, factor validation, BACKTEST strategy code, or a beginner-readable research replication package.4license: GPL-3.0-only5---6
7## WorkBuddy PandaData MCP 强制覆盖
8
9本节优先于本 Skill 后续所有数据源、依赖安装和命令示例。WorkBuddy 版只允许使用已连接的
10`pandadata` Connector:先调用 `auth_status`,再按共享 Runtime Skill 中的已登记路由调用
11`call_pandadata`。本地 PandaData SDK、直接 HTTP、凭证文件和历史下载脚本在此版本中均
12已禁用。必须执行空数据复查并在最终答案附完整调用回执;未打开 `DATA_GATE` 不得分析。
13
14## WorkBuddy PandaData MCP 强制覆盖
15
16本节优先于本 Skill 后续所有数据源、依赖安装和命令示例。WorkBuddy 版只允许使用已连接的
17`pandadata` Connector:先调用 `auth_status`,再按共享 Runtime Skill 中的已登记路由调用
18`call_pandadata`。本地 PandaData SDK、直接 HTTP、凭证文件和历史下载脚本在此版本中均
19已禁用。必须执行空数据复查并在最终答案附完整调用回执;未打开 `DATA_GATE` 不得分析。
20
21## WorkBuddy PandaData MCP 强制覆盖
22
23本节优先于本 Skill 后续所有数据源、依赖安装和命令示例。WorkBuddy 版只允许使用已连接的
24`pandadata` Connector:先调用 `auth_status`,再按共享 Runtime Skill 中的已登记路由调用
25`call_pandadata`。本地 PandaData SDK、直接 HTTP、凭证文件和历史下载脚本在此版本中均
26已禁用。必须执行空数据复查并在最终答案附完整调用回执;未打开 `DATA_GATE` 不得分析。
27
28```json qsh-form
29{
30 "version": 1,
31 "task": {
32 "placeholder": "请提供量化研报、论文、PDF、网页或文本,并说明期望复现范围",
33 "required": true
34 },
35 "fields": [
36 {
37 "key": "focus",
38 "label": "复现重点",
39 "type": "text",
40 "placeholder": "如:全文翻译、某个因子、有效性验证或回测策略"
41 }
42 ],
43 "prompt_template": "{{#task}}任务与材料:\n{{task}}\n\n{{/task}}{{#attachments}}用户上传的材料(已放入工作区):\n{{attachments}}\n\n{{/attachments}}请端到端复现所给量化报告或论文{{#focus}},重点关注 {{focus}}{{/focus}}:完成中文全文翻译、研究摘要与因子公式重构、真实可溯源数据验证、无前视偏差的 BACKTEST 策略及本地回测、中文可读报告和最终交付摘要;无法执行的环节须如实记录,输出中文报告。"
44}
45```
46
47# Report Replication BACKTEST
48
49## Purpose
50
51Turn a quant report, paper, PDF, webpage, or text source into a complete research delivery package under `/home/coder/project/replication/report-replication`:
52
531. Full Chinese translation of the original report or paper.
542. Chinese AI summary plus factor formula reconstruction in Markdown.
553. Chinese factor validation report as standalone HTML, with charts, metrics, audit notes, and plain-language explanations for users who do not know quantitative jargon.
564. BACKTEST strategy code plus a Chinese backtest explanation HTML. Preserve raw BACKTEST engine output separately when needed.
575. Chinese final delivery summary.
58
59This skill is self-contained for translation, factor reconstruction, factor validation, bundled local BACKTEST execution, optional external BACKTEST execution, and final delivery. Do not call any legacy framework-specific skills, scripts, data layers, examples, or assumptions.
60
61Pandadata is the default production market-data source. Use WorkBuddy `call_pandadata` to download daily stock, index, futures, Hong Kong, or US market data into `03_factor_validation/data_cache/` before factor validation or BACKTEST. User-provided or report-supplied files may be used only when Pandadata does not cover the required dataset, and the fallback must be documented in `manifest.json`, the validation report, and the final summary.
62
63Credentials must come from `WorkBuddy-managed authentication`, `WorkBuddy-managed authentication`, `WorkBuddy-managed authentication`, or `WorkBuddy-managed authentication`. Never write usernames, passwords, tokens, or raw credential files into generated artifacts, logs, commits, or reports. Record only that credential values were not persisted.
64
65## Language And Readability Rules
66
67- All user-facing deliverables must use Chinese as the primary language: `full_translation.md`, `ai_summary_and_factor_formula.md`, `factor_validation_report.html`, `backtest_report.html`, `final_delivery_summary.md`, and explanatory comments/docstrings in generated strategy code.
68- English may appear only when unavoidable: original paper titles, proper names, formulas, code identifiers, CSV column names, API names, ticker/symbol names, metric abbreviations, and short parenthetical glossary labels such as `IC` or `Sharpe`.
69- Do not deliver English narrative sections, English-only reports, or mojibake/garbled Chinese. If a tool generates English or garbled HTML, wrap or rewrite it into a Chinese reader-facing artifact and preserve the raw file separately for audit.
70- Before final delivery, spot-check the main readable files for Chinese readability rather than relying only on automated quality gates.
71- Explain quant concepts as if the reader is smart but new to quant research. Prefer restrained science writing: concise, concrete, and evidence-led.
72
73## Chart Image Text Rules
74
75- Text rendered inside generated chart image files must be English ASCII only. This includes PNG/SVG titles, subtitles, axis labels, legends, colorbar labels, annotation text, heatmap labels, in-image table headers, and watermarks.
76- Keep Chinese explanations outside the image in the HTML/Markdown captions and chart explanation blocks. The report can remain Chinese-readable while the chart pixels stay font-compatible.
77- When using Matplotlib, Seaborn, Plotly static export, or another image renderer, use broadly available Latin fonts such as `DejaVu Sans` or `Arial`. Do not set CJK chart fonts such as `SimHei`, `SimSun`, `Microsoft YaHei`, `Noto Sans CJK`, or `Source Han Sans`.
78- Prefer English chart labels from `references/factor_validation_checklist.md`, for example `Benchmark NAV Comparison`, not Chinese translations. If the original factor/report name is Chinese, draw an ASCII-safe display label in the chart and keep the original Chinese name in the surrounding report text.
79
80## Required Output Contract
81
82Create one project directory per report:
83
84```text
85/home/coder/project/replication/report-replication/{report_id}/
86 01_translation/full_translation.md
87 02_factor_reproduction/ai_summary_and_factor_formula.md
88 02_factor_reproduction/reference_implementation.py
89 03_factor_validation/factor_validation_report.html
90 03_factor_validation/data/
91 03_factor_validation/data/ie_factor_matrix.csv
92 03_factor_validation/data/direction_matrix_from_strategy.csv
93 03_factor_validation/data/portfolio_returns_ew_full.csv
94 03_factor_validation/data/portfolio_returns_ew_is.csv
95 03_factor_validation/data/portfolio_returns_ew_oos.csv
96 03_factor_validation/data/portfolio_returns_dir_full.csv
97 03_factor_validation/data/portfolio_returns_dir_is.csv
98 03_factor_validation/data/portfolio_returns_dir_oos.csv
99 03_factor_validation/data/ic_series.csv
100 03_factor_validation/data/factor_diagnostics.csv
101 03_factor_validation/data/coverage_by_date.csv
102 03_factor_validation/data/missing_by_asset.csv
103 03_factor_validation/data/quantile_returns.csv
104 03_factor_validation/data/rolling_metrics.csv
105 03_factor_validation/data/yearly_performance.csv
106 03_factor_validation/data/turnover_series.csv
107 03_factor_validation/data/benchmark_comparison.csv
108 03_factor_validation/data/backtest_alignment_audit.csv
109 03_factor_validation/charts/
110 03_factor_validation/charts/01_ie_distribution.png
111 03_factor_validation/charts/02_ic_series.png
112 03_factor_validation/charts/03_is_oos_ic_comparison.png
113 03_factor_validation/charts/04_cumulative_nav_equal_weight.png
114 03_factor_validation/charts/05_cumulative_nav_strategy_direction.png
115 03_factor_validation/charts/06_drawdown.png
116 03_factor_validation/charts/07_ic_distribution.png
117 03_factor_validation/charts/08_rolling_ic.png
118 03_factor_validation/charts/09_quantile_nav.png
119 03_factor_validation/charts/10_quantile_return_bar.png
120 03_factor_validation/charts/11_yearly_return_heatmap.png
121 03_factor_validation/charts/12_turnover_series.png
122 03_factor_validation/charts/13_data_coverage_heatmap.png
123 03_factor_validation/charts/14_missing_value_heatmap.png
124 03_factor_validation/charts/15_benchmark_nav_comparison.png
125 03_factor_validation/charts/16_backtest_alignment_nav.png
126 03_factor_validation/charts/17_parameter_stability_heatmap.png
127 03_factor_validation/charts/18_cost_sensitivity.png
128 03_factor_validation/charts/19_walkforward.png
129 03_factor_validation/data_cache/
130 03_factor_validation/data_cache/pandadata_market_data.csv
131 03_factor_validation/data_cache/pandadata_market_data.csv.metadata.json
132 04_backtest_strategy/strategy.py
133 04_backtest_strategy/config.json
134 04_backtest_strategy/backtest_report.html
135 04_backtest_strategy/backtest_report_raw.html (optional raw BACKTEST engine report)
136 04_backtest_strategy/backtest_logs/signal_log.jsonl
137 04_backtest_strategy/backtest_logs/equity_curve.csv
138 04_backtest_strategy/backtest_logs/performance_metrics.csv
139 04_backtest_strategy/backtest_logs/trades.csv
140 04_backtest_strategy/backtest_logs/position_return_detail.csv
141 06_delivery/final_delivery_summary.md
142 failure_report.md
143 manifest.json
144```
145
146Read `references/output_contract.md` before writing final artifacts.
147
148## Honesty Rules
149
150- Say exactly what was done. If a step was not run, state that it was not run.
151- Do not fabricate walk-forward results, cost-sensitivity results, IC series, charts, backtest reports, or BACKTEST logs.
152- If BACKTEST cannot run, or if data is unavailable or insufficient, document the blocker and mark the conclusion as inconclusive.
153- Every chart, table, and metric in the HTML report must be traceable to a file under `03_factor_validation/data/`, a chart under `03_factor_validation/charts/`, or a BACKTEST artifact.
154- Every chart and key metric in the HTML report must also be explained in plain language: what it means, how to read it, what the current result implies, and which data/artifact it came from.
155
156## Subagent Governance
157
158This skill does not require subagents. Default to a single main-agent workflow unless the current task is too large and a subagent would materially reduce risk or time.
159
160If a subagent/background agent is used:
161
162- The main agent remains fully responsible for correctness and final delivery.
163- Subagent outputs are drafts only. They must never be copied into final artifacts without main-agent review.
164- Subagents must write only under `/home/coder/project/replication/report-replication/{report_id}/.agent_work/` or another explicitly isolated scratch directory.
165- Subagents must not overwrite final artifacts such as `factor_validation_report.html`, `strategy.py`, `signal_log.jsonl`, `manifest.json`, or delivery summaries.
166- The main agent must independently verify formulas, data provenance, leakage checks, generated CSVs, charts, BACKTEST reports, and conclusions before promotion into final artifacts.
167- The main agent must rerun the relevant step checks and final `quality_gate_check.py` after integrating any subagent work.
168- If any required stage fails, create `failure_report.md` with the failed command, error, partial artifacts, likely cause, and next repair step.
169
170## Workflow
171
172### 1. Initialize
173
174Before creating or running the project, verify the local runtime dependencies:
175
176```bash
177python scripts/check_dependencies.py --install
178```
179
180Use Python 3.10 or newer for Pandadata. The default WorkBuddy `pandadata` Connector runtime reads local credentials from the current environment or `WorkBuddy-managed authentication`; it also requires `requests` at runtime.
181
182Use `scripts/create_project.py` to create the output structure and `manifest.json`. The default root is `/home/coder/project/replication/report-replication`.
183
184Download real Pandadata market data before validation and BACKTEST:
185
186```bash
187python WorkBuddy call_pandadata \
188 --asset-type stock \
189 --symbols 000001.SZ 600000.SH \
190 --start-date 20250101 \
191 --end-date 20250131 \
192 --output /home/coder/project/replication/report-replication/{report_id}/03_factor_validation/data_cache/pandadata_market_data.csv \
193 --project-dir /home/coder/project/replication/report-replication/{report_id}
194```
195
196Then use the bundled local BACKTEST engine by default:
197
198```bash
199python scripts/local_backtest.py /home/coder/project/replication/report-replication/{report_id} --market-data /home/coder/project/replication/report-replication/{report_id}/03_factor_validation/data_cache/pandadata_market_data.csv
200```
201
202The bundled engine reads real market data plus `04_backtest_strategy/backtest_logs/signal_log.jsonl`, applies a configurable execution lag, estimates fees/slippage, and writes equity, trade, metric, alignment, raw, and Chinese HTML report artifacts. If the user explicitly supplies an external BACKTEST runner, use it only after documenting the entrypoint, command, config, and output mapping in `manifest.json`.
203
204Record:
205
206- Original input path or URL.
207- Report title if known.
208- Run date.
209- Python executable and dependency report.
210- BACKTEST engine entrypoint, version if known, command, config, and output files. For the bundled engine, record `scripts/local_backtest.py`.
211- Pandadata method, symbols/universe, sample period, frequency, adjustment rule, local cache path, metadata path, missing-value handling, assumptions, parameters, code hashes, and run history.
212
213### 2. Extract And Translate
214
215Deliver `01_translation/full_translation.md`.
216
217Requirements:
218
219- It must be a full Chinese translation, not only English extraction.
220- Preserve the original structure, page markers, section markers, table notes, chart captions, and formula explanations when extractable.
221- Mark uncertain OCR/PDF extraction regions as `pending verification` / `待核验`.
222- Do not invent missing formulas, table values, or chart notes.
223
224After Step 2, run:
225
226```bash
227python scripts/check_step2_translation.py /home/coder/project/replication/report-replication/{report_id}
228```
229
230Do not move to Step 3 until the gate passes or the blocker is documented.
231
232### 3. Reconstruct Factors
233
234Deliver:
235
236- `02_factor_reproduction/ai_summary_and_factor_formula.md`
237- `02_factor_reproduction/reference_implementation.py`
238
239The Markdown file must include the research question, conclusion, asset universe, sample period, rebalance frequency, data source, benchmark, factor formula, variable definitions, portfolio construction rules, assumptions, and bias checks.
240
241The reference implementation must include factor calculation functions precise enough to audit the formula, including missing-value rules, standardization, ranking or grouping, regression model details when relevant, and rebalance timing.
242
243After Step 3, run:
244
245```bash
246python scripts/check_step3_factor_reconstruction.py /home/coder/project/replication/report-replication/{report_id}
247```
248
249Do not move to factor validation until the gate passes or the blocker is documented.
250
251### 4. Validate Factor Effectiveness
252
253Use real, traceable market or research data. Default to Pandadata daily data downloaded with WorkBuddy `call_pandadata` when validating market-price factors or running BACKTEST. Prefer the Pandadata dataset that matches the report universe and BACKTEST configuration. Do not use synthetic, mock, or randomly generated market data to prove effectiveness. A fixed-seed random factor may only be used as a negative-control baseline on the same real return data as the target factor.
254
255Validation is two-phase:
256
257```text
258Step 3: factor reconstruction
259 -> Phase A: independent theoretical factor validation
260Step 5: BACKTEST strategy and backtest
261 -> Phase B: alignment validation that consumes backtest_logs/signal_log.jsonl
262```
263
264At minimum evaluate:
265
266- Data coverage, missingness, outliers, and factor distribution.
267- IC, Rank IC, ICIR, IC t-statistic, positive IC ratio, IC distribution, yearly/quarterly IC, cumulative IC, and rolling IC.
268- Quantile/group monotonicity, equal-weight portfolio returns, long-short returns, long-only/short-only legs when applicable, and strategy-direction portfolio returns.
269- Full sample, in-sample, out-of-sample, and walk-forward when data allows.
270- Drawdown, annual return, volatility, downside volatility, Sharpe, Sortino, Calmar, max drawdown, max drawdown duration, win rate, profit/loss ratio, skewness, kurtosis, VaR/CVaR, turnover, capacity/liquidity proxy when data allows, and yearly/monthly performance.
271- Look-ahead, price leakage, data availability time, signal lag, execution price, cost assumptions, sample split, and overfitting controls.
272- Parameter stability, cost sensitivity, reverse-factor baseline, fixed-seed random-factor baseline, equal-weight buy-and-hold baseline, zero-return/always-flat baseline, leave-one-asset-out or leave-one-sector-out robustness when data allows, and BACKTEST alignment.
273
274Report readability requirements:
275
276- Write the report in Chinese. English terms may appear only as short labels, metric abbreviations, formulas, or artifact names.
277- Render every chart image with English ASCII text only; keep Chinese reader-facing explanations in the HTML below each image.
278- Add a `How To Read This Report` / `阅读指南` section near the top that explains the evidence chain from factor definition, bias audit, IC, portfolio test, OOS result, and BACKTEST result.
279- Add a metric dictionary explaining at least IE, IC, Rank IC, ICIR, Positive IC Ratio, Annual Return, Annual Volatility, Sharpe, Calmar, Max DD, Win Rate, NAV, IS, and OOS.
280- Under every chart, include a Chinese beginner-facing explanation block. It must be specific to that chart and contain:
281 - `这张图回答什么问题`
282 - `怎么看`
283 - `我们看到了什么`
284 - `这意味着什么`
285 - `数据来源`
286- Explain clearly that factor-validation NAV curves are not automatically BACKTEST actual account/equity curves:
287 - `04_cumulative_nav_equal_weight.png` is a theoretical equal-weight factor-validation curve.
288 - `05_cumulative_nav_strategy_direction.png` is a strategy-direction validation curve reconstructed from directions and return data.
289 - BACKTEST actual account/equity curves come from BACKTEST artifacts such as `04_backtest_strategy/backtest_report_raw.html`, exported equity files, or log files.
290 - For futures, explain equal-weight vs equal-lot, contract multipliers, next-bar execution, fees, slippage, margin/capital allocation, and daily mark-to-market.
291- Add a red/yellow/green (RAG) judgement table and conclusion scorecard. It must use objective metrics, not model opinion. At minimum score formula confidence, data coverage, leakage audit, IC direction, OOS portfolio result, full-sample portfolio risk/return, cost robustness, and BACKTEST actual result alignment.
292- Add benchmark comparison against at least: reverse factor, fixed-seed random factor, equal-weight buy-and-hold, and zero-return / always-flat baseline. Save the benchmark returns or metrics under `03_factor_validation/data/`.
293- Add a BACKTEST alignment audit table comparing factor-validation curves with BACKTEST actual equity curves: data source, time range, frequency, weighting/execution assumptions, final NAV, max drawdown, and whether divergence is expected/explained.
294- Produce the expanded factor-validation visual pack when data allows: IC distribution, rolling IC, quantile NAV, quantile return monotonicity bar chart, yearly/monthly performance heatmap, turnover series, data coverage heatmap, missing-value heatmap, benchmark NAV comparison, BACKTEST alignment NAV comparison, parameter stability heatmap, cost sensitivity chart, and walk-forward chart.
295- If an expanded chart or metric cannot be produced, keep the section and state the exact blocker in Chinese.
296- The report must be useful to a non-quant user without requiring them to inspect CSV files or BACKTEST internals.
297
298Final conclusion must be one of: effective, weakly effective, ineffective, regime-dependent, or inconclusive.
299
300Read `references/factor_validation_checklist.md` and `references/factor_audit_and_robustness.md` before judging effectiveness.
301
302Use `scripts/build_factor_report.py` when a deterministic HTML scaffold is useful. The generated HTML must still satisfy `references/output_contract.md` and `scripts/quality_gate_check.py`.
303
304### 5. Generate And Run BACKTEST Strategy
305
306Generate BACKTEST strategy code only after factor logic is reconstructed and Phase A validation has been attempted.
307
308Required behavior:
309
310- Read `references/backtest_engine.md` before writing or running Step 5.
311- Convert the validated factor signal into executable strategy logic that writes `04_backtest_strategy/backtest_logs/signal_log.jsonl`.
312- Keep parameters clear: symbols, frequency, factor window, rebalance frequency, entry/exit rules, risk controls, fees, slippage, margin, and capital constraints.
313- Run the bundled local BACKTEST engine with `scripts/local_backtest.py` unless the user explicitly provides an external BACKTEST runner.
314- Save or preserve BACKTEST's raw output as `04_backtest_strategy/backtest_report_raw.html`.
315- Deliver `04_backtest_strategy/backtest_report.html` as a Chinese reader-facing backtest explanation report. It must summarize strategy logic, data, run artifacts, signal log, relationship to factor validation curves, known differences from theoretical validation, and link or point to the raw BACKTEST report if one exists.
316- Save strategy logs under `04_backtest_strategy/backtest_logs/`.
317- Output `04_backtest_strategy/backtest_logs/signal_log.jsonl` for Phase B alignment validation. Each line should be JSON: `{"date": "YYYY-MM-DD", "signals": {"SYM": {"factor": float, "direction": 1|-1|0}}}`.
318- The bundled engine also writes `equity_curve.csv`, `performance_metrics.csv`, `trades.csv`, and `position_return_detail.csv`.
319
320After Step 5, run:
321
322```bash
323python scripts/check_step5_strategy.py /home/coder/project/replication/report-replication/{report_id}
324```
325
326Then update `03_factor_validation/factor_validation_report.html` with Phase B alignment results.
327
328### 6. Final Delivery Summary
329
330Generate `06_delivery/final_delivery_summary.md` after all available artifacts are complete. Keep it concise and decision-oriented:
331
332- What the report says.
333- Whether the factor is effective.
334- Whether BACKTEST ran successfully.
335- Where the reports, strategy, logs, and validation artifacts are.
336- Key assumptions, risks, blockers, and next steps.
337
338If any required stage fails, also create `failure_report.md`.
339
340### 7. Run Quality Gate
341
342Before final delivery, run:
343
344```bash
345python scripts/quality_gate_check.py /home/coder/project/replication/report-replication/{report_id}
346```
347
348If the command reports errors, do not deliver as complete. Fix the errors and rerun, or provide `failure_report.md` and state that the project is blocked rather than complete.
349
350## Quality Gates
351
352Before final delivery, verify:
353
354- All required artifact paths exist, or blockers are documented.
355- The translation is complete enough to preserve the report structure.
356- Every reconstructed formula has variables and assumptions.
357- `02_factor_reproduction/reference_implementation.py` exists and contains function-level reference code.
358- Data preparation records Pandadata provider/method, cache path, metadata path, symbols, period, adjustment type, frequency, missing-value handling, and data availability assumptions. If a non-Pandadata source is used, the report must explain why Pandadata was insufficient.
359- No credential values are written into `manifest.json`, HTML/Markdown reports, logs, CSVs, or committed files.
360- Factor validation uses real traceable data; no synthetic, mock, or random market data is used to prove effectiveness.
361- If validation data is insufficient, the conclusion is inconclusive.
362- Factor validation includes audit controls, IS/OOS or documented blocker, parameter stability, cost sensitivity or documented blocker, and baseline comparisons.
363- The HTML report includes the required sections, charts, metrics, and traceable source captions.
364- Chart explanation blocks are beginner-readable, chart-specific, non-mechanical, and include the five required parts.
365- `04_backtest_strategy/backtest_report.html` is a Chinese reader-facing explanation when the BACKTEST engine output is not Chinese-readable; any raw engine HTML is preserved separately and referenced.
366- BACKTEST was actually run through `scripts/local_backtest.py` or a documented external runner, or failure logs are saved.
367- `06_delivery/final_delivery_summary.md` exists, or `failure_report.md` explains why completion was blocked.
368
369## References
370
371- `references/output_contract.md`: required files and acceptance criteria.
372- `references/factor_validation_checklist.md`: factor validation metrics, charts, and conclusion standards.
373- `references/factor_audit_and_robustness.md`: leakage, look-ahead, overfitting, sample split, and robustness rules.
374- `references/backtest_engine.md`: BACKTEST strategy generation and execution rules.
375- `references/data_sources.md`: data source and provenance rules.
376- `references/replication_lessons_learned.md`: historical failure cases and guardrails.