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>
91 lines
3.2 KiB
Python
91 lines
3.2 KiB
Python
"""SEA01 — Hour-of-day expectancy (seasonal/intraday pattern).
|
|
|
|
IDEA: On 1h bars, compute per-UTC-hour mean return using an EXPANDING in-sample
|
|
window (strictly causal). Go long during hours whose expanding-window mean is
|
|
positive, flat otherwise. Position is vol-targeted.
|
|
|
|
Causal guarantee:
|
|
- At bar i (UTC hour h), we compute the mean return for hour h using all
|
|
*prior* bars with that same hour: mean_r[h] = mean(r[j] for j < i where hour[j] == h).
|
|
- We assign target[i] based on mean_r[h at bar i], which uses data up to i-1.
|
|
- The lib then holds target[i] during bar i+1 (shift done by lib).
|
|
|
|
Grid: we test different minimum-samples thresholds (how many past observations of
|
|
that hour are required before we take a position): [30, 90].
|
|
This keeps total backtests at 2 TFs x 2 params x 2 assets = 8, but study_weights
|
|
handles BTC+ETH internally — so 2 TFs x 2 params = 4 calls total.
|
|
"""
|
|
|
|
import sys
|
|
sys.path.insert(0, "/opt/docker/PythagorasGoal/scripts/research/alt")
|
|
import altlib as al
|
|
import numpy as np
|
|
import pandas as pd
|
|
|
|
|
|
def sea01_target(df: pd.DataFrame, min_samples: int = 30) -> np.ndarray:
|
|
"""Compute vol-targeted position based on expanding per-hour mean return.
|
|
|
|
For each bar i:
|
|
- UTC hour = df['datetime'][i].hour
|
|
- expanding mean of past returns for that same UTC hour (uses only j < i)
|
|
- if expanding mean > 0 and count >= min_samples: direction = +1
|
|
- else: flat = 0
|
|
Then vol-target the direction signal.
|
|
"""
|
|
dt = pd.to_datetime(df["datetime"])
|
|
c = df["close"].values.astype(float)
|
|
r = al.simple_returns(c) # r[i] = c[i]/c[i-1] - 1
|
|
n = len(df)
|
|
|
|
# For each bar, compute expanding mean return per UTC hour
|
|
hours = dt.dt.hour.values # 0..23
|
|
|
|
# We'll compute causally using cumulative sums per hour
|
|
# hour_cumsum[h], hour_count[h] track sum/count up to bar i-1 for hour h
|
|
hour_cumsum = np.zeros(24, dtype=float)
|
|
hour_count = np.zeros(24, dtype=int)
|
|
|
|
direction = np.zeros(n, dtype=float)
|
|
|
|
for i in range(n):
|
|
h = hours[i]
|
|
cnt = hour_count[h]
|
|
if cnt >= min_samples:
|
|
mean_r = hour_cumsum[h] / cnt
|
|
direction[i] = 1.0 if mean_r > 0.0 else 0.0
|
|
# else flat (direction[i] = 0)
|
|
|
|
# Update with bar i's return (causal: used for bar i+1 onwards)
|
|
hour_cumsum[h] += r[i]
|
|
hour_count[h] += 1
|
|
|
|
# Vol-target the binary direction signal
|
|
tgt = al.vol_target(direction, df, target_vol=0.20, vol_win_days=30, leverage_cap=2.0)
|
|
return tgt
|
|
|
|
|
|
if __name__ == "__main__":
|
|
best_rep = None
|
|
best_sharpe = -999.0
|
|
|
|
for min_samples in [30, 90]:
|
|
name = f"SEA01-ms{min_samples}"
|
|
rep = al.study_weights(
|
|
name,
|
|
lambda df, ms=min_samples: sea01_target(df, min_samples=ms),
|
|
tfs=("1h",),
|
|
)
|
|
print(al.fmt(rep))
|
|
print("JSON:", al.as_json(rep))
|
|
|
|
# Track best by min_asset_full_sharpe
|
|
s = rep["verdict"].get("best_full_sharpe", rep.get("min_asset_full_sharpe", -999))
|
|
if s > best_sharpe:
|
|
best_sharpe = s
|
|
best_rep = rep
|
|
|
|
print("\n=== BEST CONFIG ===")
|
|
print(al.fmt(best_rep))
|
|
print("JSON:", al.as_json(best_rep))
|