Prefer open direction from ATM vs spot (below=Call/short, above=Put/long).

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-07-25 12:39:23 +08:00
parent ee0ec57f89
commit 79c074ec6c
6 changed files with 110 additions and 25 deletions
+42 -8
View File
@@ -5,30 +5,64 @@ from dataclasses import dataclass
@dataclass(slots=True)
class Signal:
bias: str # call_ask_gt_put | put_ask_gt_call
bias: str # strike_below_spot | strike_above_spot | call_ask_gt_put | put_ask_gt_call
option_side: str # call | put
perp_side: str # long | short
call_ask: float
put_ask: float
def decide(call_ask: float | None, put_ask: float | None) -> Signal | None:
def decide(
call_ask: float | None,
put_ask: float | None,
*,
strike: float | None = None,
mark_px: float | None = None,
) -> Signal | None:
"""
开仓方向:
- 行权价 < 标的 → 买 Call + 永续空(ATM 偏下)
- 行权价 > 标的 → 买 Put + 永续多(ATM 偏上)
- 行权价 ≈ 标的 → 回退 Call/Put 卖一比价
"""
if call_ask is None or put_ask is None:
return None
if call_ask > put_ask:
ca = float(call_ask)
pa = float(put_ask)
if strike is not None and mark_px is not None and float(mark_px) > 0:
diff = float(strike) - float(mark_px)
if diff < -1e-9:
return Signal(
bias="strike_below_spot",
option_side="call",
perp_side="short",
call_ask=ca,
put_ask=pa,
)
if diff > 1e-9:
return Signal(
bias="strike_above_spot",
option_side="put",
perp_side="long",
call_ask=ca,
put_ask=pa,
)
if ca > pa:
return Signal(
bias="call_ask_gt_put",
option_side="call",
perp_side="short",
call_ask=float(call_ask),
put_ask=float(put_ask),
call_ask=ca,
put_ask=pa,
)
if put_ask > call_ask:
if pa > ca:
return Signal(
bias="put_ask_gt_call",
option_side="put",
perp_side="long",
call_ask=float(call_ask),
put_ask=float(put_ask),
call_ask=ca,
put_ask=pa,
)
return None