d3dab57532
- 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>
85 lines
3.2 KiB
Python
85 lines
3.2 KiB
Python
"""
|
|
run_game — carica le 100 strategie proposte dagli agenti ciechi (file in
|
|
data/games/specs/agent_*.json), lancia il torneo (epoche + cull) e stampa la
|
|
classifica finale, poi RIVELA cosa erano X e Y.
|
|
|
|
Se mancano agenti (file assenti o malformati) riempie con spec casuali, cosi'
|
|
il gioco gira sempre a 100 concorrenti.
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
import os
|
|
import random
|
|
from pathlib import Path
|
|
|
|
from scripts.games import engine
|
|
from scripts.games.arena import random_spec, run_tournament, leaderboard, _normalize
|
|
|
|
SPECS_DIR = Path(os.environ.get("GAME_SPECS_DIR", "data/games/specs"))
|
|
OUT_NAME = os.environ.get("GAME_OUT", "tournament_result.json")
|
|
N = 100
|
|
|
|
|
|
def load_specs():
|
|
rng = random.Random(123)
|
|
specs, briefs, sources = [], [], []
|
|
for i in range(N):
|
|
f = SPECS_DIR / f"agent_{i}.json"
|
|
spec = None
|
|
if f.exists():
|
|
try:
|
|
raw = json.loads(f.read_text())
|
|
fam = raw.get("family")
|
|
params = dict(raw.get("params", {}))
|
|
if "direction" in raw and "direction" not in params:
|
|
params["direction"] = raw["direction"]
|
|
spec = {"family": fam, "series": raw.get("series", "A"),
|
|
"tf": raw.get("tf", "1h"), "params": params}
|
|
# X->A, Y->B mapping (gli agenti vedono X/Y)
|
|
s = spec["series"]
|
|
spec["series"] = {"X": "A", "Y": "B", "AB": "AB",
|
|
"A": "A", "B": "B"}.get(s, "A")
|
|
spec = _normalize(spec)
|
|
briefs.append(str(raw.get("hypothesis", ""))[:300])
|
|
sources.append("agent")
|
|
except Exception as e:
|
|
spec = None
|
|
if spec is None:
|
|
spec = random_spec(rng)
|
|
briefs.append("(spec mancante -> sostituto casuale)")
|
|
sources.append("random")
|
|
specs.append(spec)
|
|
n_agent = sources.count("agent")
|
|
print(f"caricati {n_agent}/{N} spec da agenti reali, "
|
|
f"{N - n_agent} sostituiti casuali")
|
|
return specs, briefs
|
|
|
|
|
|
def main():
|
|
slip = float(os.environ.get("GAME_SLIP", "0.0"))
|
|
engine.set_slippage(slip)
|
|
if slip > 0:
|
|
print(f"SLIPPAGE attivo: {slip*100:.3f}%/lato "
|
|
f"(single-leg {2*slip*100:.2f}% RT extra, pairs {4*slip*100:.2f}% extra)")
|
|
specs, briefs = load_specs()
|
|
payload = run_tournament(specs, briefs=briefs, seed=2026,
|
|
epochs=90, cull_every=10, cull_n=10, out_name=OUT_NAME)
|
|
leaderboard(payload, top=10)
|
|
rev = payload["reveal"]
|
|
print(f"\n>>> RIVELAZIONE: Serie X = {rev['A']}, Serie Y = {rev['B']} "
|
|
f"(timeframe base {rev['tf']}). Gli agenti non lo sapevano. <<<")
|
|
# vincitore
|
|
w = payload["results"][0]
|
|
sp = w["spec"]
|
|
print(f"\nVINCITORE: agente #{w['agent']} su {w['tf']} | {sp['family']} "
|
|
f"{sp['series']} {sp['params'].get('direction','')}")
|
|
print(f" ipotesi dell'agente: {w['brief']}")
|
|
print(f" TEST(OOS): PnL {w['test']['pnl_pct']:.0f}% | win "
|
|
f"{w['test']['win_rate']*100:.0f}% | {w['test']['tpm']:.1f} trade/mese "
|
|
f"| Sharpe {w['test']['sharpe']:.1f}")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|