From 6609b39f7b42461644adfd3cb0bbb371d94539c2 Mon Sep 17 00:00:00 2001 From: fish Date: Tue, 28 Jul 2026 15:31:16 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B9=B3=E4=BB=93=E6=B1=87=E6=80=BB=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=E7=9B=88=E4=BA=8F=E6=AF=94=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 4.7 --- ft-app/app/routers/summary.py | 36 ++++++++++++++++++++++++++++--- ft-app/app/templates/summary.html | 6 ++++++ 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/ft-app/app/routers/summary.py b/ft-app/app/routers/summary.py index eea7758..34ac1da 100644 --- a/ft-app/app/routers/summary.py +++ b/ft-app/app/routers/summary.py @@ -15,6 +15,8 @@ def _future_stats(records) -> dict: open_fee = 0.0 close_fee = 0.0 wins = 0 + profit_sum = 0.0 + loss_sum = 0.0 for t in records: mul = t.point_value if t.direction == "short": @@ -26,8 +28,12 @@ def _future_stats(records) -> dict: cf = t.close_fee or 0 open_fee += of close_fee += cf - if g - of - cf > 0: + net = g - of - cf + if net > 0: wins += 1 + profit_sum += net + elif net < 0: + loss_sum += net return { "count": total, "gross": gross, @@ -37,6 +43,8 @@ def _future_stats(records) -> dict: "open_fee": open_fee, "close_fee": close_fee, "total_fee": open_fee + close_fee, + "profit_sum": profit_sum, + "loss_sum": loss_sum, } @@ -46,6 +54,8 @@ def _option_stats(records) -> dict: open_fee = 0.0 close_fee = 0.0 wins = 0 + profit_sum = 0.0 + loss_sum = 0.0 for t in records: mul = t.point_value if t.direction == "sell": @@ -57,8 +67,12 @@ def _option_stats(records) -> dict: cf = t.close_fee or 0 open_fee += of close_fee += cf - if g - of - cf > 0: + net = g - of - cf + if net > 0: wins += 1 + profit_sum += net + elif net < 0: + loss_sum += net return { "count": total, "gross": gross, @@ -68,6 +82,8 @@ def _option_stats(records) -> dict: "open_fee": open_fee, "close_fee": close_fee, "total_fee": open_fee + close_fee, + "profit_sum": profit_sum, + "loss_sum": loss_sum, } @@ -77,6 +93,8 @@ def _dual_stats(records) -> dict: open_fee = 0.0 close_fee = 0.0 wins = 0 + profit_sum = 0.0 + loss_sum = 0.0 for t in records: mul = t.point_value call_g = (t.call_close_price - t.call_open_price) * mul @@ -87,8 +105,12 @@ def _dual_stats(records) -> dict: cf = (t.call_close_fee or 0) + (t.put_close_fee or 0) open_fee += of close_fee += cf - if g - of - cf > 0: + net = g - of - cf + if net > 0: wins += 1 + profit_sum += net + elif net < 0: + loss_sum += net return { "count": total, "gross": gross, @@ -98,6 +120,8 @@ def _dual_stats(records) -> dict: "open_fee": open_fee, "close_fee": close_fee, "total_fee": open_fee + close_fee, + "profit_sum": profit_sum, + "loss_sum": loss_sum, } @@ -131,6 +155,9 @@ def summary_page(request: Request, db: Session = Depends(get_db)): total_fee = future_stats["total_fee"] + option_stats["total_fee"] + dual_stats["total_fee"] total_wins = future_stats["wins"] + option_stats["wins"] + dual_stats["wins"] total_win_rate = round(total_wins / total_count * 100, 1) if total_count > 0 else 0 + total_profit = future_stats["profit_sum"] + option_stats["profit_sum"] + dual_stats["profit_sum"] + total_loss = future_stats["loss_sum"] + option_stats["loss_sum"] + dual_stats["loss_sum"] + profit_ratio = round(total_profit / abs(total_loss), 2) if total_loss != 0 else 0 template = request.app.state.templates.get_template("summary.html") return HTMLResponse( @@ -143,6 +170,9 @@ def summary_page(request: Request, db: Session = Depends(get_db)): total_wins=total_wins, total_win_rate=total_win_rate, total_fee=total_fee, + total_profit=total_profit, + total_loss=total_loss, + profit_ratio=profit_ratio, future_stats=future_stats, future_trades=future_trades, option_stats=option_stats, diff --git a/ft-app/app/templates/summary.html b/ft-app/app/templates/summary.html index 33fbac0..00d81fa 100644 --- a/ft-app/app/templates/summary.html +++ b/ft-app/app/templates/summary.html @@ -52,6 +52,12 @@ {{ total_win_rate }}% +
+
盈亏比
+
+ {{ "%.2f"|format(profit_ratio) }} +
+
净利润