{"record":{"id":"c45b89097a7bd123","repo":"HKUDS/Vibe-Trading","slug":"n-steps-and-n-paths-must-be-1-got-n-steps-an","errorCode":null,"errorMessage":"n_steps and n_paths must be >= 1, got {n_steps} and {n_paths}","messagePattern":"n_steps and n_paths must be >= 1, got (.+?) and (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"agent/src/quantlib/risk.py","lineNumber":563,"sourceCode":"            is then NOT reproducible.\n        steps_per_year: Steps per year, i.e. ``dt = 1 / steps_per_year``.\n            Defaults to the 252-day trading year.\n\n    Returns:\n        Price matrix of shape ``(n_paths, n_steps + 1)``. Column 0 is exactly\n        ``s0`` on every path, so ``paths[:, -1] / paths[:, 0] - 1`` is the total\n        return over the whole simulation.\n\n    Raises:\n        ValueError: If ``s0`` is not positive, ``sigma`` is negative, or any of\n            ``n_steps`` / ``n_paths`` / ``steps_per_year`` is below 1.\n    \"\"\"\n    if s0 <= 0.0:\n        raise ValueError(f\"s0 must be > 0, got {s0}\")\n    if sigma < 0.0:\n        raise ValueError(f\"sigma must be >= 0, got {sigma}\")\n    if n_steps < 1 or n_paths < 1:\n        raise ValueError(f\"n_steps and n_paths must be >= 1, got {n_steps} and {n_paths}\")\n    if steps_per_year < 1:\n        raise ValueError(f\"steps_per_year must be >= 1, got {steps_per_year}\")\n\n    dt = 1.0 / steps_per_year\n    rng = np.random.default_rng(seed)\n    shocks = rng.standard_normal((n_paths, n_steps))\n    log_returns = (mu - 0.5 * sigma**2) * dt + sigma * np.sqrt(dt) * shocks\n    paths = np.empty((n_paths, n_steps + 1), dtype=float)\n    paths[:, 0] = s0\n    paths[:, 1:] = s0 * np.exp(np.cumsum(log_returns, axis=1))\n    return paths\n\n\ndef analyze_mc_results(paths: np.ndarray, confidence: float = 0.95) -> dict:\n    \"\"\"Summarise the terminal distribution of a simulated price matrix.\n\n    Args:\n        paths: Price matrix of shape ``(n_paths, n_steps + 1)`` as returned by","sourceCodeStart":545,"sourceCodeEnd":581,"githubUrl":"https://github.com/HKUDS/Vibe-Trading/blob/80ffdda44c5c4db0dd84d70e051cca591cea67df/agent/src/quantlib/risk.py#L545-L581","documentation":"monte_carlo_gbm needs at least one time step and at least one path — the shock matrix is shaped (n_paths, n_steps), so either being below 1 makes the simulation empty and meaningless. Both are checked together with a combined message.","triggerScenarios":"monte_carlo_gbm(..., n_steps=0) (e.g. horizon computed as 0 steps), n_paths=0 from a config default, or integer division truncating to zero (days // step_size when days < step_size).","commonSituations":"Short horizons with coarse step sizes; config typos; dynamic path counts from a budget variable that evaluates to 0.","solutions":["Use max(1, computed_steps) / max(1, n_paths)","Fix step-size arithmetic so requested horizons map to >= 1 step","Validate simulation parameters in config before the run"],"exampleFix":"// before\npaths = monte_carlo_gbm(s0=100, mu=0.05, sigma=0.2, n_steps=days // 252, n_paths=n)\n// after\npaths = monte_carlo_gbm(s0=100, mu=0.05, sigma=0.2, n_steps=max(1, days // 252), n_paths=max(1, n))","handlingStrategy":"validation","validationCode":"n_steps = max(1, int(n_steps))\nn_paths = max(1, int(n_paths))","typeGuard":"def are_valid_sim_dims(n_steps, n_paths) -> bool:\n    return int(n_steps) >= 1 and int(n_paths) >= 1","tryCatchPattern":"try:\n    paths = monte_carlo_gbm(..., n_steps=n_steps, n_paths=n_paths)\nexcept ValueError as e:\n    if \"n_steps and n_paths\" in str(e):\n        paths = monte_carlo_gbm(..., n_steps=max(1, n_steps), n_paths=max(1, n_paths))\n    else:\n        raise","preventionTips":["Clamp step/path counts with max(1, x)","Use ceil division for horizon->steps conversion","Validate simulation budget parameters in config"],"tags":["quantlib","risk","monte-carlo","gbm","simulation-size","valueerror"],"backgroundTag":"argument-out-of-range","analyzedSha":"80ffdda44c5c4db0dd84d70e051cca591cea67df","analyzedAt":"2026-08-28T12:46:38.989Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}