Separate gross vs net backtest profit display

This commit is contained in:
chrisnov-it
2026-05-19 19:41:49 +08:00
parent 01504ac9e3
commit 0c239418a6
2 changed files with 11 additions and 4 deletions
+8 -1
View File
@@ -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),
+3 -3
View File
@@ -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