Floor option close at intrinsic to fix expiry garbage quotes.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -17,6 +17,49 @@ class PriceResult:
|
||||
return asdict(self)
|
||||
|
||||
|
||||
def option_intrinsic(*, option_side: str, strike: float, spot: float) -> float:
|
||||
"""多头期权内在价值(USDT/ETH)。call=max(S−K,0),put=max(K−S,0)。"""
|
||||
s = float(spot)
|
||||
k = float(strike)
|
||||
side = str(option_side).lower().strip()
|
||||
if side in ("call", "c"):
|
||||
return max(s - k, 0.0)
|
||||
if side in ("put", "p"):
|
||||
return max(k - s, 0.0)
|
||||
return 0.0
|
||||
|
||||
|
||||
def resolve_option_close_bid(
|
||||
*,
|
||||
bid: float | None,
|
||||
mark: float | None,
|
||||
intrinsic: float | None,
|
||||
bypass_liquidity: bool,
|
||||
) -> float | None:
|
||||
"""
|
||||
平仓用买一价;多头卖出不得低于内在价值(SIM 防到期垃圾盘口)。
|
||||
bypass 时:买一缺失可用标记/内在价值兜底。
|
||||
"""
|
||||
candidates: list[float] = []
|
||||
if bid is not None and bid >= 0:
|
||||
candidates.append(float(bid))
|
||||
if bypass_liquidity and mark is not None and mark >= 0:
|
||||
candidates.append(float(mark))
|
||||
if intrinsic is not None and intrinsic >= 0:
|
||||
candidates.append(float(intrinsic))
|
||||
if not candidates:
|
||||
return None
|
||||
# 常规:有买一时,仍用 max(买一, 内在价值) 抬到合理底价
|
||||
# bypass:max(买一, 标记, 内在价值)
|
||||
if bypass_liquidity:
|
||||
return max(candidates)
|
||||
if bid is None:
|
||||
return None
|
||||
if intrinsic is not None and intrinsic >= 0:
|
||||
return max(float(bid), float(intrinsic))
|
||||
return float(bid)
|
||||
|
||||
|
||||
def perp_fill(
|
||||
*,
|
||||
side: str,
|
||||
|
||||
Reference in New Issue
Block a user