INNER CODE UNIT · Python
min_names
initial-d/ml-quant-trading · src/mlquant/cli/main.py:314
min_names = max(5, math.ceil((1.0 - mk_cfg.cash_weight) / mk_cfg.weight_cap - 1e-9))
weights = np.zeros_like(pred)
for t in range(max(look_back, oos), T - 1):
tradable = mask[t]
idx = np.where(tradable)[0]
if idx.size < min_names:
continue
mu = pred[t, idx].astype(np.float64)
history = rets[t - look_back:t, idx]
try:
w = opt.solve(mu, history)
except Exception as exc: # pragma: no cover
click.echo(f"[warn] solver failed at t={t}: {exc}")
continue
weights[t, idx] = w
torch.save({"weights": torch.from_numpy(weights)}, art / "weights.pt")
click.echo(f"wrote weights: {weights.shape}")