"""
================================================================================
Strategy **D075** — ``s075``
================================================================================
``close < SMA200`` and ``iv10-iv40 > 0.02``.

**Exit / structure:** hold **10** sessions, trade kind ``vert``, params ``(36, -0.25, 7.0)``.
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": "D075", "theme": "put_spread", "title": 'Weak tape + inverted IV put vertical'}

HOLD_SESSIONS = 10
TRADE_KIND = "vert"
TRADE_PARAMS = (36, -0.25, 7.0)


def wants_entry(i: int, row: pd.Series, ch: OptionChain, spy: float, ctx: ResearchContext) -> bool:
    s200 = row.get("sma_200")
    if s200 is None or pd.isna(s200) or float(row["close"]) >= float(s200):
        return False
    a = ctx.iv_atm_dte(i, 10)
    b = ctx.iv_atm_dte(i, 40)
    if a is None or b is None or a - b <= 0.02:
        return False
    if ctx.chain_contracts(i) < 90 or not ch.contracts:
        return False
    _ = spy
    return True
