Add T-shaped options chain view with straddle metrics (phase A).
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -358,3 +358,49 @@ def equivalent_contract_leverage(
|
||||
if eth_amount <= 0 or total_premium <= 0:
|
||||
return None
|
||||
return round(float(index_px) * float(eth_amount) / float(total_premium), 1)
|
||||
|
||||
|
||||
def straddle_ask_per_unit(
|
||||
call_ask: float | None,
|
||||
put_ask: float | None,
|
||||
) -> float | None:
|
||||
"""跨式双买:每 1 标的币的卖一报价之和."""
|
||||
if call_ask is None or put_ask is None:
|
||||
return None
|
||||
if float(call_ask) <= 0 or float(put_ask) <= 0:
|
||||
return None
|
||||
return round(float(call_ask) + float(put_ask), 4)
|
||||
|
||||
|
||||
def straddle_premium_total(
|
||||
call_ask: float | None,
|
||||
put_ask: float | None,
|
||||
eth_amount: float | None,
|
||||
) -> float | None:
|
||||
"""跨式双买权利金总额(USDC)."""
|
||||
per = straddle_ask_per_unit(call_ask, put_ask)
|
||||
if per is None or eth_amount is None or float(eth_amount) <= 0:
|
||||
return None
|
||||
return round(per * float(eth_amount), 2)
|
||||
|
||||
|
||||
def straddle_breakeven_band(
|
||||
strike: float | None,
|
||||
combined_ask_per_unit: float | None,
|
||||
) -> tuple[float | None, float | None]:
|
||||
"""跨式到期平衡带:下平衡 ~ 上平衡(按双卖一报价和)."""
|
||||
if strike is None or combined_ask_per_unit is None:
|
||||
return None, None
|
||||
k = float(strike)
|
||||
d = float(combined_ask_per_unit)
|
||||
return round(k - d, 2), round(k + d, 2)
|
||||
|
||||
|
||||
def format_straddle_band(
|
||||
strike: float | None,
|
||||
combined_ask_per_unit: float | None,
|
||||
) -> str:
|
||||
lo, hi = straddle_breakeven_band(strike, combined_ask_per_unit)
|
||||
if lo is None or hi is None:
|
||||
return ""
|
||||
return f"{lo:.0f} ~ {hi:.0f}"
|
||||
|
||||
Reference in New Issue
Block a user