mirror of
https://ghfast.top/https://github.com/aeroxw/easy-tdx.git
synced 2026-09-12 19:14:16 +08:00
fix(backtest): max drawdown now correctly measures peak-to-trough percentage
Previous formula was: max(absolute_drawdown) / initial_capital, which exceeds 100% when the portfolio grows then drops (e.g. from 600k to 300k on a 100k initial = 300% drawdown, which is nonsensical). Fixed to use drawdown_pct (drawdown / peak) which is always in [0, 1]. This correctly measures the maximum percentage drop from the highest equity peak, matching the standard financial definition. Also added regression test: test_max_drawdown_never_exceeds_100_pct. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
5550702620
commit
46298e68d7
@@ -289,7 +289,7 @@ class BacktestEngine:
|
||||
BacktestResult with empty DataFrames
|
||||
"""
|
||||
perf = PerformanceAnalyzer(
|
||||
pd.DataFrame(columns=["total", "drawdown"]),
|
||||
pd.DataFrame(columns=["total", "drawdown", "drawdown_pct"]),
|
||||
pd.DataFrame(columns=["direction", "pnl", "rejected"]),
|
||||
).compute()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user