sweep runner: per-config isolation, counted trials = evaluated configs
Browse files
sweep.py
CHANGED
|
@@ -88,12 +88,20 @@ def main() -> int:
|
|
| 88 |
|
| 89 |
# --- full-sample net returns per config -----------------------------
|
| 90 |
returns: dict[str, np.ndarray] = {}
|
|
|
|
| 91 |
for i, (name, (fn, kw)) in enumerate(grid.items()):
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 95 |
if (i + 1) % 25 == 0:
|
| 96 |
print(f"[sweep] {i+1}/{n_trials} backtests done", flush=True)
|
|
|
|
|
|
|
|
|
|
| 97 |
|
| 98 |
sr = {n: float(np.nanmean(r) / (np.nanstd(r, ddof=1) + 1e-12))
|
| 99 |
for n, r in returns.items()}
|
|
@@ -159,6 +167,8 @@ def main() -> int:
|
|
| 159 |
"data": "Avi-L/crypto-quant-eval-data",
|
| 160 |
"n_bars": len(bars),
|
| 161 |
"n_trials": n_trials,
|
|
|
|
|
|
|
| 162 |
"pbo_splits": args.pbo_splits,
|
| 163 |
"grid": trials,
|
| 164 |
"best_config": best,
|
|
|
|
| 88 |
|
| 89 |
# --- full-sample net returns per config -----------------------------
|
| 90 |
returns: dict[str, np.ndarray] = {}
|
| 91 |
+
failures: dict[str, str] = {}
|
| 92 |
for i, (name, (fn, kw)) in enumerate(grid.items()):
|
| 93 |
+
try:
|
| 94 |
+
pos = fn(bars, funding, **kw)
|
| 95 |
+
bt = run_backtest(bars, pos, funding)
|
| 96 |
+
returns[name] = bt["net_return"].to_numpy()
|
| 97 |
+
except Exception as e: # one bad config must not discard the sweep
|
| 98 |
+
failures[name] = repr(e)
|
| 99 |
+
print(f"[sweep] CONFIG FAILED {name}: {e}", flush=True)
|
| 100 |
if (i + 1) % 25 == 0:
|
| 101 |
print(f"[sweep] {i+1}/{n_trials} backtests done", flush=True)
|
| 102 |
+
if failures:
|
| 103 |
+
print(f"[sweep] {len(failures)} configs failed", flush=True)
|
| 104 |
+
n_trials = len(returns) # counted trials = configs actually evaluated
|
| 105 |
|
| 106 |
sr = {n: float(np.nanmean(r) / (np.nanstd(r, ddof=1) + 1e-12))
|
| 107 |
for n, r in returns.items()}
|
|
|
|
| 167 |
"data": "Avi-L/crypto-quant-eval-data",
|
| 168 |
"n_bars": len(bars),
|
| 169 |
"n_trials": n_trials,
|
| 170 |
+
"n_configs_failed": len(failures),
|
| 171 |
+
"config_failures": failures,
|
| 172 |
"pbo_splits": args.pbo_splits,
|
| 173 |
"grid": trials,
|
| 174 |
"best_config": best,
|