Fix stats max profit/loss to use win/loss subsets only.

Corrects misleading breakdown rows and summary max amounts after trade log edits.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-06-30 22:28:46 +08:00
parent d324d30332
commit 2386eca324
2 changed files with 16 additions and 6 deletions
+4 -4
View File
@@ -102,8 +102,8 @@ def _agg_metrics(label: str, items: list[dict]) -> dict:
pl_ratio = round(avg_profit / abs(avg_loss), 2) if wins and losses and avg_loss != 0 else 0.0
total_fee = round(sum(_fee(r) for r in items), 2)
total_net = round(sum(nets), 2)
max_loss = round(min(nets), 2) if nets else 0.0
max_profit = round(max(nets), 2) if nets else 0.0
max_loss = round(min(losses), 2) if losses else 0.0
max_profit = round(max(wins), 2) if wins else 0.0
win_rate = round(win_cnt / count * 100, 2) if count else 0.0
return {
"label": label,
@@ -177,8 +177,8 @@ def compute_summary(trades: list[dict], reviews: list[dict], live_capital: float
avg_loss = round(sum(losses) / len(losses), 2) if losses else 0.0
pl_ratio = round(avg_profit / abs(avg_loss), 2) if wins and losses and avg_loss != 0 else 0.0
total_fee = round(sum(_fee(t) for t in trades) + sum(_fee(r) for r in reviews), 2)
max_loss_amt = round(min(nets), 2) if nets else 0.0
max_profit_amt = round(max(nets), 2) if nets else 0.0
max_loss_amt = round(min(losses), 2) if losses else 0.0
max_profit_amt = round(max(wins), 2) if wins else 0.0
margins_loss = [
_margin_pct(_net_pnl(t), t.get("margin"))