Add max trade duration to backtest results

This commit is contained in:
mrpabloyeah
2025-05-17 02:50:10 +02:00
parent 193cfb634c
commit 6d3ed84807
2 changed files with 8 additions and 0 deletions

View File

@@ -370,6 +370,7 @@ def text_table_add_metrics(strat_results: dict) -> None:
f"{strat_results['winning_days']} / "
f"{strat_results['draw_days']} / {strat_results['losing_days']}",
),
("Max trade duration", f"{strat_results['holding_max']}"),
("Avg. Duration Winners", f"{strat_results['winner_holding_avg']}"),
("Avg. Duration Loser", f"{strat_results['loser_holding_avg']}"),
(

View File

@@ -344,6 +344,11 @@ def generate_trading_stats(results: DataFrame) -> dict[str, Any]:
if not results.empty
else timedelta()
)
holding_max = (
timedelta(minutes=round(results["trade_duration"].max()))
if not results.empty
else timedelta()
)
winner_holding_avg = (
timedelta(minutes=round(winning_trades["trade_duration"].mean()))
if not winning_trades.empty
@@ -363,6 +368,8 @@ def generate_trading_stats(results: DataFrame) -> dict[str, Any]:
"winrate": len(winning_trades) / len(results) if len(results) else 0.0,
"holding_avg": holding_avg,
"holding_avg_s": holding_avg.total_seconds(),
"holding_max": holding_max,
"holding_max_s": holding_max.total_seconds(),
"winner_holding_avg": winner_holding_avg,
"winner_holding_avg_s": winner_holding_avg.total_seconds(),
"loser_holding_avg": loser_holding_avg,