"""
================================================================================
Strategy **D014** — ``s014``
================================================================================

Theme
-----
**Vol-of-vol ratio extreme (VVIX/VIX) with long convexity.**

Economic idea
-------------
When **VVIX/VIX** is very high, the market is pricing a lot of uncertainty *about*
volatility relative to volatility itself. This sleeve buys a **21 DTE** ATM straddle when
the ratio exceeds **1.22** (and VVIX data exist on the panel).

Entry
-----
1. ``vvix_over_vix()`` from context returns a value ``> 1.22``.
2. ``VIX < 35`` (avoid pairing with pure VIX blow-off where ratio can be distorted).
3. ``n_contracts[i] >= 80``.

Exit
----
Long straddle 21 DTE, hold **5** sessions.
================================================================================
"""

from __future__ import annotations

import math

from RenTech.core.options_data_loader import OptionChain
from RenTech.strategy_stack.diverse_theta_strategies_v1.context import ResearchContext

META = {"sid": "D014", "theme": "vol_of_vol", "title": "VVIX/VIX very high long straddle"}

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


def wants_entry(i: int, row, ch: OptionChain, spy: float, ctx: ResearchContext) -> bool:
    r = ctx.vvix_over_vix(i)
    if r is None or r <= 1.22:
        return False
    vx = ctx.vix(i)
    if not math.isfinite(vx) or vx >= 35.0:
        return False
    if ctx.chain_contracts(i) < 80:
        return False
    if not ch.contracts:
        return False
    _ = spy, row
    return True
