{"record":{"id":"507778577103e735","repo":"HKUDS/Vibe-Trading","slug":"paths-column-0-the-starting-price-must-be-strict","errorCode":null,"errorMessage":"paths column 0 (the starting price) must be strictly positive","messagePattern":"paths column 0 \\(the starting price\\) must be strictly positive","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"agent/src/quantlib/risk.py","lineNumber":606,"sourceCode":"                returns over the simulation, so a bad outcome is negative.\n            var, cvar (float): Positive loss magnitudes, computed with the same\n                order-statistic convention as ``historical_var`` /\n                ``historical_cvar``, so ``cvar >= var``.\n            prob_loss (float): Fraction of paths ending below their start.\n            worst_5pct_return, best_5pct_return (float): Signed 5th and 95th\n                percentiles of the terminal return (linear interpolation).\n\n    Raises:\n        ValueError: If ``paths`` is not 2-D with at least two columns, holds a\n            non-positive starting price, or ``confidence`` is outside (0, 1).\n    \"\"\"\n    _validate_confidence(confidence)\n    matrix = np.asarray(paths, dtype=float)\n    if matrix.ndim != 2 or matrix.shape[1] < 2:\n        raise ValueError(f\"paths must be 2-D with >= 2 columns, got shape {matrix.shape}\")\n    start = matrix[:, 0]\n    if (start <= 0.0).any():\n        raise ValueError(\"paths column 0 (the starting price) must be strictly positive\")\n\n    returns = matrix[:, -1] / start - 1.0\n    return {\n        \"mean_return\": float(np.mean(returns)),\n        \"median_return\": float(np.median(returns)),\n        \"std_return\": float(np.std(returns, ddof=1)) if returns.size > 1 else 0.0,\n        \"var\": historical_var(returns, confidence),\n        \"cvar\": historical_cvar(returns, confidence),\n        \"prob_loss\": float(np.mean(returns < 0.0)),\n        \"worst_5pct_return\": float(np.percentile(returns, 5.0)),\n        \"best_5pct_return\": float(np.percentile(returns, 95.0)),\n    }\n\n\ndef fit_gpd_tail(\n    returns: pd.Series | np.ndarray | Sequence[float],\n    threshold_pct: float = 5.0,\n) -> dict:","sourceCodeStart":588,"sourceCodeEnd":624,"githubUrl":"https://github.com/HKUDS/Vibe-Trading/blob/80ffdda44c5c4db0dd84d70e051cca591cea67df/agent/src/quantlib/risk.py#L588-L624","documentation":"analyze_mc_results uses column 0 as the starting price to compute returns (terminal/start - 1), so every entry in that column must be strictly positive. A zero or negative starting price makes the return ratio undefined and would corrupt every statistic derived from it.","triggerScenarios":"Passing a matrix whose first column contains 0 or negative values — e.g. a PnL matrix instead of price paths, paths built with s0=0, or a matrix where the s0 column was dropped/shifted (returns stacked in col 0).","commonSituations":"Concatenating simulation output incorrectly (np.hstack of returns without the s0 column); passing log-prices or PnL; sign errors in path construction.","solutions":["Ensure column 0 holds the positive starting prices (monte_carlo_gbm already does this)","If you dropped s0, prepend it: np.hstack([np.full((n,1), s0), returns_matrix])","Convert log-price matrices with np.exp before analysis"],"exampleFix":"// before\nstats = analyze_mc_results(returns_matrix)  # col 0 is returns, can be <= 0\n// after\nstats = analyze_mc_results(np.hstack([np.full((returns_matrix.shape[0], 1), s0), returns_matrix]))","handlingStrategy":"validation","validationCode":"import numpy as np\nm = np.asarray(paths, dtype=float)\nassert (m[:, 0] > 0).all(), \"column 0 must hold positive starting prices\"","typeGuard":"import numpy as np\n\ndef has_positive_start_col(x) -> bool:\n    m = np.asarray(x, dtype=float)\n    return m.ndim == 2 and m.shape[1] >= 2 and bool((m[:, 0] > 0).all())","tryCatchPattern":"try:\n    stats = analyze_mc_results(paths)\nexcept ValueError as e:\n    if \"starting price\" in str(e):\n        stats = analyze_mc_results(np.hstack([np.full((paths.shape[0], 1), s0), paths]))\n    else:\n        raise","preventionTips":["Keep the s0 column when post-processing path matrices","np.exp() log-price matrices before analysis","Verify with monte_carlo_gbm's own output shape as reference"],"tags":["quantlib","risk","monte-carlo","positive-values","valueerror"],"backgroundTag":"invalid-domain-value","analyzedSha":"80ffdda44c5c4db0dd84d70e051cca591cea67df","analyzedAt":"2026-08-28T12:46:38.989Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}