INNER CODE UNIT · Python
cmd_backtest
initial-d/ml-quant-trading · src/mlquant/cli/main.py:335
def cmd_backtest(config_path: str) -> None:
cfg = load_config(config_path)
art = _artifacts_dir(cfg)
panel_blob = torch.load(art / "panel.pt", weights_only=False)
weight_blob = torch.load(art / "weights.pt", weights_only=False)
pred_path = art / "predictions.pt"
oos = 0
if pred_path.exists():
oos = int(torch.load(pred_path, weights_only=False).get("oos_start", 0))
# Halt-aware returns: loaders zero-fill halted prices.
rets = _load_panel(art).returns.numpy()
weights = weight_blob["weights"].numpy()
costs_bps = cfg.get("costs_bps", 5.0)
# Score only the out-of-sample window; the engine charges the entry
# trade on its first row.
res = run_backtest(weights[oos:], rets[oos:], costs_bps=costs_bps)