Fix OO expiry Put PnL: overlay wrong near-zero settlement fills with intrinsic.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -76,3 +76,57 @@ def test_public_fallback_and_overlay(monkeypatch) -> None:
|
||||
view = _overlay_expiry_zero_fills(g, fills, 1877.8)
|
||||
assert view[0]["fill_px"] == 0.0 # call OTM
|
||||
assert abs(view[1]["fill_px"] - (1920 - 1877.8)) < 1e-9
|
||||
|
||||
|
||||
def test_overlay_wrong_near_zero_put_fill() -> None:
|
||||
"""账单误写成 0.2 时,应按内在价值 42.2 覆盖,Put 显示盈利。"""
|
||||
g = {
|
||||
"hedge_mode": "option_option",
|
||||
"option_side": "call",
|
||||
"option2_side": "put",
|
||||
"strike": 1940.0,
|
||||
"strike2": 1920.0,
|
||||
"close_reason": "expiry",
|
||||
}
|
||||
fills = [
|
||||
{
|
||||
"leg": "option",
|
||||
"action": "open",
|
||||
"fill_px": 12.0,
|
||||
"qty_eth": 7.5,
|
||||
"fee": 0.045,
|
||||
"slip": 0,
|
||||
},
|
||||
{
|
||||
"leg": "option2",
|
||||
"action": "open",
|
||||
"fill_px": 12.8,
|
||||
"qty_eth": 7.0,
|
||||
"fee": 0.045,
|
||||
"slip": 0,
|
||||
},
|
||||
{
|
||||
"leg": "option",
|
||||
"action": "close",
|
||||
"fill_px": 0.0,
|
||||
"qty_eth": 7.5,
|
||||
"fee": 0,
|
||||
"slip": 0,
|
||||
},
|
||||
{
|
||||
"leg": "option2",
|
||||
"action": "close",
|
||||
"fill_px": 0.2,
|
||||
"qty_eth": 7.0,
|
||||
"fee": 0.0007,
|
||||
"slip": 0,
|
||||
},
|
||||
]
|
||||
from app.sim.pnl import summarize_fills_pnl
|
||||
|
||||
view = _overlay_expiry_zero_fills(g, fills, 1877.8)
|
||||
assert abs(view[3]["fill_px"] - 42.2) < 1e-9
|
||||
s = summarize_fills_pnl(view)
|
||||
# Put: (42.2 - 12.8) * 7 = 205.8
|
||||
assert abs(float(s["option2_pnl"] or 0) - 205.8) < 1e-6
|
||||
assert float(s["option2_pnl"] or 0) > 0
|
||||
|
||||
Reference in New Issue
Block a user