{"record":{"id":"1373809dbe8e3a0a","repo":"HKUDS/Vibe-Trading","slug":"confidence-must-be-in-0-1-got-confidence-137380","errorCode":null,"errorMessage":"confidence must be in (0, 1), got {confidence}","messagePattern":"confidence must be in \\(0, 1\\), got (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"agent/src/quantlib/risk.py","lineNumber":109,"sourceCode":"        raise ValueError(f\"returns must be 1-D, got shape {values.shape}\")\n    values = values.ravel()\n    finite = values[np.isfinite(values)]\n    if finite.size == 0:\n        raise ValueError(\"returns contains no finite observation\")\n    return finite\n\n\ndef _validate_confidence(confidence: float) -> None:\n    \"\"\"Check that a confidence level is a strict probability.\n\n    Args:\n        confidence: Confidence level, e.g. 0.95.\n\n    Raises:\n        ValueError: If ``confidence`` is not strictly between 0 and 1.\n    \"\"\"\n    if not 0.0 < confidence < 1.0:\n        raise ValueError(f\"confidence must be in (0, 1), got {confidence}\")\n\n\ndef _validate_horizon(horizon: int) -> None:\n    \"\"\"Check that a holding period is a positive whole number of periods.\n\n    Args:\n        horizon: Holding period in periods (days for a daily return series).\n\n    Raises:\n        ValueError: If ``horizon`` is less than 1.\n    \"\"\"\n    if horizon < 1:\n        raise ValueError(f\"horizon must be >= 1, got {horizon}\")\n\n\ndef _tail_index(n: int, confidence: float) -> int:\n    \"\"\"Position of the VaR order statistic in an ascending-sorted sample.\n","sourceCodeStart":91,"sourceCodeEnd":127,"githubUrl":"https://github.com/HKUDS/Vibe-Trading/blob/80ffdda44c5c4db0dd84d70e051cca591cea67df/agent/src/quantlib/risk.py#L91-L127","documentation":"_validate_confidence enforces that the confidence level is a strict probability, 0 < confidence < 1. Confidence is interpreted as a quantile level (e.g. 0.95 for 95% VaR), so 0, 1, negative values, or percentages like 95 would produce meaningless quantiles and are rejected.","triggerScenarios":"historical_var(r, confidence=95) (passing percent instead of fraction), confidence=0.0, confidence=1.0, or a negative value; also any default misconfigured in a config file as 95 instead of 0.95.","commonSituations":"Config files or UI dropdowns that express confidence as an integer percentage; copy-pasted code from libraries that accept 95 (e.g. some VaR toolkits) into this one which expects 0.95.","solutions":["Pass the fraction: use 0.95, not 95","If the value comes from config as a percent, divide by 100 before the call","Add an assertion or unit test on config values in (0,1)"],"exampleFix":"// before\nvar = historical_var(returns, confidence=95)\n// after\nvar = historical_var(returns, confidence=0.95)","handlingStrategy":"validation","validationCode":"def ok_confidence(c):\n    return isinstance(c, (int, float)) and 0.0 < c < 1.0\nassert ok_confidence(confidence)","typeGuard":"def is_strict_probability(c) -> bool:\n    return isinstance(c, (int, float)) and not isinstance(c, bool) and 0.0 < float(c) < 1.0","tryCatchPattern":"try:\n    var = historical_var(r, confidence)\nexcept ValueError as e:\n    if \"confidence must be in\" in str(e):\n        confidence = min(max(confidence / 100 if confidence > 1 else 0.95, 1e-12), 1 - 1e-12)\n    else:\n        raise","preventionTips":["Store confidence as a fraction (0.95) in config, never a percent","Validate config values at load time","Add a unit test asserting 0 < confidence < 1"],"tags":["quantlib","risk","validation","confidence","valueerror"],"backgroundTag":"argument-out-of-range","analyzedSha":"80ffdda44c5c4db0dd84d70e051cca591cea67df","analyzedAt":"2026-08-28T12:46:38.989Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}