修复币本位期权残档判定:内在价值按币报价(S-K)/S,避免与美元点差混比误杀有效买一

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-08-20 16:21:54 +08:00
parent b0c331aa26
commit a7bec5e121
6 changed files with 115 additions and 20 deletions
+6 -11
View File
@@ -13,6 +13,7 @@ import ccxt
from lib.options.options_pricing_lib import (
expiry_breakeven_from_ask,
idx_distance_to_be,
intrinsic_px_per_unit,
is_shallow_itm,
option_moneyness,
option_moneyness_label,
@@ -251,15 +252,6 @@ def tick_sz_and_ct_mult(
return tick_sz, ct_mult or 0.01
def _intrinsic_px_per_unit(opt_type: str, strike: float, index_px: float) -> float | None:
o = (opt_type or "").upper()
if o == "C" and index_px > strike:
return float(index_px) - float(strike)
if o == "P" and index_px < strike:
return float(strike) - float(index_px)
return None
def _resolve_chain_quote(
*,
ticker: dict[str, Any],
@@ -267,6 +259,7 @@ def _resolve_chain_quote(
opt_type: str,
strike: float,
index_px: float,
inst_id: str | None = None,
) -> dict[str, Any]:
"""链列表报价:卖一缺失时用标记价/内在价值估算(深度实值常见无卖一)."""
tick_sz = meta.get("tickSz")
@@ -276,12 +269,13 @@ def _resolve_chain_quote(
ask_sz = _safe_float(ticker.get("askSz"))
bid_sz = _safe_float(ticker.get("bidSz"))
ask_estimated = False
iid = (inst_id or str(meta.get("instId") or "")).strip()
if ask is None and mark is not None and mark > 0:
ask = round_option_px(mark, tick_sz, "buy")
ask_estimated = True
if ask is None:
intrinsic = _intrinsic_px_per_unit(opt_type, strike, index_px)
intrinsic = intrinsic_px_per_unit(opt_type, strike, index_px, inst_id=iid or None)
if intrinsic is not None and intrinsic > 0:
ask = round_option_px(intrinsic, tick_sz, "buy")
ask_estimated = True
@@ -289,7 +283,7 @@ def _resolve_chain_quote(
if bid is None and mark is not None and mark > 0:
bid = round_option_px(mark, tick_sz, "sell")
if bid is None:
intrinsic = _intrinsic_px_per_unit(opt_type, strike, index_px)
intrinsic = intrinsic_px_per_unit(opt_type, strike, index_px, inst_id=iid or None)
if intrinsic is not None and intrinsic > 0:
bid = round_option_px(intrinsic, tick_sz, "sell")
@@ -878,6 +872,7 @@ def build_option_chain(
opt_type=opt_type,
strike=strike,
index_px=idx,
inst_id=inst_id,
)
ask = q["ask"]
bid = q["bid"]