{"record":{"id":"bb7e73a448596f45","repo":"HKUDS/Vibe-Trading","slug":"confidence-must-be-in-0-0-1-0-got-confidence","errorCode":null,"errorMessage":"confidence must be in (0.0, 1.0), got {confidence}","messagePattern":"confidence must be in \\(0\\.0, 1\\.0\\), got (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"agent/src/quantlib/credit.py","lineNumber":940,"sourceCode":"\n    Raises:\n        ValueError: If parameters violate domain constraints.\n    \"\"\"\n    ead = _require_finite(ead, \"ead\")\n    pd = _require_finite(pd, \"pd\")\n    lgd = _require_finite(lgd, \"lgd\")\n    asset_correlation = _require_finite(asset_correlation, \"asset_correlation\")\n    confidence = _require_finite(confidence, \"confidence\")\n    if ead <= 0.0:\n        raise ValueError(f\"ead must be strictly positive, got {ead}\")\n    if not (0.0 < pd < 1.0):\n        raise ValueError(f\"pd must be in (0.0, 1.0), got {pd}\")\n    if not (0.0 <= lgd <= 1.0):\n        raise ValueError(f\"lgd must be in [0.0, 1.0], got {lgd}\")\n    if not (0.0 <= asset_correlation < 1.0):\n        raise ValueError(f\"asset_correlation must be in [0.0, 1.0), got {asset_correlation}\")\n    if not (0.0 < confidence < 1.0):\n        raise ValueError(f\"confidence must be in (0.0, 1.0), got {confidence}\")\n\n    rho = asset_correlation\n    inv_pd = float(norm.ppf(pd))\n    inv_conf = float(norm.ppf(confidence))\n\n    numerator = inv_pd + np.sqrt(rho) * inv_conf\n    denominator = np.sqrt(1.0 - rho)\n    wcdr = float(norm.cdf(numerator / denominator))\n\n    el = expected_loss(ead, pd, lgd)\n    wcl = float(ead * lgd * wcdr)\n    ul = float(max(0.0, wcl - el))\n    capital_ratio = float(ul / ead) if ead > 0 else 0.0\n\n    return {\n        \"expected_loss\": el,\n        \"wcdr\": wcdr,\n        \"worst_case_loss\": wcl,","sourceCodeStart":922,"sourceCodeEnd":958,"githubUrl":"https://github.com/HKUDS/Vibe-Trading/blob/80ffdda44c5c4db0dd84d70e051cca591cea67df/agent/src/quantlib/credit.py#L922-L958","documentation":"vasicek_credit_var evaluates norm.ppf(confidence) to get the quantile of the systematic factor, so confidence must be strictly inside (0.0, 1.0): 0 or 1 map to infinite inverse-normal values and the VaR is undefined.","triggerScenarios":"Calling vasicek_credit_var with confidence = 0.0, 1.0, 99.9 (percent), or values like 1.001 from rounding.","commonSituations":"Passing 99.9 instead of 0.999 (percent vs decimal) is by far the most common slip; floating point rounding that yields exactly 1.0.","solutions":["Use decimal confidence: 0.999 for 99.9%","Clamp: confidence = min(max(c, 1e-12), 1 - 1e-12)","Validate user-facing inputs that specify confidence as a percent and divide by 100"],"exampleFix":"# before\nvar = vasicek_credit_var(1e6, 0.02, 0.6, 0.2, confidence=99.9)\n\n# after\nvar = vasicek_credit_var(1e6, 0.02, 0.6, 0.2, confidence=0.999)","handlingStrategy":"validation","validationCode":"confidence = confidence / 100.0 if confidence > 1.0 else confidence\nconfidence = min(max(confidence, 1e-12), 1.0 - 1e-12)\nvar = vasicek_credit_var(ead, pd, lgd, rho, confidence)","typeGuard":"def is_valid_confidence(c: float) -> bool:\n    return isinstance(c, (int, float)) and 0.0 < float(c) < 1.0","tryCatchPattern":"try:\n    var = vasicek_credit_var(ead, pd, lgd, rho, conf)\nexcept ValueError as e:\n    if 'confidence' in str(e):\n        var = vasicek_credit_var(ead, pd, lgd, rho, 0.999)\n    else:\n        raise","preventionTips":["Accept percent in user configs but always divide by 100 before the call","Use 0.999 (not 99.9) in code and tests","Clamp after rounding to avoid exactly 1.0 from float error"],"tags":["credit-var","vasicek","confidence-level","input-validation","python"],"backgroundTag":"argument-out-of-range","analyzedSha":"80ffdda44c5c4db0dd84d70e051cca591cea67df","analyzedAt":"2026-08-28T12:46:38.989Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}