@@ -157,6 +157,17 @@ def max_drawdown(returns):
157
157
# Always convert to pandas Series
158
158
return pd .Series ([result ])
159
159
160
+ def realized_max_drawdown (starting_balance , df_pnl ):
161
+ """
162
+ Calculates the realized maximum drawdown as a percentage
163
+ """
164
+ cumulative_balance = starting_balance + df_pnl .cumsum ()
165
+ peak_balance = cumulative_balance .cummax ()
166
+ drawdown = peak_balance - cumulative_balance
167
+ drawdown_pct = (drawdown / peak_balance ) * 100
168
+ result = - drawdown_pct .max ()
169
+
170
+ return pd .Series ([result ])
160
171
161
172
def cagr (returns , rf = 0.0 , compounded = True , periods = 365 ):
162
173
"""
@@ -311,6 +322,7 @@ def trades(trades_list: List[ClosedTrade], daily_balance: list, final: bool = Tr
311
322
average_losing_holding_period = losing_trades ['holding_period' ].mean ()
312
323
gross_profit = winning_trades ['PNL' ].sum ()
313
324
gross_loss = losing_trades ['PNL' ].sum ()
325
+ realized_max_dd = realized_max_drawdown (starting_balance , df ['PNL' ]).iloc [0 ]
314
326
315
327
start_date = datetime .fromtimestamp (store .app .starting_time / 1000 )
316
328
date_index = pd .date_range (start = start_date , periods = len (daily_balance ))
@@ -366,6 +378,7 @@ def safe_convert(value, convert_type=float):
366
378
'gross_profit' : safe_convert (gross_profit ),
367
379
'gross_loss' : safe_convert (gross_loss ),
368
380
'max_drawdown' : safe_convert (max_dd ),
381
+ 'realized_max_drawdown' : safe_convert (realized_max_dd ),
369
382
'annual_return' : safe_convert (annual_return ),
370
383
'sharpe_ratio' : safe_convert (sharpe ),
371
384
'calmar_ratio' : safe_convert (calmar ),
0 commit comments