5ac4e16af8
Ondata di ricerca onesta a largo spettro su BTC/ETH+DVOL certificati: 104 ipotesi distinte (11 famiglie), un agente-finder per ipotesi, verifica avversariale a 3 scettici sui promettenti, sintesi (153 agenti totali). Esito: NIENTE di nuovo regge -> conferma del soffitto strutturale ~1.3 BTC/ETH-direzionale; lo stack TP01+XS01+VRP01 resta imbattuto. - altlib.py: harness condiviso vettoriale leak-free (eval_weights/study_weights, fee-sweep, both-asset + hold-out 2025+). Riproduce i numeri canonici di TP01. - MARGINAL SCORER (study_marginal/marginal_vs_tp01): Sharpe INCREMENTALE vs baseline TP01 (corr, blend uplift OOS, alpha residua) + jackknife OOS (clean-year + drop-best-month). earns_slot = abs!=FAIL & ADDS & robust_oos. Smaschera gli overlay su TSMOM con PASS assoluti fasulli (CMB04, VOL11, ...) e il falso positivo KAMA (ADDS ma muore al jackknife). - runs/*.py (104) script riproducibili per ipotesi; wf_altstrat.js workflow. - Verdetto: 0 candidati deployabili; 2 LEAD fragili (VOL08, STA05_LS) da forward-monitor. - test_marginal_scorer.py blocca baseline + invarianti. Suite: 32 verde. Diario: docs/diary/2026-06-20-alt-strategies-100agent-sweep.md Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
98 lines
3.1 KiB
Python
98 lines
3.1 KiB
Python
"""CMB04 — Momentum + Low-Vol Filter
|
|
HYPOTHESIS: TSMOM long-flat taken only when realized vol is below its rolling median
|
|
(avoid high-vol whipsaw). Vol-target the rest.
|
|
|
|
Grid: 2 vol-filter windows (30d vs 60d rolling median lookback) x 2 TFs (1d, 12h) = 4 cells total.
|
|
Best config chosen by min(BTC,ETH) holdout Sharpe.
|
|
"""
|
|
import sys
|
|
sys.path.insert(0, "/opt/docker/PythagorasGoal/scripts/research/alt")
|
|
import altlib as al
|
|
import numpy as np
|
|
|
|
|
|
def cmb04_target(df, vol_filter_days: int = 30):
|
|
"""
|
|
TSMOM multi-horizon (1m/3m/6m) long-flat, gated by a low-vol filter:
|
|
- Compute realized vol (30d) at each bar.
|
|
- Compute rolling median of that vol over vol_filter_days.
|
|
- Only take the TSMOM signal when realized_vol < rolling_median (low-vol regime).
|
|
- In high-vol regime: go flat (0).
|
|
- Vol-target the resulting direction.
|
|
"""
|
|
c = df["close"].values.astype(float)
|
|
bpd = al.bars_per_day(df)
|
|
bpy = bpd * 365.25
|
|
|
|
# --- TSMOM multi-horizon direction (1m, 3m, 6m) ---
|
|
horizons = (30 * bpd, 90 * bpd, 180 * bpd)
|
|
direction = np.zeros(len(c))
|
|
for h in horizons:
|
|
h = int(h)
|
|
sig = np.full(len(c), np.nan)
|
|
if h < len(c):
|
|
sig[h:] = np.sign(c[h:] / c[:-h] - 1.0)
|
|
direction += np.nan_to_num(sig, nan=0.0)
|
|
# Majority vote -> long or flat
|
|
direction = np.clip(np.sign(direction), 0.0, 1.0) # long-flat only
|
|
|
|
# --- Realized vol (30d causal) ---
|
|
rv_win = max(2, 30 * bpd)
|
|
r = al.simple_returns(c)
|
|
rv = al.realized_vol(r, rv_win, bpy)
|
|
|
|
# --- Rolling median of realized vol over vol_filter_days ---
|
|
med_win = max(2, vol_filter_days * bpd)
|
|
rv_median = (
|
|
al._series_if_array(rv).rolling(med_win, min_periods=max(2, med_win // 2)).median().values
|
|
if hasattr(al, "_series_if_array")
|
|
else __import__("pandas").Series(rv).rolling(med_win, min_periods=max(2, med_win // 2)).median().values
|
|
)
|
|
|
|
# --- Gate: only enter when rv < median (low-vol regime) ---
|
|
low_vol_gate = np.where(
|
|
np.isfinite(rv) & np.isfinite(rv_median) & (rv < rv_median),
|
|
1.0,
|
|
0.0
|
|
)
|
|
gated_direction = direction * low_vol_gate
|
|
|
|
# --- Vol-target the gated direction ---
|
|
pos = al.vol_target(gated_direction, df, target_vol=0.20, vol_win_days=30, leverage_cap=2.0)
|
|
return pos
|
|
|
|
|
|
def make_target_fn(vol_filter_days: int):
|
|
def fn(df):
|
|
return cmb04_target(df, vol_filter_days=vol_filter_days)
|
|
return fn
|
|
|
|
|
|
if __name__ == "__main__":
|
|
import pandas as pd
|
|
|
|
best_rep = None
|
|
best_hold = -9.0
|
|
best_label = ""
|
|
|
|
configs = [
|
|
("CMB04-vf30", 30),
|
|
("CMB04-vf60", 60),
|
|
]
|
|
|
|
for label, vfd in configs:
|
|
fn = make_target_fn(vfd)
|
|
rep = al.study_weights(label, fn, tfs=("1d", "12h"))
|
|
v = rep["verdict"]
|
|
h = v.get("best_holdout_sharpe", -9)
|
|
print(al.fmt(rep))
|
|
print(f" [grid] {label}: holdout={h:.3f}")
|
|
if h > best_hold:
|
|
best_hold = h
|
|
best_rep = rep
|
|
best_label = label
|
|
|
|
print("\n=== BEST CONFIG ===", best_label)
|
|
print(al.fmt(best_rep))
|
|
print("JSON:", al.as_json(best_rep))
|