Add depth-based option close flow.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-07-11 08:46:07 +08:00
parent 02472f19cb
commit 6e45604d93
6 changed files with 396 additions and 20 deletions
+36
View File
@@ -129,6 +129,42 @@ def test_format_quote_liquidity():
assert format_quote_liquidity(None, 10) is None
def test_estimate_close_by_bids_full_depth():
from lib.options.options_pricing_lib import estimate_close_by_bids
out = estimate_close_by_bids(
[{"px": 12.3, "sz": 2}, {"px": 12.1, "sz": 3}],
4,
ct_mult=0.01,
premium_paid=0.4,
)
assert out["covered_sheets"] == 4
assert out["uncovered_sheets"] == 0
assert out["total_received"] == 0.488
assert out["avg_px"] == 12.2
assert out["estimated_pnl"] == 0.088
assert [x["sheets"] for x in out["levels"]] == [2, 2]
def test_estimate_close_by_bids_partial_depth():
from lib.options.options_pricing_lib import estimate_close_by_bids
out = estimate_close_by_bids([{"px": 10, "sz": 1}], 3, ct_mult=0.01, premium_paid=0.6)
assert out["covered_sheets"] == 1
assert out["uncovered_sheets"] == 2
assert out["total_received"] == 0.1
assert out["estimated_pnl"] == -0.1
def test_estimate_close_by_bids_empty():
from lib.options.options_pricing_lib import estimate_close_by_bids
out = estimate_close_by_bids([], 2)
assert out["covered_sheets"] == 0
assert out["uncovered_sheets"] == 2
assert out["avg_px"] is None
def test_expiry_breakeven_from_ask():
from lib.options.options_pricing_lib import expiry_breakeven_from_ask