"""Independent recompute of the M&A ripple headline from the published CSVs ONLY. No database, no Cymetica code. Reads flagship_events.csv + flagship_legs.csv. """ import csv, math from collections import defaultdict ev = list(csv.DictReader(open("flagship_events.csv"))) lg = list(csv.DictReader(open("flagship_legs.csv"))) # 1. Rebuild every basket return from raw leg prices, compare to the published field. by_ev = defaultdict(list) for r in lg: by_ev[(r["selector"], r["deal_id"])].append(r) worst = 0.0 for e in ev: legs = by_ev[(e["selector"], e["deal_id"])] recomputed = sum(float(l["renormalized_weight"]) * (float(l["exit_price"]) / float(l["entry_price"]) - 1.0) for l in legs) * 100.0 worst = max(worst, abs(recomputed - float(e["basket_return_pct"]))) print(f"1. basket returns rebuilt from raw prices — worst mismatch {worst:.6f} pp") # 2. Excess = basket - SPY, recomputed from the published SPY prices. worst = 0.0 for e in ev: spy = (float(e["spy_exit"]) / float(e["spy_entry"]) - 1.0) * 100.0 worst = max(worst, abs((float(e["basket_return_pct"]) - spy) - float(e["excess_return_pct"]))) print(f"2. excess vs SPY recomputed from SPY prices — worst mismatch {worst:.6f} pp") # 3. The headline numbers. print("3. headline recompute:") g = defaultdict(list) for e in ev: g[(e["selector"], e["attention_bucket"])].append(float(e["excess_return_pct"])) for k in sorted(g): xs = g[k] n = len(xs); m = sum(xs)/n sd = math.sqrt(sum((x-m)**2 for x in xs)/(n-1)) if n > 1 else 0.0 t = m/(sd/math.sqrt(n)) if sd else 0.0 hit = 100.0*sum(1 for x in xs if x > 0)/n print(f" {k[0]:>8} {k[1]:>4} n={n:3d} avg={m:+6.2f}% t={t:+5.2f} hit={hit:5.1f}%")