Color 期期 preview PnL and show RR vs full premium loss.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -121,6 +121,24 @@
|
||||
return '<span class="opt-moneyness opt-moneyness-' + m + '">' + label + "</span>";
|
||||
}
|
||||
|
||||
function pnlClass(v) {
|
||||
if (v == null || v === "") return "";
|
||||
const n = Number(v);
|
||||
if (Number.isNaN(n)) return "";
|
||||
return n >= 0 ? "hp-pnl-pos" : "hp-pnl-neg";
|
||||
}
|
||||
|
||||
function fmtPnlHtml(v, digits) {
|
||||
if (v == null || v === "" || Number.isNaN(Number(v))) return "—";
|
||||
const cls = pnlClass(v);
|
||||
return '<strong class="' + cls + '">' + fmt(v, digits) + "</strong>";
|
||||
}
|
||||
|
||||
function fmtRr(v) {
|
||||
if (v == null || Number.isNaN(Number(v))) return "—";
|
||||
return fmt(v, 2) + ":1";
|
||||
}
|
||||
|
||||
function matchesMoneyFilter(c) {
|
||||
const f = state.moneyFilter || "all";
|
||||
if (f === "all") return true;
|
||||
@@ -997,21 +1015,35 @@
|
||||
if (summary) {
|
||||
if (d.plan_type === "perp_options") {
|
||||
summary.innerHTML =
|
||||
"止盈合计 <strong>" +
|
||||
fmt(s.tp_total) +
|
||||
"</strong> · 止损合计 <strong>" +
|
||||
fmt(s.sl_total) +
|
||||
"</strong> · 保费 " +
|
||||
"止盈合计 " +
|
||||
fmtPnlHtml(s.tp_total) +
|
||||
" · 止损合计 " +
|
||||
fmtPnlHtml(s.sl_total) +
|
||||
" · 保费 " +
|
||||
fmt(s.premium_paid) +
|
||||
(s.hedge_ratio_at_sl != null ? " · 止损对冲率 " + fmt(s.hedge_ratio_at_sl) + "%" : "");
|
||||
} else {
|
||||
const upTot = s.at_target_up_total != null ? s.at_target_up_total : s.at_target_total;
|
||||
const dnTot = s.at_target_down_total;
|
||||
let rrLine = "";
|
||||
if (s.rr_at_up != null || s.rr_at_down != null) {
|
||||
rrLine =
|
||||
" · 盈亏比 上破 " +
|
||||
fmtRr(s.rr_at_up) +
|
||||
(dnTot != null ? " / 下破 " + fmtRr(s.rr_at_down) : "") +
|
||||
'<span class="muted">(亏=全额保费 ' +
|
||||
fmt(s.rr_risk_premium != null ? s.rr_risk_premium : s.premium_paid) +
|
||||
")</span>";
|
||||
}
|
||||
summary.innerHTML =
|
||||
"目标价合计 <strong>" +
|
||||
fmt(s.at_target_total) +
|
||||
"</strong> · 到期现价 <strong>" +
|
||||
fmt(s.expiry_flat_total) +
|
||||
"</strong> · 保费 " +
|
||||
"上破 " +
|
||||
fmtPnlHtml(upTot) +
|
||||
(dnTot != null ? " · 下破 " + fmtPnlHtml(dnTot) : "") +
|
||||
" · 到期现价 " +
|
||||
fmtPnlHtml(s.expiry_flat_total) +
|
||||
" · 保费 " +
|
||||
fmt(s.premium_paid) +
|
||||
rrLine +
|
||||
(s.expiry_is_loss ? " · 到期无盈利(记总亏损)" : "");
|
||||
}
|
||||
}
|
||||
@@ -1021,11 +1053,11 @@
|
||||
const tr = document.createElement("tr");
|
||||
let mid;
|
||||
if (sc.perp_pnl != null) {
|
||||
mid = "永续 " + fmt(sc.perp_pnl);
|
||||
mid = "永续 " + fmtPnlHtml(sc.perp_pnl);
|
||||
} else {
|
||||
mid = "A " + fmt(sc.leg_a_pnl) + " / B " + fmt(sc.leg_b_pnl);
|
||||
mid = "A " + fmtPnlHtml(sc.leg_a_pnl) + " / B " + fmtPnlHtml(sc.leg_b_pnl);
|
||||
}
|
||||
const optCol = sc.options_pnl != null ? fmt(sc.options_pnl) : "—";
|
||||
const optCol = sc.options_pnl != null ? fmtPnlHtml(sc.options_pnl) : "—";
|
||||
tr.innerHTML =
|
||||
"<td>" +
|
||||
(sc.label || sc.id) +
|
||||
@@ -1035,9 +1067,9 @@
|
||||
mid +
|
||||
"</td><td>" +
|
||||
optCol +
|
||||
"</td><td><strong>" +
|
||||
fmt(sc.total) +
|
||||
"</strong></td><td class=\"muted\">" +
|
||||
"</td><td>" +
|
||||
fmtPnlHtml(sc.total) +
|
||||
"</td><td class=\"muted\">" +
|
||||
(sc.note || "") +
|
||||
"</td>";
|
||||
tbody.appendChild(tr);
|
||||
|
||||
Reference in New Issue
Block a user