diff --git a/core/backtesting/enhanced_engine.py b/core/backtesting/enhanced_engine.py index 2c85d47..93381f3 100644 --- a/core/backtesting/enhanced_engine.py +++ b/core/backtesting/enhanced_engine.py @@ -471,13 +471,20 @@ def run_enhanced_backtest(strategy_id, params, historical_data_df, symbol_name=N max_drawdown_clean = round(max_drawdown * 100, 2) if math.isfinite(max_drawdown) else 0.0 win_rate_clean = round(win_rate, 2) if math.isfinite(win_rate) else 0.0 - logger.info(f"Enhanced Backtest Complete: {len(trades)} trades, ${total_profit_clean:+.0f} profit, {win_rate_clean:.0f}% win rate, ${total_spread_costs:.0f} spread costs") + gross_profit_clean = round(total_profit_clean + round(total_spread_costs, 2), 2) + + logger.info( + f"Enhanced Backtest Complete: {len(trades)} trades, " + f"gross ${gross_profit_clean:+.0f}, net ${total_profit_clean:+.0f}, " + f"{win_rate_clean:.0f}% win rate, ${total_spread_costs:.0f} spread costs" + ) return { "strategy_name": strategy_class.name, "instrument": instrument_symbol, "total_trades": len(trades), "final_capital": final_capital, + "gross_profit_usd": gross_profit_clean, "total_profit_usd": total_profit_clean, "total_spread_costs": round(total_spread_costs, 2), "net_profit_after_costs": round(total_profit_clean, 2), diff --git a/static/js/backtesting.js b/static/js/backtesting.js index 12cb936..af6ec93 100644 --- a/static/js/backtesting.js +++ b/static/js/backtesting.js @@ -111,9 +111,9 @@ document.addEventListener('DOMContentLoaded', () => { resultsContainer.classList.remove('hidden'); // Enhanced display with spread costs and protection info - const spreadCosts = data.total_spread_costs || 0; - const netProfit = data.net_profit_after_costs || data.total_profit_usd; - const grossProfit = data.total_profit_usd || 0; + const spreadCosts = data.total_spread_costs ?? 0; + const netProfit = data.net_profit_after_costs ?? data.total_profit_usd ?? 0; + const grossProfit = data.gross_profit_usd ?? (netProfit + spreadCosts); const instrument = data.instrument || 'UNKNOWN'; // Check if protection was applied