import lab, rules as Q, rotmap as R, math R.INDEX_NEED = 1; R.RISK_MA = 100 M = lab.load(); label, runs = lab.oracle(M) def g_var(thrust=None, top_exit=False): g = {"on": False, "dropped": set()} def rule(i): up = M.risk_on(i) if g["on"] and (not up or (top_exit and M.alt_top_warning(i))): g["on"] = False elif not g["on"] and up and (M.alt_bottom(i) or (thrust and (M.c30[i] or 0) >= thrust and (M.c90[i] or 0) < 0.5)): g["on"], g["dropped"] = True, set() if not g["on"]: return {"BTC": 1.0} if up else {} for b in R.ALT_BASKETS: if M.basket_top(b, i): g["dropped"].add(b) have = [b for b in R.ALT_BASKETS if M.idx[b][i]] live = [b for b in have if b not in g["dropped"]] w = {b: 1 / len(have) for b in live} if len(live) < len(have): w["BTC"] = 1 - sum(w.values()) return w return rule P = [("2020-06-01", "2024-06-30"), ("2024-07-01", None)] def show(n, mk): cells = [] for a, z in P: s = lab.score(M, mk(), a, z, label=label, runs=runs); st = R.stats(M.backtest(mk(), M.pos[a], M.pos[z] if z else M.N - 1)[0]) cells.append("cap %3d%% maj %d/%d ret %+6d%% dd %4.0f%% sw %3d" % (s["capture"], s["caught"], s["major"], st["total"], st["maxdd"], s["switches"])) print("%-32s" % n + " | ".join(cells)) show("G 100d (v2 base)", lambda: g_var()) for t in (0.6, 0.7, 0.8): show("G + thrust c30>=%.0f%% (c90<50)" % (t * 100), lambda t=t: g_var(t)) show("G + market top exit", lambda: g_var(None, True))