backtest-audit-kit
"I verify whether your strategy is real — or whether the backtest lied to you."
A tiny, dependency-free toolkit that audits a backtest the way an accountant audits a ledger and a QA engineer audits a test suite. It does not sell you returns; it finds the four ways a backtest most often lies.
回测审计 / 策略代码复核服务 — 一页说明与联系方式 → PORTFOLIO.md Backtest audits · strategy-code review — one-page overview → PORTFOLIO.md
一条命令(3 分钟)
python3 -m auditkit.cli your.csv --trials 50 # 不用装,纯标准库
pip install -e . && auditkit your.csv # 或者装上,用 auditkit 命令
给它一份交易/净值 CSV(date + equity,或 date + pnl / return),它只回三件事:
| 检查 | 问的问题 | 什么时候红 |
|---|---|---|
| look-ahead | 时间戳和成交价物理上可能吗 | 时间戳倒退、entry==exit 零持有、入场价落在该 bar 的 high/low 之外 = FAIL |
| multiple testing | 这个 Sharpe 能和「试了 N 次里最好的那次」分开吗 | 校正后 p ≥ 0.05 = FAIL(--trials 必须填你实际搜过的参数组数;在多个时间框架上各调过参数,再加 --timeframes N,N_eff = trials × timeframes;不填则标 UNVERIFIED,不冒充通过) |
| out-of-sample decay | 后半段还剩多少边 | 后半 SR ≤ 0 = FAIL,衰减 ≥ 50% = WARN |
多尺度搜索会单独标一行:同一策略在 5 个时间框架上各调 100 组 = N_eff 500,门槛按 500 算;若按 100 会判 PASS、按 500 判 FAIL,会额外出一条 WARN 说明膨胀。
退出码:0 全过 · 1 有 FAIL · 2 有缺输入判不了的项。加 --ohlc bars.csv(date, high, low)才能判价格级前视;--json 给机器读;--split 0.6 改样本内比例。
One command (3 minutes)
python3 -m auditkit.cli your.csv --trials 50 prints three verdicts — look-ahead,
multiple-testing (deflated Sharpe), out-of-sample decay — from a plain CSV
(date + equity, or pnl / return). Exit code 0 = pass, 1 = FAIL, 2 = needs input.
Without --trials the multiple-testing line says UNVERIFIED instead of inventing a pass.
Tuned the same grid on several time frames? Add --timeframes N — effective trials become
trials × N, and the tool prints the inflated N and, when it flips the verdict, a WARN line.
--ohlc bars.csv unlocks the price-level look-ahead check.
English
What it is. A pure standard-library (Python 3.9+) kit of four independent checkers for a trading backtest:
| Checker | Question it answers |
|---|---|
checks/lookahead.py |
Does any decision on bar i see bars i+1...? (AST-based future-function lint) |
checks/invariants.py |
Does the ledger obey accounting invariants? (equity identity, wd_cum carry, monotonic counters, non-negative balances) |
checks/mutants.py |
Which bugs would your test suite not catch? (mutation testing; survivors = coverage blind spots) |
checks/fees.py |
Are fees two-sided, funding charged per bar, and slippage counted once per fill? |
checks/bust_revival.py |
After a ruin check, does the account get reset to 1% and keep trading? (see cases/case10_bust_revival.md) |
Who it is for. Quant developers, prop-desk researchers, and anyone who has ever shipped a strategy that looked great in a notebook and died in production. If you are reviewing someone else's backtest — or your own — this gives you a checklist, reproduction scripts, and before/after numbers instead of opinions.
What I deliver. ① A ranked findings list plus a runnable reproduction script for each problem. ② A minimal fix patch. ③ A before/after reconciliation of the headline numbers (win rate, net PnL, multiple, MDD, t-stat).
Three sample cases — this page summarizes three of the eleven write-ups in cases/:
- Look-ahead — the exit scan ran on the entry bar, so every signal knew its outcome. Fixed: 91 trades / 90.1% / +$214.37 → 26 trades / 65.4% / -$0.12; a tick-level re-run gives 27 trades / 66.7% / +$0.37. The leak was worth ≈ $214 of imaginary PnL — the whole profit.
- Withdrawal accounting — the bust path dropped
wd_cum(10 return sites). It only fires when a run busts: at lev 1.2 the published config never busts, so 7.82x → 7.82x; at lev 5 it busts once and 0.00x → 5.97x. The ~27x gap between 215.27x (no withdrawal) and 7.82x (double-keep-half) is withdrawal policy, not the bug — an earlier version of this page paired those two and mis-attributed it. - Drawdown metric — the circuit-breaker reset the running peak, so the
"reported MDD" was only the local drawdown. Same run, same config:
investor-view raw drawdown 98.7% vs reported 53.1% — a 45.6 pp
gap. Conclusion: MDD must be written twice (breaker-local and raw).
(Bonus case 4: 5-minute bar clustering inflated
n~11x and turned t = 15.60 into t = 1.75 after a 24h cooldown.)
Two public cases, both answered and followed by a change — threads outside this repo; one-page PDF: audits/2026-11-01-two-public-cases.pdf.
| Thread | The number I questioned | What happened |
|---|---|---|
| mr-scrooge-v6 #9 | -$1,308.74 over 1,041 trades (t ~ -3.0) | accepted; ratchet re-tightened, config bug fixed (B-142 to B-145) |
| pineforge-engine #664 | 341 of 7,989 probes graded at a 100x wider PnL tolerance | accepted; regrade of all 7,989 due 2026-11-04 |
Full write-up: audits/2026-11-01-two-public-cases.md. Not paid work, and not a track record: 23 public threads opened, 7 answered (30%), 0 paid.
What a deliverable looks like - audits/2026-11-01-sample-verification-report.pdf. One page, on a public live record recomputed from its own daily file: six numbers side by side, two convention gaps explained, one command to re-run. That result was no error found - which is also a result.
Install.
pip install backtest-audit-kit
Use it in code (four checkers, pure standard library):
from auditkit.checks import lookahead
findings = lookahead.detect_file("strategy.py") # future-data lint
print(lookahead.format_findings(findings))
How to run.
cd portfolio/backtest-audit-kit
python3 -m unittest discover tests # stdlib only, no install
# or, if you have pytest:
python3 -m pytest tests/ -q
python3 examples/run_demo.py # see all four checkers in action
Honesty note. The look-ahead checker is a heuristic linter, not a proof
engine: it flags the shapes that leak, and a stand-alone forward-simulation
pass is reported MEDIUM for human review rather than being declared safe.
Mutation testing reports blind spots; it never claims your strategy is
profitable. No checker here predicts returns.
中文
是什么。 一个纯 Python 标准库(3.9+)实现的回测审计工具包,四个互相独立 的检查器:
| 检查器 | 回答的问题 |
|---|---|
checks/lookahead.py |
在 bar i 上的决策,是否读到了 i+1... 的数据?(基于 AST 的前视/未来函数检测) |
checks/invariants.py |
账本是否满足会计不变量?(权益恒等式、wd_cum 结转、计数器单调、余额非负) |
checks/mutants.py |
你的测试套件抓不到哪些 bug?(变异测试;存活的变异体 = 覆盖盲区) |
checks/fees.py |
手续费是否双边计、资金费是否逐 bar 计、滑点是否每笔只算一次? |
checks/bust_revival.py |
爆仓检查之后,账户是否被重置成 1% 继续交易?(见 cases/case10_bust_revival.md) |
给谁用。 量化开发者、自营研究岗、以及任何"回测很美、实盘就死"过的 人。带看别人的回测(或自己的)时,它给你的是问题清单 + 复现脚本 + 修复前后 的数字,而不是一句"我觉得不太行"。
交付物承诺。 ① 按严重度排序的问题清单,每个问题配一个可运行的复现脚本。 ② 最小修复补丁。③ 修复前后的对账数字(胜率 / 净利 / 倍数 / 回撤 / t 值)。
三个案例摘要(本页只摘三份;cases/ 里另有完整 11 份):
- 前视 bug —— 出场扫描写在开仓 bar 的循环内,每个信号都提前知道结果。 修复后:91 笔 / 90.1% / +$214.37 → 26 笔 / 65.4% / -$0.12;tick 级 复跑得 27 笔 / 66.7% / +$0.37。这个泄漏值 约 $214 的虚假收益, 即全部利润。
- 提现会计 bug —— 爆仓返程丢了
wd_cum(引擎里有 10 处这样的 return)。 它只在爆仓时触发:lev 1.2 的公开配置全程 0 爆仓 ⇒ 7.82x → 7.82x, 一分不变;lev 5 爆仓一次 ⇒ 0.00x → 5.97x。215.27x 与 7.82x 之间那 27 倍 是提现规则本身的代价(不提现 vs 翻 2 留 1),不是 bug —— 早先这一页把 两个配置配成了一对,归因是错的,已改。 - 回撤口径 bug —— 熔断触发时把 peak 重置为 cap,"报告 MDD"只是每段熔断 后的局部回撤。同一次 run、同一配置:投资者口径 98.7% vs 报告 53.1%,差 45.6 个百分点。结论:MDD 必须双写(熔断口径 + 原始口径)。 (附赠案例 4:一段暴跌连打十几根 5min bar 让样本量虚增约 11 倍,t 值从 15.60 在 24h 冷却去重后掉到 1.75。)
两个公开案例(都在本仓库之外) —— 对方认账并改了代码;一页 PDF:audits/2026-11-01-two-public-cases.pdf。
| 帖子 | 我质疑的数字 | 结果 |
|---|---|---|
| mr-scrooge-v6 #9 | 1,041 笔合计 -$1,308.74(t ≈ -3.0) | 认账;收紧 ratchet,修掉配置加载 bug(B-142 至 B-145) |
| pineforge-engine #664 | 7,989 个 probe 里 341 个按宽 100 倍的 PnL 容差评分 | 认账;承诺 2026-11-04 前重跑全部 7,989 |
完整文字:audits/2026-11-01-two-public-cases.md。不是付费工作,也不是战绩:公开 23 条,7 条有回复(30%),付费 0。
第三份,性质不同:读源码。 APEX V2 [JOAT](开源 Pine,作者 JOAT)——不跑、不看净值,只把描述里的每个数字对回代码,查出六处对不上:面板上的 8.0σ 其实是 12 个标准差(分母带 * 1.5);confluence 分母 9 但输入上限 7;九个票里有俩测的是同一个 VWAP 偏离;Enable Trailing Stop 默认开着却永远触发不了(limit 和 trail_price 同价);Risk Per Trade % 算完没用(仓位走 default_qty_value=100);strategy() 无手续费无滑点。每条都带行号,附 sed 复现命令:audits/2026-11-01-apex-v2-code-audit.md。没有对方回复 —— TradingView 脚本页没有评论区(页面 706KB 里 comment 只出现两次,全是数据字段;相关 API 全 404),所以这份是"结论"而不是"回合"。
交付物长什么样 —— audits/2026-11-01-sample-verification-report.pdf。一页纸,靶子是一份公开的实盘记录,用他本人发布的逐日文件复算:六个数字逐行对照,两处口径差异讲清楚,附一条可重跑的命令。那次结论是「未发现错误」——这也是结果。
怎么跑。
cd portfolio/backtest-audit-kit
python3 -m unittest discover tests # 只用标准库,无需安装
# 若装了 pytest:
python3 -m pytest tests/ -q
python3 examples/run_demo.py # 四个检查器全跑一遍
诚实声明。 前视检查器是启发式 linter,不是证明器:它抓的是会泄漏的代码
形态,独立的"向前模拟"循环会被标为 MEDIUM 交人工复核,而不是被判安全。
变异测试只报告覆盖盲区,从不声称你的策略赚钱。本工具包不预测任何收益。
Also in this account · 另见
outpost/— 一个"只放能跑、能查、能被否证的东西"的据点: 单文件表格整理工具(零依赖、离线自检 14 项)+ 一份被自己推翻的回测(做空山寨无 edge)- 一次"两条腿都断了"的数据源修复。不写客户名、不写"我能做什么"。
Metadata
Release files for backtest-audit-kit 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| backtest_audit_kit-0.2.0.tar.gz | 38.2 kB | Without provenance | Details for backtest_audit_kit-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| backtest_audit_kit-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for backtest_audit_kit-0.2.0-py3-none-any.whl |
Total release size: 68.2 kB
Release files / backtest_audit_kit-0.2.0.tar.gz
| Download URL | backtest_audit_kit-0.2.0.tar.gz |
|---|---|
| Size | 38.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e1058c43516d26adcecf6ee98dc64017a6cc7a49fefa1bc8a74d6769b5ef7803
|
|
BLAKE2b-256 checksum How to use checksums |
f4f35c37440b6f34276c8df1f99a0369feb708d79a0bb6c21b6973efc0df2de4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.3
|
Release files / backtest_audit_kit-0.2.0-py3-none-any.whl
| Download URL | backtest_audit_kit-0.2.0-py3-none-any.whl |
|---|---|
| Size | 29.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f434f91df1742136f2270723825a5f9858e59aa807488ed55e09c34a851adc65
|
|
BLAKE2b-256 checksum How to use checksums |
1680ff99360e45fc2a63808214ad6337b5184dbbda84e10d2ccb05004fb91672
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.3
|
Security for backtest-audit-kit 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.