Skip to content

Commit

Permalink
fix: update total_volume calculation to actually reflect volume
Browse files Browse the repository at this point in the history
  • Loading branch information
xmatthias committed Jan 22, 2025
1 parent 1d22cf9 commit 7f2e696
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions freqtrade/optimize/optimize_reports/optimize_reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,14 @@ def _generate_result_line(
}


def generate_pair_metrics(
def calculate_trade_volume(trades_dict: list[dict[str, Any]]) -> float:
# Aggregate the total volume traded from orders.cost.
# Orders is a nested dictionary within the trades list.

return sum(sum(order["cost"] for order in trade.get("orders", [])) for trade in trades_dict)


def generate_pair_metrics( #
pairlist: list[str],
stake_currency: str,
starting_balance: float,
Expand Down Expand Up @@ -431,8 +438,9 @@ def generate_strategy_stats(

expectancy, expectancy_ratio = calculate_expectancy(results)
backtest_days = (max_date - min_date).days or 1
trades_dict = results.to_dict(orient="records")
strat_stats = {
"trades": results.to_dict(orient="records"),
"trades": trades_dict,
"locks": [lock.to_json() for lock in content["locks"]],
"best_pair": best_pair,
"worst_pair": worst_pair,
Expand All @@ -444,7 +452,7 @@ def generate_strategy_stats(
"total_trades": len(results),
"trade_count_long": len(results.loc[~results["is_short"]]),
"trade_count_short": len(results.loc[results["is_short"]]),
"total_volume": float(results["stake_amount"].sum()),
"total_volume": calculate_trade_volume(trades_dict),
"avg_stake_amount": results["stake_amount"].mean() if len(results) > 0 else 0,
"profit_mean": results["profit_ratio"].mean() if len(results) > 0 else 0,
"profit_median": results["profit_ratio"].median() if len(results) > 0 else 0,
Expand Down

0 comments on commit 7f2e696

Please sign in to comment.