Improve formatting in drawdown calc

This commit is contained in:
Matthias 2024-02-19 07:09:23 +01:00 committed by Joe Schr
parent b6c19252c9
commit bb6c31c55a

View File

@ -143,8 +143,10 @@ def calculate_max_drawdown(trades: pd.DataFrame, *, date_col: str = 'close_date'
starting_balance=starting_balance starting_balance=starting_balance
) )
idxmin = max_drawdown_df['drawdown_relative'].idxmax() if relative \ idxmin = (
else max_drawdown_df['drawdown'].idxmin() max_drawdown_df['drawdown_relative'].idxmax()
if relative else max_drawdown_df['drawdown'].idxmin()
)
if idxmin == 0: if idxmin == 0:
raise ValueError("No losing trade, therefore no drawdown.") raise ValueError("No losing trade, therefore no drawdown.")
high_date = profit_results.loc[max_drawdown_df.iloc[:idxmin]['high_value'].idxmax(), date_col] high_date = profit_results.loc[max_drawdown_df.iloc[:idxmin]['high_value'].idxmax(), date_col]