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>
96 lines
3.1 KiB
Python
96 lines
3.1 KiB
Python
"""TRD09 — Aroon Trend Strategy
|
|
Aroon(period): long when AroonUp > AroonDown AND AroonUp > 70.
|
|
Uses vol-targeting (TP01-style) for position sizing.
|
|
"""
|
|
import sys
|
|
sys.path.insert(0, "/opt/docker/PythagorasGoal/scripts/research/alt")
|
|
import altlib as al
|
|
import numpy as np
|
|
|
|
|
|
def aroon(df, period: int = 25):
|
|
"""Compute Aroon Up and Aroon Down (causal).
|
|
AroonUp[i] = 100 * (bars since highest high in [i-period..i]) / period
|
|
AroonDown[i] = 100 * (bars since lowest low in [i-period..i]) / period
|
|
Both in [0, 100].
|
|
"""
|
|
high = df["high"].values.astype(float)
|
|
low = df["low"].values.astype(float)
|
|
n = len(high)
|
|
aroon_up = np.full(n, np.nan)
|
|
aroon_down = np.full(n, np.nan)
|
|
|
|
# Vectorized using pandas rolling argmax/argmin
|
|
import pandas as pd
|
|
h_series = pd.Series(high)
|
|
l_series = pd.Series(low)
|
|
|
|
for i in range(period, n):
|
|
window_h = high[i - period: i + 1]
|
|
window_l = low[i - period: i + 1]
|
|
# position of max/min within window (0=oldest, period=current)
|
|
idx_max = np.argmax(window_h) # periods ago = period - idx_max
|
|
idx_min = np.argmin(window_l)
|
|
aroon_up[i] = 100.0 * idx_max / period
|
|
aroon_down[i] = 100.0 * idx_min / period
|
|
|
|
return aroon_up, aroon_down
|
|
|
|
|
|
def make_target(period: int = 25, threshold: float = 70.0, use_vol_target: bool = True):
|
|
"""Return a target function for al.study_weights."""
|
|
def target_fn(df):
|
|
up, dn = aroon(df, period)
|
|
# Long signal: AroonUp > AroonDown AND AroonUp > threshold
|
|
direction = np.where(
|
|
(up > dn) & (up > threshold),
|
|
1.0,
|
|
0.0 # flat otherwise (long-flat, no short)
|
|
)
|
|
direction[~np.isfinite(up)] = 0.0
|
|
|
|
if use_vol_target:
|
|
return al.vol_target(direction, df, target_vol=0.20, vol_win_days=30, leverage_cap=2.0)
|
|
else:
|
|
return direction
|
|
|
|
return target_fn
|
|
|
|
|
|
if __name__ == "__main__":
|
|
# Small grid: period x threshold (4 combos max)
|
|
configs = [
|
|
{"period": 25, "threshold": 70.0},
|
|
{"period": 14, "threshold": 70.0},
|
|
{"period": 25, "threshold": 60.0},
|
|
{"period": 40, "threshold": 70.0},
|
|
]
|
|
|
|
best_rep = None
|
|
best_score = -999.0
|
|
|
|
for cfg in configs:
|
|
name = f"TRD09_p{cfg['period']}_t{int(cfg['threshold'])}"
|
|
print(f"\n=== Running {name} ===")
|
|
fn = make_target(period=cfg["period"], threshold=cfg["threshold"])
|
|
rep = al.study_weights(name, fn, tfs=("1d",))
|
|
print(al.fmt(rep))
|
|
|
|
# Score = min of BTC/ETH hold-out sharpe
|
|
cells = rep.get("cells", [])
|
|
if cells:
|
|
cell = cells[0] # 1d
|
|
pa = cell.get("per_asset", {})
|
|
btc_ho = pa.get("BTC", {}).get("holdout", {}).get("sharpe", -999)
|
|
eth_ho = pa.get("ETH", {}).get("holdout", {}).get("sharpe", -999)
|
|
score = min(btc_ho, eth_ho)
|
|
if score > best_score:
|
|
best_score = score
|
|
best_rep = rep
|
|
best_cfg = cfg
|
|
|
|
print("\n\n=== BEST CONFIG ===")
|
|
print(f"Config: {best_cfg}")
|
|
print(al.fmt(best_rep))
|
|
print("JSON:", al.as_json(best_rep))
|