"""
================================================================================
Strategy **D037** — ``s037``  (ATM IV inversion 14 vs 45 — long straddle)
================================================================================
**Idea:** Same family as D016 but **different** tenors and threshold: ``iv14 - iv45 > 0.025``.
**Entry:** as above, ``VIX<31``, ``contracts>=80``.
**Exit:** Long straddle **16** DTE, hold **4**.
================================================================================
"""

from __future__ import annotations

import math

from RenTech.core.options_data_loader import OptionChain
from RenTech.strategy_stack.diverse_theta_strategies_v1.context import ResearchContext

META = {"sid": "D037", "theme": "iv_term", "title": "IV14 much above IV45 inversion long straddle"}

HOLD_SESSIONS = 4
TRADE_KIND = "sl"
TRADE_PARAMS = (16,)


def wants_entry(i: int, row, ch: OptionChain, spy: float, ctx: ResearchContext) -> bool:
    a = ctx.iv_atm_dte(i, 14)
    b = ctx.iv_atm_dte(i, 45)
    if a is None or b is None or a - b <= 0.025:
        return False
    vx = ctx.vix(i)
    if not math.isfinite(vx) or vx >= 31.0:
        return False
    if ctx.chain_contracts(i) < 80 or not ch.contracts:
        return False
    _ = spy, row
    return True
