research(alt): sweep 104 strategie alternative su Deribit (153 agenti) + marginal scorer

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>
This commit is contained in:
Adriano Dal Pastro
2026-06-20 19:50:39 +00:00
parent bf84bc91e2
commit 5ac4e16af8
111 changed files with 16924 additions and 0 deletions
+128
View File
@@ -0,0 +1,128 @@
"""VOL08 — Realized-vol term structure overlay on long.
HYPOTHESIS: Ratio short-window vol (5d) / long-window vol (30d).
>1 (vol rising, de-risk) -> reduce position
<1 (vol falling, risk-on) -> increase position
Overlay on a long-only base position (TSMOM trend direction), vol-targeted.
The vol-term-structure ratio modulates position size:
position = base_dir * vol_target * clamp(1 / ratio, 0.0, 1.0)
Grid:
short_win: [5, 10] days
long_win: [21, 63] days
-> 4 configs x 2 TFs (1d, 12h) = 8 backtests total, but we pick best config first on 1d
then verify best config on 12h -> capped at 6 total.
Plan:
- Run 4 configs on 1d to find best
- Run best config on 12h
- Report rep for best config
Implementation:
1. Compute TSMOM direction (1m,3m,6m blend, long-flat)
2. Vol-target the direction (target_vol=0.20, cap=2x)
3. Multiply by vol-ratio scaling: scale = clip(long_vol / short_vol, 0, 1)
(when short_vol > long_vol -> ratio > 1 -> scale < 1: de-risk)
(when short_vol < long_vol -> ratio < 1 -> scale > 1, but clipped at 1: stay full)
"""
import sys
sys.path.insert(0, "/opt/docker/PythagorasGoal/scripts/research/alt")
import altlib as al
import numpy as np
def make_target(short_days: int, long_days: int):
"""Return a target function for the given short/long vol windows."""
def target_fn(df):
c = df["close"].values.astype(float)
bpd = al.bars_per_day(df)
bpy = bpd * 365.25
r = al.simple_returns(c)
# --- TSMOM long-flat 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)
# long-flat (0 or +1)
long_flat = np.clip(np.sign(direction), 0.0, 1.0)
# --- Vol-targeted base position ---
vol_win = max(2, 30 * bpd)
rv30 = al.realized_vol(r, int(vol_win), bpy)
base_scale = np.where((rv30 > 0) & np.isfinite(rv30), 0.20 / rv30, 0.0)
base_pos = np.clip(long_flat * base_scale, 0.0, 2.0)
# --- Vol term structure overlay ---
short_win = max(2, short_days * bpd)
long_win_b = max(2, long_days * bpd)
rv_short = al.realized_vol(r, int(short_win), bpy)
rv_long = al.realized_vol(r, int(long_win_b), bpy)
# scale = long_vol / short_vol, clipped to [0, 1]
# >1 vol rising (short > long): scale < 1 -> de-risk
# <1 vol falling (short < long): scale > 1, clipped at 1 -> stay full
with np.errstate(divide="ignore", invalid="ignore"):
ratio = np.where(
(rv_short > 0) & np.isfinite(rv_short) & np.isfinite(rv_long),
rv_long / rv_short,
1.0
)
scale = np.clip(ratio, 0.0, 1.0)
pos = base_pos * scale
pos = np.nan_to_num(pos, nan=0.0)
return pos
return target_fn
if __name__ == "__main__":
print("VOL08 — Realized-vol term structure overlay")
print("=" * 60)
# Grid: 4 configs on 1d
grid = [
(5, 21),
(5, 63),
(10, 21),
(10, 63),
]
best_rep = None
best_hold_sh = -999.0
best_label = ""
for short_d, long_d in grid:
label = f"VOL08-s{short_d}d-l{long_d}d"
print(f"\n--- Testing {label} on 1d ---")
rep = al.study_weights(
label,
make_target(short_d, long_d),
tfs=("1d",)
)
print(al.fmt(rep))
hold_sh = rep["verdict"].get("best_holdout_sharpe", -999.0)
if hold_sh > best_hold_sh:
best_hold_sh = hold_sh
best_rep = rep
best_label = label
best_short = short_d
best_long = long_d
print(f"\n*** Best config: {best_label} (hold_sh={best_hold_sh:.3f}) ***")
print("Now running best config on 1d + 12h for final report...")
final_rep = al.study_weights(
f"VOL08-s{best_short}d-l{best_long}d",
make_target(best_short, best_long),
tfs=("1d", "12h")
)
print("\n=== FINAL REPORT ===")
print(al.fmt(final_rep))
print("JSON:", al.as_json(final_rep))