Files
Adriano Dal Pastro 5ac4e16af8 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>
2026-06-20 19:50:39 +00:00

105 lines
3.6 KiB
Python

"""RSK04 — Momentum-of-Momentum Sizing
HYPOTHESIS: Size the TSMOM (long-flat) position by the STABILITY/AGREEMENT of
multi-horizon momentum signals. When all horizons agree (strong consensus), take
a larger position. When signals disagree, reduce exposure.
MECHANISM:
- Compute TSMOM signals for 3 horizons: 1M, 3M, 6M (same as TP01 canonical)
- Direction = go long only if net signal > 0 (majority bullish), else flat
- SIZE = fraction of horizons that agree with the majority direction
e.g. all 3 agree -> size=1.0, 2/3 agree -> size=0.667, 1/3 -> flat
- Apply vol-targeting on top of the sized position
INTERNAL GRID (<=4 configs x 2 assets x 2 TFs = <=16 backtests):
A: horizons=(1M,3M,6M), size by fraction-agreement
B: horizons=(1M,3M,6M,12M), size by fraction-agreement (4 horizons)
Two TFs: 1d, 12h -> 2 configs x 2 tfs x 2 assets = 8 backtests total
CAUSAL: all signals use close[i] for the past horizon -> no leakage.
"""
import sys
sys.path.insert(0, "/opt/docker/PythagorasGoal/scripts/research/alt")
import altlib as al
import numpy as np
def make_target(horizons_months, tf):
"""Return a target_fn(df) that implements momentum-of-momentum sizing."""
def target_fn(df):
c = df["close"].values.astype(float)
n = len(c)
bpd = al.bars_per_day(df)
# Compute per-horizon signals: +1 (bullish) or 0 (bearish/flat)
# Signal at bar i: sign of return over last `h` bars
signals = []
for months in horizons_months:
h = int(round(months * 30.44 * bpd))
h = max(h, 2)
sig = np.zeros(n)
# causal: sig[i] uses close[i] vs close[i-h]
sig[h:] = np.where(c[h:] / c[:n-h] > 1.0, 1.0, 0.0)
# NaN guard: first h bars stay 0
signals.append(sig)
signals = np.stack(signals, axis=1) # shape (n, num_horizons)
num_horizons = len(horizons_months)
# Net bullish count at each bar
bullish_count = signals.sum(axis=1) # in [0, num_horizons]
bearish_count = num_horizons - bullish_count
# Direction: go long only if strict majority bullish
direction = np.where(bullish_count > num_horizons / 2, 1.0, 0.0)
# Size = fraction of horizons agreeing with the direction taken
# If long: fraction_agree = bullish_count / num_horizons
# If flat (direction=0): size = 0
fraction_agree = np.where(
direction > 0,
bullish_count / num_horizons,
0.0
)
# Apply vol-targeting with the agreement-sized direction
# We pass the sized direction (0..1) into vol_target as if it were direction
target = al.vol_target(fraction_agree, df, target_vol=0.20,
vol_win_days=30, leverage_cap=2.0)
return target
return target_fn
# Config A: 3 horizons (1M, 3M, 6M)
horizons_A = [1, 3, 6]
# Config B: 4 horizons (1M, 3M, 6M, 12M)
horizons_B = [1, 3, 6, 12]
# Run on 1d and 12h timeframes
rep_A = al.study_weights(
"RSK04-A(1M3M6M)",
make_target(horizons_A, "1d"),
tfs=("1d", "12h")
)
rep_B = al.study_weights(
"RSK04-B(1M3M6M12M)",
make_target(horizons_B, "1d"),
tfs=("1d", "12h")
)
print("=== RSK04: Momentum-of-Momentum Sizing ===\n")
print(al.fmt(rep_A))
print()
print(al.fmt(rep_B))
print()
print("JSON:", al.as_json(rep_A))
print("JSON:", al.as_json(rep_B))
# Determine best config by holdout sharpe
best_rep = max([rep_A, rep_B],
key=lambda r: r["verdict"].get("best_holdout_sharpe", -99))
print("\n=== BEST CONFIG ===")
print(al.fmt(best_rep))
print("JSON_BEST:", al.as_json(best_rep))