"""
================================================================================
Strategy **D055** — ``s055``
================================================================================
``iv7 + 0.015 < iv45`` contango in ATM IV + VIX below 28.

**Exit / structure:** hold **5** sessions, trade kind ``sl``, params ``(18,)``.
Signal logic is implemented only in this module (no imports from sibling strategies).
================================================================================
"""

from __future__ import annotations

import math

import pandas as pd

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

META = {"sid": "D055", "theme": "iv_term", "title": 'Front IV below back IV long straddle'}

HOLD_SESSIONS = 5
TRADE_KIND = "sl"
TRADE_PARAMS = (18,)


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