期期出场改盈亏比:达目标平盈利腿,亏损腿残值20%或到期平
将上/下破目标价替换为盈亏比(盈利金额/初始权利金,默认2);残值平需买一流动性且权利金≤初始20%。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -1166,12 +1166,9 @@
|
||||
renderListStrikes();
|
||||
renderTStrikes();
|
||||
if (d.index_px) {
|
||||
const idx = Number(d.index_px);
|
||||
if ($("hp-target-up") && !$("hp-target-up").value) {
|
||||
$("hp-target-up").value = String(Math.round(idx * 1.03));
|
||||
}
|
||||
if ($("hp-target-down") && !$("hp-target-down").value) {
|
||||
$("hp-target-down").value = String(Math.round(idx * 0.97));
|
||||
// 盈亏比默认2,不随指数自动改写
|
||||
if ($("hp-profit-rr") && !$("hp-profit-rr").value) {
|
||||
$("hp-profit-rr").value = "2";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1581,8 +1578,7 @@
|
||||
if ($("hp-contracts")) $("hp-contracts").value = "";
|
||||
if ($("hp-tp")) $("hp-tp").value = "";
|
||||
if ($("hp-sl")) $("hp-sl").value = "";
|
||||
if ($("hp-target-up")) $("hp-target-up").value = "";
|
||||
if ($("hp-target-down")) $("hp-target-down").value = "";
|
||||
if ($("hp-profit-rr")) $("hp-profit-rr").value = "2";
|
||||
if ($("hp-sel-inst")) $("hp-sel-inst").textContent = "—";
|
||||
if ($("hp-premium-line")) $("hp-premium-line").textContent = "";
|
||||
if ($("hp-oo-sheets-a")) {
|
||||
@@ -1618,16 +1614,12 @@
|
||||
if (!matchesOoMoneyFilter(state.legA) || !matchesOoMoneyFilter(state.legB)) {
|
||||
throw new Error("期期两腿须为平值或虚值,不可选实值");
|
||||
}
|
||||
const up = Number(($("hp-target-up") && $("hp-target-up").value) || 0);
|
||||
const down = Number(($("hp-target-down") && $("hp-target-down").value) || 0);
|
||||
if (!up || !down) throw new Error("请填写上破与下破目标价");
|
||||
if (up <= down) throw new Error("上破目标价必须大于下破目标价");
|
||||
const rr = Number(($("hp-profit-rr") && $("hp-profit-rr").value) || 0);
|
||||
if (!(rr > 0)) throw new Error("请填写盈亏比(须大于0,默认2)");
|
||||
body = {
|
||||
plan_type: "options_options",
|
||||
target_price_up: up,
|
||||
target_price_down: down,
|
||||
target_price: up,
|
||||
index_px: indexPx() || (up + down) / 2,
|
||||
profit_rr: rr,
|
||||
index_px: indexPx() || 0,
|
||||
leg_a: legPayload(state.legA, ooSheets("hp-oo-sheets-a")),
|
||||
leg_b: legPayload(state.legB, ooSheets("hp-oo-sheets-b")),
|
||||
};
|
||||
@@ -1719,22 +1711,28 @@
|
||||
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;
|
||||
const rrTarget = s.profit_rr != null ? s.profit_rr : null;
|
||||
let rrLine = "";
|
||||
if (s.rr_at_up != null || s.rr_at_down != null) {
|
||||
if (rrTarget != null) {
|
||||
rrLine =
|
||||
" · 目标盈亏比 " +
|
||||
fmt(rrTarget, 2) +
|
||||
'<span class="muted">(盈利金额/初始权利金)</span>';
|
||||
} else if (s.rr_at_up != null || s.rr_at_down != null) {
|
||||
rrLine =
|
||||
" · 盈亏比 上破 " +
|
||||
fmtRr(s.rr_at_up) +
|
||||
(dnTot != null ? " / 下破 " + fmtRr(s.rr_at_down) : "") +
|
||||
(s.at_target_down_total != null ? " / 下破 " + fmtRr(s.rr_at_down) : "") +
|
||||
'<span class="muted">(亏=全额保费 ' +
|
||||
fmt(s.rr_risk_premium != null ? s.rr_risk_premium : s.premium_paid) +
|
||||
")</span>";
|
||||
}
|
||||
const aTot = s.at_rr_a_full_total != null ? s.at_rr_a_full_total : s.at_target_up_total;
|
||||
const bTot = s.at_rr_b_full_total != null ? s.at_rr_b_full_total : s.at_target_down_total;
|
||||
summary.innerHTML =
|
||||
"上破 " +
|
||||
fmtPnlHtml(upTot) +
|
||||
(dnTot != null ? " · 下破 " + fmtPnlHtml(dnTot) : "") +
|
||||
(rrTarget != null ? "腿A达标 " : "上破 ") +
|
||||
fmtPnlHtml(aTot) +
|
||||
(bTot != null ? (rrTarget != null ? " · 腿B达标 " : " · 下破 ") + fmtPnlHtml(bTot) : "") +
|
||||
" · 到期现价 " +
|
||||
fmtPnlHtml(s.expiry_flat_total) +
|
||||
" · 保费 " +
|
||||
@@ -2057,8 +2055,7 @@
|
||||
"hp-tp",
|
||||
"hp-sl",
|
||||
"hp-sheets",
|
||||
"hp-target-up",
|
||||
"hp-target-down",
|
||||
"hp-profit-rr",
|
||||
]);
|
||||
if ($("hp-preview-btn"))
|
||||
$("hp-preview-btn").addEventListener("click", function () {
|
||||
@@ -2171,6 +2168,9 @@
|
||||
if (p.plan_type === "perp_options") {
|
||||
return "止盈 " + fmt(p.tp) + " · 止损 " + fmt(p.sl);
|
||||
}
|
||||
if (p.profit_rr != null && Number(p.profit_rr) > 0) {
|
||||
return "盈亏比 " + fmt(p.profit_rr, 2);
|
||||
}
|
||||
return "上破 " + fmt(p.target_price_up || p.target_price) + " · 下破 " + fmt(p.target_price_down || p.target_price);
|
||||
}
|
||||
|
||||
@@ -2330,8 +2330,9 @@
|
||||
target_win_leg: "期期平盈利腿",
|
||||
target_up_win_leg: "期期上破·平盈利腿",
|
||||
target_down_win_leg: "期期下破·平盈利腿",
|
||||
oo_rest_closing: "期期全平·清残腿中",
|
||||
oo_rest_closed: "期期全平·两腿已平",
|
||||
profit_rr_win_leg: "期期盈亏比达标·平盈利腿",
|
||||
oo_rest_closing: "期期残值平·清亏损腿中",
|
||||
oo_rest_closed: "期期残值平·两腿已平",
|
||||
orphaned_after_tp: "止盈后持有至到期",
|
||||
orphaned_option_expiry: "残腿到期",
|
||||
hold_to_expiry: "持有至到期",
|
||||
@@ -2405,12 +2406,19 @@
|
||||
fmt(p.perp_size, 4) +
|
||||
"</div>";
|
||||
} else {
|
||||
html +=
|
||||
"<div><span class=\"muted\">目标价</span> 上破 " +
|
||||
fmt(p.target_price_up || p.target_price) +
|
||||
" · 下破 " +
|
||||
fmt(p.target_price_down || p.target_price) +
|
||||
"</div>";
|
||||
if (p.profit_rr != null && Number(p.profit_rr) > 0) {
|
||||
html +=
|
||||
"<div><span class=\"muted\">盈亏比</span> " +
|
||||
fmt(p.profit_rr, 2) +
|
||||
" <span class=\"muted\">(盈利金额/初始权利金)</span></div>";
|
||||
} else {
|
||||
html +=
|
||||
"<div><span class=\"muted\">目标价</span> 上破 " +
|
||||
fmt(p.target_price_up || p.target_price) +
|
||||
" · 下破 " +
|
||||
fmt(p.target_price_down || p.target_price) +
|
||||
"</div>";
|
||||
}
|
||||
}
|
||||
html +=
|
||||
"<div><span class=\"muted\">权利金合计</span> " +
|
||||
@@ -2626,17 +2634,13 @@
|
||||
if (!matchesOoMoneyFilter(state.legA) || !matchesOoMoneyFilter(state.legB)) {
|
||||
throw new Error("期期两腿须为平值或虚值,不可选实值");
|
||||
}
|
||||
const up = Number(($("hp-target-up") && $("hp-target-up").value) || 0);
|
||||
const down = Number(($("hp-target-down") && $("hp-target-down").value) || 0);
|
||||
if (!up || !down) throw new Error("请填写上破与下破目标价");
|
||||
if (up <= down) throw new Error("上破目标价必须大于下破目标价");
|
||||
const rr = Number(($("hp-profit-rr") && $("hp-profit-rr").value) || 0);
|
||||
if (!(rr > 0)) throw new Error("请填写盈亏比(须大于0,默认2)");
|
||||
body = {
|
||||
plan_type: "options_options",
|
||||
underlying: state.underlying,
|
||||
target_price_up: up,
|
||||
target_price_down: down,
|
||||
target_price: up,
|
||||
index_px: indexPx() || (up + down) / 2,
|
||||
profit_rr: rr,
|
||||
index_px: indexPx() || 0,
|
||||
oo_close_mode: state.ooCloseModeEnabled ? state.ooCloseMode : "hold_expiry",
|
||||
oo_sheets_mode: state.ooSheetsMode || "same_sheets",
|
||||
leg_a: legPayload(state.legA, ooSheets("hp-oo-sheets-a")),
|
||||
|
||||
@@ -1444,21 +1444,37 @@
|
||||
function renderTargetDelegateRow(p) {
|
||||
const inst = p.inst_id || "";
|
||||
const hedgeTarget = p.hedge_plan_target || null;
|
||||
if (hedgeTarget && Number(hedgeTarget.target_index) > 0) {
|
||||
const side = (p.opt_type || hedgeTarget.opt_type || "").toUpperCase() === "P" ? "Put ≤" : "Call ≥";
|
||||
return (
|
||||
'<div class="opt-target-row opt-target-row--managed">' +
|
||||
'<span class="opt-target-row-label">对冲计划</span>' +
|
||||
'<span class="opt-target-armed">计划 #' +
|
||||
hedgeTarget.plan_id +
|
||||
" · " +
|
||||
side +
|
||||
" " +
|
||||
fmt(hedgeTarget.target_index, 1) +
|
||||
"</span>" +
|
||||
'<span class="muted opt-target-row-hint">进行中 · 由对冲计划监控,到位后仅平盈利腿</span>' +
|
||||
"</div>"
|
||||
);
|
||||
if (hedgeTarget) {
|
||||
const rr = hedgeTarget.profit_rr != null ? Number(hedgeTarget.profit_rr) : null;
|
||||
if (rr != null && rr > 0) {
|
||||
return (
|
||||
'<div class="opt-target-row opt-target-row--managed">' +
|
||||
'<span class="opt-target-row-label">对冲计划</span>' +
|
||||
'<span class="opt-target-armed">计划 #' +
|
||||
hedgeTarget.plan_id +
|
||||
" · 盈亏比 " +
|
||||
fmt(rr, 2) +
|
||||
"</span>" +
|
||||
'<span class="muted opt-target-row-hint">进行中 · 达盈亏比仅平盈利腿;亏损腿残值平或到期平</span>' +
|
||||
"</div>"
|
||||
);
|
||||
}
|
||||
if (Number(hedgeTarget.target_index) > 0) {
|
||||
const side = (p.opt_type || hedgeTarget.opt_type || "").toUpperCase() === "P" ? "Put ≤" : "Call ≥";
|
||||
return (
|
||||
'<div class="opt-target-row opt-target-row--managed">' +
|
||||
'<span class="opt-target-row-label">对冲计划</span>' +
|
||||
'<span class="opt-target-armed">计划 #' +
|
||||
hedgeTarget.plan_id +
|
||||
" · " +
|
||||
side +
|
||||
" " +
|
||||
fmt(hedgeTarget.target_index, 1) +
|
||||
"</span>" +
|
||||
'<span class="muted opt-target-row-hint">进行中 · 由对冲计划监控,到位后仅平盈利腿</span>' +
|
||||
"</div>"
|
||||
);
|
||||
}
|
||||
}
|
||||
const tgt = p.target_index != null && p.target_index !== "" ? Number(p.target_index) : null;
|
||||
const armed = tgt != null && Number.isFinite(tgt) && tgt > 0;
|
||||
@@ -1896,13 +1912,15 @@
|
||||
});
|
||||
}
|
||||
const hedgeTarget = p.hedge_plan_target;
|
||||
if (hedgeTarget && hedgeTarget.target_index != null) {
|
||||
if (hedgeTarget && (hedgeTarget.target_index != null || hedgeTarget.profit_rr != null)) {
|
||||
targets.push({
|
||||
inst_id: p.inst_id,
|
||||
opt_type: p.opt_type || hedgeTarget.opt_type,
|
||||
target_index: hedgeTarget.target_index,
|
||||
profit_rr: hedgeTarget.profit_rr,
|
||||
plan_id: hedgeTarget.plan_id,
|
||||
managed_by: hedgeTarget.managed_by,
|
||||
exit_mode: hedgeTarget.exit_mode,
|
||||
});
|
||||
}
|
||||
return targets;
|
||||
|
||||
@@ -76,8 +76,9 @@
|
||||
target_win_leg: "期期平盈利腿",
|
||||
target_up_win_leg: "期期上破·平盈利腿",
|
||||
target_down_win_leg: "期期下破·平盈利腿",
|
||||
oo_rest_closing: "期期全平·清残腿中",
|
||||
oo_rest_closed: "期期全平·两腿已平",
|
||||
profit_rr_win_leg: "期期盈亏比达标·平盈利腿",
|
||||
oo_rest_closing: "期期残值平·清亏损腿中",
|
||||
oo_rest_closed: "期期残值平·两腿已平",
|
||||
orphaned_after_tp: "止盈后持有至到期",
|
||||
orphaned_option_expiry: "残腿到期",
|
||||
hold_to_expiry: "持有至到期",
|
||||
|
||||
Reference in New Issue
Block a user