"""
================================================================================
Strategy **D047** — ``s047``  (Q1 months + elevated VIX — long straddle)
================================================================================
**Idea:** ``month in (1,2,3)`` and ``VIX>19`` as a coarse seasonality × fear interaction.
**Entry:** month filter + VIX + ``iv_atm(17)`` exists, ``contracts>=80``.
**Exit:** Long straddle **17** DTE, hold **5**.
================================================================================
"""

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": "D047", "theme": "calendar_season", "title": "Q1 months + elevated VIX long straddle"}

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


def wants_entry(i: int, row: pd.Series, ch: OptionChain, spy: float, ctx: ResearchContext) -> bool:
    m = row.get("month")
    if m is None or pd.isna(m) or int(m) not in (1, 2, 3):
        return False
    vx = ctx.vix(i)
    if not math.isfinite(vx) or vx <= 19.0:
        return False
    if ctx.iv_atm_dte(i, 17) is None:
        return False
    if ctx.chain_contracts(i) < 80 or not ch.contracts:
        return False
    _ = spy
    return True
