Improve options order estimates and chain filter defaults.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-07-11 14:37:53 +08:00
parent 9f0a30a040
commit c9c8388250
4 changed files with 204 additions and 63 deletions
+41 -9
View File
@@ -75,19 +75,51 @@ def test_equivalent_contract_leverage():
assert lev == 144.9
def test_estimate_expiry_profit_at_index():
from lib.options.options_pricing_lib import estimate_expiry_profit_at_index
# Call 1780, ask 12.2, 0.01 ETH, target 1793 -> (13-12.2)*0.01 = 0.008
p = estimate_expiry_profit_at_index(
opt_type="C", strike=1780, target_idx=1793, entry_px=12.2, eth_amount=0.01
def test_estimate_expiry_value_and_profit_at_index():
from lib.options.options_pricing_lib import (
estimate_expiry_profit_at_index,
estimate_expiry_value_at_index,
)
assert p == 0.008
value = estimate_expiry_value_at_index(
opt_type="C", strike=1800, target_idx=2000, eth_amount=1.0
)
assert value == 200.0
profit = estimate_expiry_profit_at_index(
opt_type="C",
strike=1800,
target_idx=2000,
entry_px=0.148,
eth_amount=1.0,
total_premium=14.8,
)
assert profit == 185.2
# Call 1780, ask 12.2, 0.01 ETH, target 1793 -> value 0.13, profit 0.01
v = estimate_expiry_value_at_index(
opt_type="C", strike=1780, target_idx=1793, eth_amount=0.01
)
assert v == 0.13
p = estimate_expiry_profit_at_index(
opt_type="C",
strike=1780,
target_idx=1793,
entry_px=12.2,
eth_amount=0.01,
total_premium=0.122,
)
assert p == 0.01
# OTM call loses premium
p2 = estimate_expiry_profit_at_index(
opt_type="C", strike=1780, target_idx=1770, entry_px=12.2, eth_amount=0.01
opt_type="C",
strike=1780,
target_idx=1770,
entry_px=12.2,
eth_amount=0.01,
total_premium=0.122,
)
assert p2 == round(-12.2 * 0.01, 4)
assert p2 == -0.12
def test_resolve_chain_quote_otm_no_quote():