"""
================================================================================
Strategy **D078** — ``s078``
================================================================================
``VVIX/VIX<1.04`` and ``bb_width_20<0.05``.

**Exit / structure:** hold **6** sessions, trade kind ``sg``, params ``(39, -0.22, 0.15)``.
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": "D078", "theme": "calm_dual", "title": 'Low VVIX ratio + tight BB width strangle'}

HOLD_SESSIONS = 6
TRADE_KIND = "sg"
TRADE_PARAMS = (39, -0.22, 0.15)


def wants_entry(i: int, row: pd.Series, ch: OptionChain, spy: float, ctx: ResearchContext) -> bool:
    r = ctx.vvix_over_vix(i)
    if r is None or r >= 1.04:
        return False
    bw = row.get("bb_width_20")
    if bw is None or pd.isna(bw) or float(bw) >= 0.05:
        return False
    if ctx.chain_contracts(i) < 100 or not ch.contracts:
        return False
    _ = spy
    return True
