"""
================================================================================
Strategy **D045** — ``s045``  (Large 20d return magnitude — long straddle)
================================================================================
**Idea:** ``abs(ret_20) > 0.09`` flags a **big** 20-session move; buy straddle for continuation
or whipsaw, gated by ``VIX<26``.
**Entry:** abs return + VIX gate + ``contracts>=80``.
**Exit:** Long straddle **20** 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": "D045", "theme": "return_shock", "title": "Large abs 20d return + non-extreme VIX long straddle"}

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


def wants_entry(i: int, row: pd.Series, ch: OptionChain, spy: float, ctx: ResearchContext) -> bool:
    r20 = row.get("ret_20")
    if r20 is None or pd.isna(r20) or abs(float(r20)) <= 0.09:
        return False
    vx = ctx.vix(i)
    if not math.isfinite(vx) or vx >= 26.0:
        return False
    if ctx.chain_contracts(i) < 80 or not ch.contracts:
        return False
    _ = spy
    return True
