Fix OO expiry settle index: persist spot and never invent strike from OTM fill.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-08-11 16:44:56 +08:00
parent 4a5d19e30f
commit 3264dd4381
6 changed files with 124 additions and 17 deletions
+48
View File
@@ -0,0 +1,48 @@
"""期期到期结算指数:虚值 Call fill=0 不得反推成行权价。"""
from __future__ import annotations
from app.api.trades import _infer_settle_index
def test_otm_call_zero_fill_does_not_become_strike() -> None:
g = {
"hedge_mode": "option_option",
"option_side": "call",
"option2_side": "put",
"strike": 1920.0,
"strike2": 1890.0,
"settle_index_px": None,
}
fills = [
{"leg": "option", "action": "close", "fill_px": 0.0, "slip": 0},
{"leg": "option2", "action": "close", "fill_px": 0.0, "slip": 0},
]
assert _infer_settle_index(g, fills) is None
def test_itm_put_fill_infers_settle_near_1875() -> None:
g = {
"hedge_mode": "option_option",
"option_side": "call",
"option2_side": "put",
"strike": 1920.0,
"strike2": 1920.0,
"settle_index_px": None,
}
fills = [
{"leg": "option", "action": "close", "fill_px": 0.0, "slip": 0},
{"leg": "option2", "action": "close", "fill_px": 45.0, "slip": 0},
]
# put intrinsic 45 → settle = 1920 - 45 = 1875
assert _infer_settle_index(g, fills) == 1875.0
def test_stored_settle_wins() -> None:
g = {
"option_side": "call",
"strike": 1920.0,
"settle_index_px": 1875.2,
}
fills = [{"leg": "option", "action": "close", "fill_px": 0.0, "slip": 0}]
assert _infer_settle_index(g, fills) == 1875.2