"""
================================================================================
Strategy **D094** — ``s094``
================================================================================
``sma_20 < sma_200`` and ``VIX < 15.5`` + VRP.

**Exit / structure:** hold **6** sessions, trade kind ``sg``, params ``(41, -0.22, 0.15)``.
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": "D094", "theme": "combo_ma_vix", "title": 'Bear MA stack but VIX very low short strangle'}

HOLD_SESSIONS = 6
TRADE_KIND = "sg"
TRADE_PARAMS = (41, -0.22, 0.15)


def wants_entry(i: int, row: pd.Series, ch: OptionChain, spy: float, ctx: ResearchContext) -> bool:
    s20 = row.get("sma_20")
    s200 = row.get("sma_200")
    if s20 is None or s200 is None or pd.isna(s20) or pd.isna(s200):
        return False
    if float(s20) >= float(s200):
        return False
    vx = ctx.vix(i)
    if not math.isfinite(vx) or vx >= 15.5:
        return False
    rv = float(row["rv21"]) if pd.notna(row.get("rv21")) else float("nan")
    if not math.isfinite(rv) or rv <= 0:
        return False
    iv = ctx.iv_atm_dte(i, 41)
    if iv is None or iv <= rv:
        return False
    if ctx.chain_contracts(i) < 100 or not ch.contracts:
        return False
    _ = spy
    return True
