HKUDS/Vibe-Trading · error · ValueError

n_steps and n_paths must be >= 1, got {n_steps} and {n_paths

Error message

n_steps and n_paths must be >= 1, got {n_steps} and {n_paths}

What it means

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.

Source

Thrown at agent/src/quantlib/risk.py:563

            is then NOT reproducible.
        steps_per_year: Steps per year, i.e. ``dt = 1 / steps_per_year``.
            Defaults to the 252-day trading year.

    Returns:
        Price matrix of shape ``(n_paths, n_steps + 1)``. Column 0 is exactly
        ``s0`` on every path, so ``paths[:, -1] / paths[:, 0] - 1`` is the total
        return over the whole simulation.

    Raises:
        ValueError: If ``s0`` is not positive, ``sigma`` is negative, or any of
            ``n_steps`` / ``n_paths`` / ``steps_per_year`` is below 1.
    """
    if s0 <= 0.0:
        raise ValueError(f"s0 must be > 0, got {s0}")
    if sigma < 0.0:
        raise ValueError(f"sigma must be >= 0, got {sigma}")
    if n_steps < 1 or n_paths < 1:
        raise ValueError(f"n_steps and n_paths must be >= 1, got {n_steps} and {n_paths}")
    if steps_per_year < 1:
        raise ValueError(f"steps_per_year must be >= 1, got {steps_per_year}")

    dt = 1.0 / steps_per_year
    rng = np.random.default_rng(seed)
    shocks = rng.standard_normal((n_paths, n_steps))
    log_returns = (mu - 0.5 * sigma**2) * dt + sigma * np.sqrt(dt) * shocks
    paths = np.empty((n_paths, n_steps + 1), dtype=float)
    paths[:, 0] = s0
    paths[:, 1:] = s0 * np.exp(np.cumsum(log_returns, axis=1))
    return paths


def analyze_mc_results(paths: np.ndarray, confidence: float = 0.95) -> dict:
    """Summarise the terminal distribution of a simulated price matrix.

    Args:
        paths: Price matrix of shape ``(n_paths, n_steps + 1)`` as returned by

View on GitHub (pinned to 80ffdda44c)

Solutions

  1. Use max(1, computed_steps) / max(1, n_paths)
  2. Fix step-size arithmetic so requested horizons map to >= 1 step
  3. Validate simulation parameters in config before the run

Example fix

// before
paths = monte_carlo_gbm(s0=100, mu=0.05, sigma=0.2, n_steps=days // 252, n_paths=n)
// after
paths = monte_carlo_gbm(s0=100, mu=0.05, sigma=0.2, n_steps=max(1, days // 252), n_paths=max(1, n))
Defensive patterns

Strategy: validation

Validate before calling

n_steps = max(1, int(n_steps))
n_paths = max(1, int(n_paths))

Type guard

def are_valid_sim_dims(n_steps, n_paths) -> bool:
    return int(n_steps) >= 1 and int(n_paths) >= 1

Try / catch

try:
    paths = monte_carlo_gbm(..., n_steps=n_steps, n_paths=n_paths)
except ValueError as e:
    if "n_steps and n_paths" in str(e):
        paths = monte_carlo_gbm(..., n_steps=max(1, n_steps), n_paths=max(1, n_paths))
    else:
        raise

Prevention

When it happens

Trigger: 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).

Common situations: Short horizons with coarse step sizes; config typos; dynamic path counts from a budget variable that evaluates to 0.

Related errors


AI-assisted analysis of HKUDS/Vibe-Trading@80ffdda44c (2026-08-28). Data as JSON: /api/errors/c45b89097a7bd123. Report an issue: GitHub.