"""
================================================================================
Strategy **D096** — ``s096``
================================================================================
``skew(i)-skew(i-5) < -0.007`` at (30,-0.18,0.12).

**Exit / structure:** hold **4** sessions, trade kind ``sl``, params ``(13,)``.
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": "D096", "theme": "skew_momentum", "title": 'Five-session skew decrease long straddle'}

HOLD_SESSIONS = 4
TRADE_KIND = "sl"
TRADE_PARAMS = (13,)


def wants_entry(i: int, row: pd.Series, ch: OptionChain, spy: float, ctx: ResearchContext) -> bool:
    if i < 5:
        return False
    a = ctx.skew_iv_diff(i, 30, -0.18, 0.12)
    b = ctx.skew_iv_diff(i - 5, 30, -0.18, 0.12)
    if a is None or b is None or a - b >= -0.007:
        return False
    if ctx.chain_contracts(i) < 80 or not ch.contracts:
        return False
    _ = spy, row
    return True
