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>
90 lines
3.3 KiB
Python
90 lines
3.3 KiB
Python
"""TRD11 — SMA50 slope momentum
|
|
HYPOTHESIS: Position = sign of slope of SMA(50) over last k bars (long-flat variant).
|
|
The slope of SMA(50) captures the direction of the medium-term trend.
|
|
Long-flat: go long when slope > 0, flat otherwise.
|
|
Grid: slope_window (k) in {3, 5, 10} bars.
|
|
Vol-targeted position (target_vol=20%, leverage_cap=2x).
|
|
"""
|
|
import sys
|
|
sys.path.insert(0, "/opt/docker/PythagorasGoal/scripts/research/alt")
|
|
import altlib as al
|
|
import numpy as np
|
|
|
|
|
|
def make_target(sma_period: int = 50, slope_win: int = 5, long_flat: bool = True):
|
|
"""Return a target function for study_weights.
|
|
|
|
sma_period: period of the SMA
|
|
slope_win: number of bars to measure the slope over (slope = sma[i] - sma[i-slope_win])
|
|
long_flat: if True, only go long (flat when slope <= 0); if False, long/short
|
|
"""
|
|
def target(df):
|
|
c = df["close"].values.astype(float)
|
|
s = al.sma(c, sma_period)
|
|
|
|
# Slope = change in SMA over slope_win bars (causal: uses s[i] vs s[i-slope_win])
|
|
slope = np.full(len(s), np.nan)
|
|
for i in range(slope_win, len(s)):
|
|
if np.isfinite(s[i]) and np.isfinite(s[i - slope_win]):
|
|
slope[i] = s[i] - s[i - slope_win]
|
|
|
|
# Direction signal
|
|
if long_flat:
|
|
direction = np.where(slope > 0, 1.0, 0.0)
|
|
else:
|
|
direction = np.where(slope > 0, 1.0, np.where(slope < 0, -1.0, 0.0))
|
|
|
|
# Mask NaN slope with flat
|
|
direction = np.where(np.isfinite(slope), direction, 0.0)
|
|
|
|
# Vol-target
|
|
tgt = al.vol_target(direction, df, target_vol=0.20, vol_win_days=30, leverage_cap=2.0)
|
|
return tgt
|
|
|
|
target.__name__ = f"sma{sma_period}_slope{slope_win}_{'lf' if long_flat else 'ls'}"
|
|
return target
|
|
|
|
|
|
# Small internal grid: slope windows [3, 5, 10] all long-flat, plus one L/S variant
|
|
configs = [
|
|
{"sma_period": 50, "slope_win": 3, "long_flat": True},
|
|
{"sma_period": 50, "slope_win": 5, "long_flat": True},
|
|
{"sma_period": 50, "slope_win": 10, "long_flat": True},
|
|
{"sma_period": 50, "slope_win": 5, "long_flat": False}, # L/S variant
|
|
]
|
|
|
|
best_rep = None
|
|
best_score = -999.0
|
|
|
|
for cfg in configs:
|
|
name = f"TRD11-sma{cfg['sma_period']}-k{cfg['slope_win']}-{'LF' if cfg['long_flat'] else 'LS'}"
|
|
fn = make_target(**cfg)
|
|
rep = al.study_weights(name, fn, tfs=("1d", "12h"))
|
|
|
|
# Score = min of BTC/ETH full Sharpe (most conservative)
|
|
cells = rep.get("cells", [])
|
|
best_cell_score = -999.0
|
|
for cell in cells:
|
|
pa = cell.get("per_asset", {})
|
|
btc_sh = pa.get("BTC", {}).get("full", {}).get("sharpe", -999)
|
|
eth_sh = pa.get("ETH", {}).get("full", {}).get("sharpe", -999)
|
|
min_sh = min(btc_sh, eth_sh)
|
|
# Also require positive holdout on both
|
|
btc_ho = pa.get("BTC", {}).get("holdout", {}).get("sharpe", -999)
|
|
eth_ho = pa.get("ETH", {}).get("holdout", {}).get("sharpe", -999)
|
|
if btc_ho > 0 and eth_ho > 0:
|
|
min_sh += 0.5 # bonus for positive holdout
|
|
if min_sh > best_cell_score:
|
|
best_cell_score = min_sh
|
|
|
|
if best_cell_score > best_score:
|
|
best_score = best_cell_score
|
|
best_rep = rep
|
|
print(f"\n*** NEW BEST: {name} score={best_cell_score:.3f} ***")
|
|
|
|
print(al.fmt(rep))
|
|
|
|
print("\n\n=== BEST CONFIG ===")
|
|
print(al.fmt(best_rep))
|
|
print("JSON:", al.as_json(best_rep))
|