"""SKH_P_REGIME_plateau — tight plateau probe around the sweep winner
vola_lo=20, vola_hi=88, vol_lo=55, vol_hi=80 (V1 base: ptn_n=55, sl_atr=2.5, tp_atr=6.0).

Confirm neighbors in ALL 4 band dims are also good (no knife-edge).
"""
from __future__ import annotations
import sys
sys.path.insert(0, "/opt/docker/PythagorasGoal/scripts/research/skyhook")
import skyhooklib as sk
from src.strategies.skyhook import SkyhookParams

ASSETS = ("BTC", "ETH")
BASE = dict(ptn_n=55, sl_atr=2.5, tp_atr=6.0)
WIN = dict(vola_lo=20, vola_hi=88, vol_lo=55, vol_hi=80)


def ev(**bands):
    p = SkyhookParams(**{**BASE, **bands})
    res = {a: sk.run_asset(a, p, sk.FEE_RT) for a in ASSETS}
    mf = min(res[a]["full"]["sharpe"] for a in ASSETS)
    mh = min(res[a]["holdout"]["sharpe"] for a in ASSETS)
    tr = min(res[a]["full"]["n_trades"] for a in ASSETS)
    dd = max(res[a]["full"]["maxdd"] for a in ASSETS)
    return mf, mh, tr, dd


def probe(dim, values):
    print(f"\n-- perturb {dim} (others at winner) --")
    for v in values:
        bands = dict(WIN); bands[dim] = v
        mf, mh, tr, dd = ev(**bands)
        mark = " <-- WIN" if v == WIN[dim] else ""
        print(f"   {dim}={v:>4}: minF={mf:+.2f} minH={mh:+.2f} tr={tr:>3} DD={dd*100:.0f}%{mark}")


def main():
    mf, mh, tr, dd = ev(**WIN)
    print(f"WINNER {WIN}: minF={mf:+.2f} minH={mh:+.2f} tr={tr} DD={dd*100:.0f}%")
    probe("vola_lo", [15, 20, 25, 30])
    probe("vola_hi", [83, 85, 88, 90, 92])
    probe("vol_lo",  [45, 50, 55, 60, 65])
    probe("vol_hi",  [75, 78, 80, 82, 85])


if __name__ == "__main__":
    main()
