Also add min trade duration and display the info horizontally
This commit is contained in:
@@ -370,9 +370,18 @@ def text_table_add_metrics(strat_results: dict) -> None:
|
|||||||
f"{strat_results['winning_days']} / "
|
f"{strat_results['winning_days']} / "
|
||||||
f"{strat_results['draw_days']} / {strat_results['losing_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']}"),
|
"Min/Max/Avg. Duration Winners",
|
||||||
("Avg. Duration Loser", f"{strat_results['loser_holding_avg']}"),
|
f"{strat_results.get('winner_holding_min', 'N/A')} / "
|
||||||
|
f"{strat_results.get('winner_holding_max', 'N/A')} / "
|
||||||
|
f"{strat_results.get('winner_holding_avg', 'N/A')}",
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"Min/Max/Avg. Duration Losers",
|
||||||
|
f"{strat_results.get('loser_holding_min', 'N/A')} / "
|
||||||
|
f"{strat_results.get('loser_holding_max', 'N/A')} / "
|
||||||
|
f"{strat_results.get('loser_holding_avg', 'N/A')}",
|
||||||
|
),
|
||||||
(
|
(
|
||||||
"Max Consecutive Wins / Loss",
|
"Max Consecutive Wins / Loss",
|
||||||
(
|
(
|
||||||
|
|||||||
@@ -336,27 +336,44 @@ def generate_trading_stats(results: DataFrame) -> dict[str, Any]:
|
|||||||
}
|
}
|
||||||
|
|
||||||
winning_trades = results.loc[results["profit_ratio"] > 0]
|
winning_trades = results.loc[results["profit_ratio"] > 0]
|
||||||
|
winning_duratios = winning_trades["trade_duration"]
|
||||||
draw_trades = results.loc[results["profit_ratio"] == 0]
|
draw_trades = results.loc[results["profit_ratio"] == 0]
|
||||||
losing_trades = results.loc[results["profit_ratio"] < 0]
|
losing_trades = results.loc[results["profit_ratio"] < 0]
|
||||||
|
losing_duratios = losing_trades["trade_duration"]
|
||||||
|
|
||||||
holding_avg = (
|
holding_avg = (
|
||||||
timedelta(minutes=round(results["trade_duration"].mean()))
|
timedelta(minutes=round(results["trade_duration"].mean()))
|
||||||
if not results.empty
|
if not results.empty
|
||||||
else timedelta()
|
else timedelta()
|
||||||
)
|
)
|
||||||
holding_max = (
|
winner_holding_min = (
|
||||||
timedelta(minutes=round(results["trade_duration"].max()))
|
timedelta(minutes=round(winning_duratios[winning_duratios > 0].min()))
|
||||||
if not results.empty
|
if not winning_duratios.empty
|
||||||
|
else timedelta()
|
||||||
|
)
|
||||||
|
winner_holding_max = (
|
||||||
|
timedelta(minutes=round(winning_duratios.max()))
|
||||||
|
if not winning_duratios.empty
|
||||||
else timedelta()
|
else timedelta()
|
||||||
)
|
)
|
||||||
winner_holding_avg = (
|
winner_holding_avg = (
|
||||||
timedelta(minutes=round(winning_trades["trade_duration"].mean()))
|
timedelta(minutes=round(winning_duratios.mean()))
|
||||||
if not winning_trades.empty
|
if not winning_duratios.empty
|
||||||
|
else timedelta()
|
||||||
|
)
|
||||||
|
loser_holding_min = (
|
||||||
|
timedelta(minutes=round(losing_duratios[losing_duratios > 0].min()))
|
||||||
|
if not losing_duratios.empty
|
||||||
|
else timedelta()
|
||||||
|
)
|
||||||
|
loser_holding_max = (
|
||||||
|
timedelta(minutes=round(losing_duratios.max()))
|
||||||
|
if not losing_duratios.empty
|
||||||
else timedelta()
|
else timedelta()
|
||||||
)
|
)
|
||||||
loser_holding_avg = (
|
loser_holding_avg = (
|
||||||
timedelta(minutes=round(losing_trades["trade_duration"].mean()))
|
timedelta(minutes=round(losing_duratios.mean()))
|
||||||
if not losing_trades.empty
|
if not losing_duratios.empty
|
||||||
else timedelta()
|
else timedelta()
|
||||||
)
|
)
|
||||||
winstreak, loss_streak = calc_streak(results)
|
winstreak, loss_streak = calc_streak(results)
|
||||||
@@ -368,10 +385,16 @@ def generate_trading_stats(results: DataFrame) -> dict[str, Any]:
|
|||||||
"winrate": len(winning_trades) / len(results) if len(results) else 0.0,
|
"winrate": len(winning_trades) / len(results) if len(results) else 0.0,
|
||||||
"holding_avg": holding_avg,
|
"holding_avg": holding_avg,
|
||||||
"holding_avg_s": holding_avg.total_seconds(),
|
"holding_avg_s": holding_avg.total_seconds(),
|
||||||
"holding_max": holding_max,
|
"winner_holding_min": winner_holding_min,
|
||||||
"holding_max_s": holding_max.total_seconds(),
|
"winner_holding_min_s": winner_holding_min.total_seconds(),
|
||||||
|
"winner_holding_max": winner_holding_max,
|
||||||
|
"winner_holding_max_s": winner_holding_max.total_seconds(),
|
||||||
"winner_holding_avg": winner_holding_avg,
|
"winner_holding_avg": winner_holding_avg,
|
||||||
"winner_holding_avg_s": winner_holding_avg.total_seconds(),
|
"winner_holding_avg_s": winner_holding_avg.total_seconds(),
|
||||||
|
"loser_holding_min": loser_holding_min,
|
||||||
|
"loser_holding_min_s": loser_holding_min.total_seconds(),
|
||||||
|
"loser_holding_max": loser_holding_max,
|
||||||
|
"loser_holding_max_s": loser_holding_max.total_seconds(),
|
||||||
"loser_holding_avg": loser_holding_avg,
|
"loser_holding_avg": loser_holding_avg,
|
||||||
"loser_holding_avg_s": loser_holding_avg.total_seconds(),
|
"loser_holding_avg_s": loser_holding_avg.total_seconds(),
|
||||||
"max_consecutive_wins": winstreak,
|
"max_consecutive_wins": winstreak,
|
||||||
|
|||||||
Reference in New Issue
Block a user