Avoid failure when calculating max-drawdown
occurs if if no winning trade is recorded.
This commit is contained in:
parent
e88a1ab209
commit
a0f9c1bf7b
@ -413,8 +413,9 @@ def calculate_max_drawdown(trades: pd.DataFrame, *, date_col: str = 'close_date'
|
|||||||
high_val = max_drawdown_df.loc[max_drawdown_df.iloc[:idxmin]
|
high_val = max_drawdown_df.loc[max_drawdown_df.iloc[:idxmin]
|
||||||
['high_value'].idxmax(), 'cumulative']
|
['high_value'].idxmax(), 'cumulative']
|
||||||
low_val = max_drawdown_df.loc[idxmin, 'cumulative']
|
low_val = max_drawdown_df.loc[idxmin, 'cumulative']
|
||||||
|
max_drawdown_rel = 0.0
|
||||||
max_drawdown_rel = (high_val - low_val) / (high_val + starting_balance)
|
if high_val + starting_balance != 0:
|
||||||
|
max_drawdown_rel = (high_val - low_val) / (high_val + starting_balance)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
abs(min(max_drawdown_df['drawdown'])),
|
abs(min(max_drawdown_df['drawdown'])),
|
||||||
|
Loading…
Reference in New Issue
Block a user