"""Phase 3 gate — computational performance and stylized facts at N = 100, 1,000, 10,000 traders (no API).""" from __future__ import annotations import json import sys import time from pathlib import Path sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "src")) from market_agents.experiments.config import RunConfig # noqa: E402 from market_agents.experiments.runner import run_config # noqa: E402 from market_agents.metrics.outcomes import run_outcomes # noqa: E402 ROOT = Path(__file__).resolve().parents[1] rows = [] for n, seeds in ((100, [1, 2, 3]), (1000, [1, 2, 3]), (10000, [1])): for s in seeds: act = {k: v * 100.0 / n for k, v in RunConfig().population.activity.items()} # constant order flow per tick cfg = RunConfig.from_yaml(ROOT / "configs/baseline.yaml", **{"name": f"scale_{n}", "seed": s, "population.n_traders": n, "population.activity": act}) t0 = time.perf_counter() res = run_config(cfg) oc = run_outcomes(res) oc["wall_s"] = time.perf_counter() - t0 oc["n_orders"] = int(res.agents["n_orders"].sum()) rows.append(oc) print(f"N={n} seed={s}: {oc['wall_s']:.1f}s, {oc['n_trades']} trades, {oc['n_orders']} orders, mad={oc['mad_pct']:.2f}% " f"acf1={oc['acf_r_1']:.2f} kurt={oc['kurtosis']:.1f} spread={oc['spread_bp']:.1f}bp", flush=True) out = ROOT / "results/calibration" out.mkdir(parents=True, exist_ok=True) with open(out / "scale_benchmark.json", "w") as f: json.dump(rows, f, indent=1, default=float)