import json, math, statistics as S, collections
exec(open('it2c.py').read().split("# HOT conditional")[0])
# full rule family with majors gate, check halves and trim at HOT
def run_rule(gate_majors=True, gate_btc=True, hot_trim=False, nin=30, nout=15, delay=0):
    G=collections.defaultdict(list)
    for k in keys:
        ds=[d for d,_ in D[k]['line']]; L=[v for _,v in D[k]['line']]; bo=bt_on(ds); st=stage_series(L)
        i=max(nin,nout)
        while i<len(L)-1:
            ok=L[i]>max(L[i-nin:i]) and (not gate_btc or bo[i]) and (not gate_majors or k=='majors' or ON['majors'].get(ds[i]))
            if not ok: i+=1; continue
            j0=i+delay
            if j0>=len(L)-1: break
            ent=L[j0]; ex=None; part=0; w=1.0; acc=0
            for j in range(j0+1,len(L)):
                if hot_trim and w==1.0 and st[j][0]=='HOT': acc+=0.5*(L[j]/ent-1); w=0.5
                if L[j]<min(L[j-nout:j]): ex=j; break
            if ex is None: break
            r=acc+w*(L[ex]/ent-1)-0.01
            t=dict(sig=ds[i],ret=r,k=k)
            per='H1' if ds[i]<'2024-09-01' else 'H2'
            for g in ('all',per,('memes' if 'meme' in k or k in('sol_pump','sol_bonk') else 'majors' if k=='majors' else 'other')): G[g].append(t)
            G['y'+ds[i][:4]].append(t)
            i=ex+1
    return G
for nm,kw in [('A: 30d high, BTC gate only',dict(gate_majors=False)),('B: 30d high, BTC + majors ON',{}),('C: B + trim half at HOT',dict(hot_trim=True)),
              ('D: B but next-day entry',dict(delay=1)),('E: B with 20/10',dict(nin=20,nout=10)),('F: B with 50/20',dict(nin=50,nout=20)),('G: majors gate, no BTC gate',dict(gate_btc=False))]:
    G=run_rule(**kw); print("\n==",nm)
    for g in ('all','H1','H2','memes','other','majors','y2023','y2024','y2025','y2026'):
        if G[g]: print(f"  {g:7s}",st_(G[g]))
