From b47948b604000c30dd934c5e0d72ef8f4135a1c2 Mon Sep 17 00:00:00 2001 From: ramseshk Date: Tue, 4 Aug 2026 08:56:22 +0000 Subject: [PATCH] Fix fee tier recalculation for historical backtests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Server: recalc endpoint now checks HISTORICAL_DIR as fallback when file not found in BACKTEST_DIR. Previously historical backtests returned "not found" on recalc. Frontend: renderBTDetail now accepts pnl_net/pnl_net_pct from recalc response (the endpoint returns pnl_net not pnl). Verified: VIP 0 → VIP 6 on OBI historical backtest changes net PnL from 54.31% to 66.57% with fees dropping $18.10 → $5.85. --- dashboard/server.py | 2 ++ dashboard/static/index.html | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/dashboard/server.py b/dashboard/server.py index dbb59a5..d0325c6 100644 --- a/dashboard/server.py +++ b/dashboard/server.py @@ -204,6 +204,8 @@ async def get_backtest(name: str): async def recalc_backtest(name: str, fee_tier: int = 0, staking_tier: str = "none"): """Recalculate backtest PnL with different fee tier.""" fpath = os.path.join(BACKTEST_DIR, f"{name}.json") + if not os.path.exists(fpath): + fpath = os.path.join(HISTORICAL_DIR, f"{name}.json") if not os.path.exists(fpath): return JSONResponse({"error": "not found"}, status_code=404) with open(fpath) as f: diff --git a/dashboard/static/index.html b/dashboard/static/index.html index 6fd7b50..aa322fe 100644 --- a/dashboard/static/index.html +++ b/dashboard/static/index.html @@ -306,8 +306,8 @@ function onFeeTierChange(){ // ═══════════ Render backtest detail with fee toggle ── function renderBTDetail(full){ - var pnl=feeOn?(full.pnl||0):(full.pnl_gross||full.pnl||0); - var pnlPct=feeOn?(full.pnl_pct||0):(full.pnl_gross_pct||full.pnl_pct||0); + var pnl=feeOn?(full.pnl_net||full.pnl||0):(full.pnl_gross||full.pnl||0); + var pnlPct=feeOn?(full.pnl_net_pct||full.pnl_pct||0):(full.pnl_gross_pct||full.pnl_pct||0); var fees=full.fees_total||0; var strat=full.strategy||''; document.getElementById('det-name').textContent=strat+(feeOn?' (net of fees)':' (gross, no fees)');