Settle expiry options at intrinsic value like live exchange.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-07-26 16:08:44 +08:00
parent a58d97938c
commit e3671d9798
5 changed files with 109 additions and 65 deletions
+18 -4
View File
@@ -29,6 +29,21 @@ def option_intrinsic(*, option_side: str, strike: float, spot: float) -> float:
return 0.0
def option_expiry_settle(
*,
intrinsic: float,
qty_eth: float,
fee_rate: float,
) -> PriceResult:
"""到期结算:按内在价值入账(对齐实盘),无买卖价差滑点,仅扣手续费。"""
base = max(float(intrinsic), 0.0)
fill = base
f = float(fee_rate)
notional = abs(fill * float(qty_eth))
fee = notional * f
return PriceResult(base_px=base, fill_px=fill, fee=fee, slip=0.0, notional=notional)
def resolve_option_close_bid(
*,
bid: float | None,
@@ -37,8 +52,9 @@ def resolve_option_close_bid(
bypass_liquidity: bool,
) -> float | None:
"""
平仓用买一价;多头卖出不得低于内在价值(SIM 防到期垃圾盘口)。
bypass 时:买一缺失可用标记/内在价值兜底
非到期平仓用买一价;多头卖出不得低于内在价值(SIM)。
紧急 bypassmax(买一, 标记, 内在价值)
到期请用 option_expiry_settle,不要走本函数。
"""
candidates: list[float] = []
if bid is not None and bid >= 0:
@@ -49,8 +65,6 @@ def resolve_option_close_bid(
candidates.append(float(intrinsic))
if not candidates:
return None
# 常规:有买一时,仍用 max(买一, 内在价值) 抬到合理底价
# bypassmax(买一, 标记, 内在价值)
if bypass_liquidity:
return max(candidates)
if bid is None: