"""runner_daylike.py -- [2026-10-26] 'days like today' test: list breadth turns up (9:45 <= 0 -> 10:15 >= +1), stock ATR >= 8, rising lows.
Buy at 10:15 (next minute), C3 exit. Year 1 / year 2."""
import json, numpy as np
from collections import defaultdict
S = json.load(open("runner_snap.json")); B = defaultdict(dict)
for x in S: B[x["day"]][x["T"]] = x["breadth"]
turn = {d for d, b in B.items() if b.get(15) is not None and b.get(45) is not None and b[15] <= 0 and b[45] >= 1}
print(f"turn days: {len(turn)} of {len(B)} ({sum(d < '2025-10-01' for d in turn)} year 1)")
m = lambda X: f"{np.mean([x['c3'] for x in X]):+.3f}% n={len(X)} rise>=5% {np.mean([x['rise'] >= 5 for x in X]):.0%}" if X else "-"
X = [x for x in S if x["T"] == 45 and x["day"] in turn]
R = {"all list stocks on turn days": lambda x: True,
     "ATR >= 8": lambda x: x["atr"] >= 8,
     "ATR >= 8 + higher lows >= 0.6": lambda x: x["atr"] >= 8 and x["hl_share"] >= 0.6,
     "ATR >= 8 + higher lows >= 0.6 + above VWAP": lambda x: x["atr"] >= 8 and x["hl_share"] >= 0.6 and x["vs_vwap"] > 0,
     "ATR >= 8 + gap down + above VWAP": lambda x: x["atr"] >= 8 and x["gap"] < 0 and x["vs_vwap"] > 0}
for lab, f in R.items():
    Z = [x for x in X if f(x)]
    print(f"  {lab:45} y1 {m([z for z in Z if z['day'] < '2025-10-01'])} | y2 {m([z for z in Z if z['day'] >= '2025-10-01'])}")
print("other days, ATR>=8 + hl>=0.6 + above VWAP:", m([x for x in S if x["T"] == 45 and x["day"] not in turn and x["atr"] >= 8 and x["hl_share"] >= 0.6 and x["vs_vwap"] > 0]))
