14522262e6
Reset del progetto su fondamenta verificate dopo la scoperta che l'intera libreria "validata OOS" era artefatto di feed contaminato (print fantasma del feed Cerbero TESTNET + storico Binance/USDT). - Storico ricostruito da Deribit MAINNET (ccxt pubblico, tokenless) e CERTIFICATO (certify_feed.py): BTC/ETH puliti su TUTTA la storia (mediana 2-6 bps vs Coinbase USD), integrita' OHLC + coerenza resample (maxΔ 0.00) + cross-venue OK. Alt esclusi (illiquidi/divergenti: LTC/DOGE 50-82% barre flat; XRP/BNB non certificabili). - Verdetto sul feed pulito: FADE / PAIRS / XS01 / TSM01 morti (ogni portafoglio Sharpe -2.3..-3.0, DD ~40%); solo SH01 e frammenti HONEST con segnale residuo, da ri-validare in isolamento. - Cleanup "restart pulito": strategie, stack live (src/live, src/portfolio, runner/executor, yml, docker), ~100 script ricerca/gate, waste/games/ portfolios, dati non certificati + cache e 60+ diari -> archiviati in Old/ (preservati, non cancellati). Diario consolidato in un unico documento. - Skeleton ricerca tenuto: Strategy ABC + indicatori + src/fractal + src/backtest/engine + load_data; tool dati certificati (rebuild_history, certify_feed, audit_feed, multi_source_check). - Universo dati ATTIVO: solo BTC/ETH (5m/15m/1h); guardrail fisico (load_data su alt -> FileNotFoundError). Esecuzione DISABILITATA, conto flat. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
45 lines
1.8 KiB
Python
45 lines
1.8 KiB
Python
import numpy as np
|
|
import pandas as pd
|
|
from src.live.tsmom_worker import TsmomWorker
|
|
|
|
|
|
def _df(n=300, slope=1.0):
|
|
c = np.linspace(100, 100 + slope * n, n)
|
|
ts = (pd.date_range("2023-01-01", periods=n, freq="1D", tz="UTC").astype("int64") // 10**6)
|
|
return pd.DataFrame({"timestamp": ts, "open": c, "high": c, "low": c, "close": c, "volume": 1.0})
|
|
|
|
|
|
def test_tsmom_selects_full_consensus_uptrend(tmp_path):
|
|
# tutti gli orizzonti positivi -> score=1>=thr; BTC su -> risk_on
|
|
w = TsmomWorker(universe=["BTC", "AAA"], horizons=(63, 126, 252), thr=1.0,
|
|
gross=0.30, data_dir=tmp_path)
|
|
data = {"BTC": _df(slope=1.0), "AAA": _df(slope=2.0)}
|
|
w.tick(data)
|
|
assert w.weights["BTC"] > 0 and w.weights["AAA"] > 0
|
|
assert abs(sum(w.weights.values()) - 0.30) < 1e-9
|
|
|
|
|
|
def test_tsmom_flat_when_risk_off(tmp_path):
|
|
w = TsmomWorker(universe=["BTC", "AAA"], thr=1.0, gross=0.30, data_dir=tmp_path)
|
|
data = {"BTC": _df(slope=-1.0), "AAA": _df(slope=2.0)}
|
|
w.tick(data)
|
|
assert sum(w.weights.values()) == 0.0
|
|
|
|
|
|
def test_tsmom_persists_and_resumes(tmp_path):
|
|
w = TsmomWorker(universe=["BTC", "AAA"], gross=0.30, data_dir=tmp_path)
|
|
w.tick({"BTC": _df(slope=1.0), "AAA": _df(slope=2.0)})
|
|
w2 = TsmomWorker(universe=["BTC", "AAA"], gross=0.30, data_dir=tmp_path)
|
|
assert w2.weights == w.weights
|
|
|
|
|
|
def test_tsmom_warns_on_short_panel(tmp_path, monkeypatch):
|
|
# worker GIA' operativo + panel sotto need=253 -> WARN invece di silent return
|
|
calls = []
|
|
monkeypatch.setattr("src.live.telegram_notifier.notify_event",
|
|
lambda e, d=None: calls.append(e))
|
|
w = TsmomWorker(universe=["BTC", "AAA"], gross=0.30, data_dir=tmp_path)
|
|
w.last_bar_ts = 123
|
|
w.tick({"BTC": _df(n=100), "AAA": _df(n=100)})
|
|
assert calls == ["PANEL_SHORT"] and w._panel_warned
|