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>
68 lines
2.0 KiB
Python
68 lines
2.0 KiB
Python
"""TRD01 — EMA Cross 20/100 Long-Flat Strategy.
|
|
|
|
HYPOTHESIS: Long when EMA(fast) > EMA(slow), else flat.
|
|
Grid: (fast, slow) in {(10,50), (20,100), (50,200)}.
|
|
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
|
|
|
|
# Grid: (fast, slow) pairs — 3 param sets, tested on 2 TFs = 6 total backtests max
|
|
GRID = [
|
|
(10, 50),
|
|
(20, 100),
|
|
(50, 200),
|
|
]
|
|
|
|
def make_target(fast: int, slow: int):
|
|
"""Returns a target_fn for the given EMA fast/slow parameters.
|
|
Signal is decided with data <= close[i] (causal EMA), vol-targeted.
|
|
"""
|
|
def target_fn(df):
|
|
c = df["close"].values.astype(float)
|
|
e_fast = al.ema(c, fast)
|
|
e_slow = al.ema(c, slow)
|
|
# Direction: +1 when fast > slow, else 0 (long-flat only)
|
|
direction = np.where(e_fast > e_slow, 1.0, 0.0)
|
|
# Warmup: NaN-out until slow EMA has enough data (approx 3x slow period)
|
|
warmup = slow * 3
|
|
direction[:warmup] = 0.0
|
|
# Vol-target the position
|
|
tgt = al.vol_target(direction, df, target_vol=0.20, vol_win_days=30, leverage_cap=2.0)
|
|
return tgt
|
|
return target_fn
|
|
|
|
|
|
def main():
|
|
best_rep = None
|
|
best_score = -9999.0
|
|
best_params = None
|
|
|
|
for (fast, slow) in GRID:
|
|
name = f"TRD01_ema{fast}_{slow}"
|
|
print(f"\n=== Testing {name} ===")
|
|
rep = al.study_weights(
|
|
name,
|
|
make_target(fast, slow),
|
|
tfs=("1d", "12h"),
|
|
)
|
|
verdict = rep["verdict"]
|
|
score = verdict.get("best_holdout_sharpe", -9999.0) or -9999.0
|
|
print(al.fmt(rep))
|
|
print("JSON:", al.as_json(rep))
|
|
|
|
if score > best_score:
|
|
best_score = score
|
|
best_rep = rep
|
|
best_params = (fast, slow)
|
|
|
|
print(f"\n\n=== BEST CONFIG: EMA({best_params[0]},{best_params[1]}) ===")
|
|
print(al.fmt(best_rep))
|
|
print("JSON:", al.as_json(best_rep))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|