feat(games): sessione 2 del gioco Blind Traders su timing diversi (30m/2h/4h)

- engine: resampling (_RESAMPLE) per 30m/2h/4h/1d + TF_BPM esteso -> nuovi timing.
- arena/run_game: TIMEFRAMES estesi, out_name e GAME_SPECS_DIR/GAME_OUT parametrizzati
  (game 1 non sovrascritto).
- Risultato: 10 finalisti tutti 30m pairs ETH/BTC (vincitore #36: OOS Sh 12.3, 43 tr/mese).
  La regola >=10 trade/mese filtra i tf lunghi (4h: 4/33 qualificati). Conferma la
  frontiera frequenza-vs-edge. Diario 2026-06-09-blind-traders-game2.md.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Adriano Dal Pastro
2026-06-09 13:01:34 +00:00
parent abc1c1cb80
commit d3dab57532
5 changed files with 74 additions and 9 deletions
+24 -3
View File
@@ -18,8 +18,13 @@ import pandas as pd
from src.data.downloader import load_data
FEE_RT = 0.001 # 0.10% round-trip (taker Deribit, baseline progetto)
TF_BPM = {"5m": 12 * 24 * 30, "15m": 4 * 24 * 30, "1h": 24 * 30} # barre/mese per tf
TF_BPM = {"5m": 12 * 24 * 30, "15m": 4 * 24 * 30, "30m": 2 * 24 * 30,
"1h": 24 * 30, "2h": 12 * 30, "4h": 6 * 30, "1d": 30} # barre/mese per tf
MIN_TRADES_PER_MONTH = 10.0
# timeframe non presenti come parquet -> resamplati da una base (open=first,
# high=max, low=min, close=last, volume=sum). Permette "timing diversi" nel gioco.
_RESAMPLE = {"30m": ("15m", "30min"), "2h": ("1h", "2h"),
"4h": ("1h", "4h"), "1d": ("1h", "1D")}
# Slippage per LATO (oltre alle fee). 0 = come prima. Single-leg paga 2 lati
# (ingresso+uscita), i pairs ne pagano 4 (2 gambe x 2 lati).
@@ -34,14 +39,30 @@ def set_slippage(slip_per_side: float):
# --------------------------------------------------------------------------
# Dati anonimizzati
# --------------------------------------------------------------------------
def _load_tf(asset: str, tf: str):
"""Carica un asset al timeframe tf (parquet diretto, o resample da una base)."""
if tf in _RESAMPLE:
base_tf, rule = _RESAMPLE[tf]
d = load_data(asset, base_tf).copy()
d["dt"] = pd.to_datetime(d["datetime"])
g = d.set_index("dt").resample(rule).agg(
{"open": "first", "high": "max", "low": "min", "close": "last",
"volume": "sum"}).dropna(subset=["open", "close"])
g = g.reset_index()
g["datetime"] = g["dt"]
g["timestamp"] = (g["dt"].astype("int64") // 1_000_000)
return g.drop(columns=["dt"])
return load_data(asset, tf).copy()
def load_anon(tf: str = "1h"):
"""Carica BTC->A, ETH->B allineati sull'intersezione temporale.
Ritorna un dict con array OHLC per A e B + datetime. I nomi reali NON
compaiono: gli agenti vedono solo 'A' e 'B'.
"""
btc = load_data("BTC", tf).copy()
eth = load_data("ETH", tf).copy()
btc = _load_tf("BTC", tf)
eth = _load_tf("ETH", tf)
for d in (btc, eth):
d["dt"] = pd.to_datetime(d["datetime"])
btc = btc.set_index("dt")