Skip to content

Commit 7f2e696

Browse files
committed
fix: update total_volume calculation to actually reflect volume
closes freqtrade#11268
1 parent 1d22cf9 commit 7f2e696

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

freqtrade/optimize/optimize_reports/optimize_reports.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,14 @@ def _generate_result_line(
108108
}
109109

110110

111-
def generate_pair_metrics(
111+
def calculate_trade_volume(trades_dict: list[dict[str, Any]]) -> float:
112+
# Aggregate the total volume traded from orders.cost.
113+
# Orders is a nested dictionary within the trades list.
114+
115+
return sum(sum(order["cost"] for order in trade.get("orders", [])) for trade in trades_dict)
116+
117+
118+
def generate_pair_metrics( #
112119
pairlist: list[str],
113120
stake_currency: str,
114121
starting_balance: float,
@@ -431,8 +438,9 @@ def generate_strategy_stats(
431438

432439
expectancy, expectancy_ratio = calculate_expectancy(results)
433440
backtest_days = (max_date - min_date).days or 1
441+
trades_dict = results.to_dict(orient="records")
434442
strat_stats = {
435-
"trades": results.to_dict(orient="records"),
443+
"trades": trades_dict,
436444
"locks": [lock.to_json() for lock in content["locks"]],
437445
"best_pair": best_pair,
438446
"worst_pair": worst_pair,
@@ -444,7 +452,7 @@ def generate_strategy_stats(
444452
"total_trades": len(results),
445453
"trade_count_long": len(results.loc[~results["is_short"]]),
446454
"trade_count_short": len(results.loc[results["is_short"]]),
447-
"total_volume": float(results["stake_amount"].sum()),
455+
"total_volume": calculate_trade_volume(trades_dict),
448456
"avg_stake_amount": results["stake_amount"].mean() if len(results) > 0 else 0,
449457
"profit_mean": results["profit_ratio"].mean() if len(results) > 0 else 0,
450458
"profit_median": results["profit_ratio"].median() if len(results) > 0 else 0,

0 commit comments

Comments
 (0)