"""
================================================================================
Strategy **D061** — ``s061``
================================================================================
RV21 below 0.11 + IV34 above 1.15×RV + VIX>12.

**Exit / structure:** hold **7** sessions, trade kind ``ss``, params ``(34,)``.
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": "D061", "theme": "realized_vol", "title": 'Very low RV21 short straddle'}

HOLD_SESSIONS = 7
TRADE_KIND = "ss"
TRADE_PARAMS = (34,)


def wants_entry(i: int, row: pd.Series, ch: OptionChain, spy: float, ctx: ResearchContext) -> bool:
    rv = float(row["rv21"]) if pd.notna(row.get("rv21")) else float("nan")
    if not math.isfinite(rv) or rv >= 0.11:
        return False
    vx = ctx.vix(i)
    if not math.isfinite(vx) or vx <= 12.0:
        return False
    iv = ctx.iv_atm_dte(i, 34)
    if iv is None or iv <= 1.15 * rv:
        return False
    if ctx.chain_contracts(i) < 80 or not ch.contracts:
        return False
    _ = spy
    return True
