"""
================================================================================
Strategy **D070** — ``s070``
================================================================================
Yesterday ``ret_1 > 1.8%`` and ``vix_chg_5 < -1`` + VRP.

**Exit / structure:** hold **5** sessions, trade kind ``ss``, params ``(27,)``.
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": "D070", "theme": "overnight_proxy", "title": 'Large up day then vol fade short straddle'}

HOLD_SESSIONS = 5
TRADE_KIND = "ss"
TRADE_PARAMS = (27,)


def wants_entry(i: int, row: pd.Series, ch: OptionChain, spy: float, ctx: ResearchContext) -> bool:
    if i < 1:
        return False
    r1 = ctx.row(i - 1).get("ret_1")
    if r1 is None or pd.isna(r1) or float(r1) <= 0.018:
        return False
    dv = row.get("vix_chg_5")
    if dv is None or pd.isna(dv) or float(dv) >= -1.0:
        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, 27)
    if iv is None or iv <= rv:
        return False
    if ctx.chain_contracts(i) < 80 or not ch.contracts:
        return False
    _ = spy
    return True
