@@ -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,
|
||||
|
||||
@@ -52,6 +52,12 @@
|
||||
{{ total_win_rate }}%
|
||||
</div>
|
||||
</div>
|
||||
<div class="stat-card">
|
||||
<div class="label">盈亏比</div>
|
||||
<div class="value" style="{% if profit_ratio >= 1 %}color:var(--danger-fg);{% else %}color:var(--success-fg);{% endif %}">
|
||||
{{ "%.2f"|format(profit_ratio) }}
|
||||
</div>
|
||||
</div>
|
||||
<div class="stat-card">
|
||||
<div class="label">净利润</div>
|
||||
<div class="value" style="{% if net_pnl > 0 %}color:var(--danger-fg);{% elif net_pnl < 0 %}color:var(--success-fg);{% endif %}">
|
||||
|
||||
Reference in New Issue
Block a user