Diagnose failed or underperforming backtests, locate the root cause, and fix the issue
复制下面这句话,粘贴给 Claude Code、Codex、Cursor 等 AI 编程工具,它会读取安装说明并在你确认后完成安装。
请阅读 https://ai.atlankj.com/install/asset/gh-backtest-diagnose-6fc1afd9f2fa ,按照其中的说明把「backtest-diagnose」安装到你(当前 AI 工具)中。执行前先告诉我将运行的命令和写入的位置,等我确认。
查看 AI 将读取的安装说明正在读取 GitHub 原文…
内容来自 GitHub 原始文件,由原作者维护。在 GitHub 查看
Use this skill when a user reports that a backtest failed, raised an error, or produced poor results.
read_file to inspect artifacts/metrics.csv, equity.csv, and trades.csvread_file to inspect code/signal_engine.py and config.jsonedit_file to modify the code, then rerun the backtestread_file to inspect the new metrics.csvexit_code != 0)| Error Type | Common Cause | Fix |
|---|---|---|
| ImportError | Missing dependency | bash("pip install xxx") |
| KeyError | DataFrame column-name mismatch | Check the actual column names in data_map |
| IndexError | Empty data or insufficient length | Add length checks |
| TypeError | Incorrect signal type | Ensure the return value is pd.Series |
trade_count=0): signal-logic bug. Conditions are too strict, so the signal stays at 0. Check whether entry and exit logic is reasonable, and inspect the signal series to confirm it is not all zeros.dropna is too aggressive.| Symptom | Root Cause | Fix |
|---|---|---|
| No data fetched | Invalid API token or code issue | Check config.json |
| Too little data | Date range too narrow | Expand the date range |
If you encounter the following keywords, do not modify the code. The problem is on the data-provider side:
rate limitAPI limitdaily limitInformation (common in Tushare API responses)These issues require the user to check the API token, switch data sources, or wait for the quota to reset.
artifacts/metrics.csv exists and is non-emptyartifacts/equity.csv exists and is non-emptytrade_count > 0 (0 trades means a signal bug)NaNexit_code == 0This Hard-Gate Checklist is also the evidence ingestion gate for Strategy Discovery: a run failing any gate produces no evidence rows — never partial rows — and is skipped with a stable machine-readable token (hard-gate:exit-nonzero, hard-gate:metrics-missing, hard-gate:zero-trades, hard-gate:equity-empty, hard-gate:equity-nan). Diagnose and fix the failing gate as usual, rerun the backtest, then repopulate the evidence cache with refresh_strategy_evidence (agent tool / MCP tool, or vibe-trading strategy-evidence refresh --manifest <path>) so the fixed run becomes queryable evidence. See the strategy-discovery skill for the manifest format and the full gate list.
write_file, unless the structure is fundamentally brokenAfter modifying signal_engine.py, you must confirm:
bash("python -c \"import ast; ast.parse(open('code/signal_engine.py').read()); print('OK')\"")class SignalEngine: the file must define class SignalEnginedef generate: the class must contain a def generate methodaction_items Writing RulesAfter diagnosis, output actionable improvement suggestions:
"Change X from A to B" or "Add X logic in signal_engine.py""Change RSI threshold from 30 to 25 in signal_engine.py line 42""Add signals = signals.fillna(0) after signal calculation to prevent NaN propagation""Add a volume filter: skip buy signals when volume is below the 20-day average"