{"record":{"id":"7a2b4e0e53fadda6","repo":"HKUDS/Vibe-Trading","slug":"pd-must-be-in-0-0-1-0-got-pd-7a2b4e","errorCode":null,"errorMessage":"pd must be in (0.0, 1.0), got {pd}","messagePattern":"pd must be in \\(0\\.0, 1\\.0\\), got (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"agent/src/quantlib/credit.py","lineNumber":934,"sourceCode":"        dict with keys:\n            * ``expected_loss`` (float): Base expected loss (EL).\n            * ``wcdr`` (float): Worst-case conditional default rate at confidence.\n            * ``worst_case_loss`` (float): Total portfolio loss at confidence (WCL).\n            * ``unexpected_loss`` (float): Economic capital / Credit VaR (WCL - EL).\n            * ``capital_ratio`` (float): Capital required as decimal fraction of EAD.\n\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))","sourceCodeStart":916,"sourceCodeEnd":952,"githubUrl":"https://github.com/HKUDS/Vibe-Trading/blob/80ffdda44c5c4db0dd84d70e051cca591cea67df/agent/src/quantlib/credit.py#L916-L952","documentation":"vasicek_credit_var evaluates the inverse normal CDF at pd (norm.ppf(pd)), so pd must be strictly inside (0.0, 1.0): at 0 or 1 the inverse is infinite and the Vasicek quantile formula is undefined.","triggerScenarios":"Calling vasicek_credit_var with pd = 0.0, pd = 1.0, pd = 2.5, or percent/bps values like 2 (for 2%).","commonSituations":"Default-free entities (pd = 0) in a portfolio batch; unit errors (2 instead of 0.02); already-defaulted names (pd = 1) passed through from a ratings table.","solutions":["Convert units to decimals (percent/100, bps/10000)","Floor/ceiling borderline values, e.g. pd = min(max(pd, 1e-6), 1 - 1e-6)","Exclude pd == 0 (no default risk) or pd == 1 (already defaulted) names from the VaR batch"],"exampleFix":"# before\nvar = vasicek_credit_var(1e6, pd=0.0, lgd=0.6, asset_correlation=0.2, confidence=0.999)\n\n# after\nvar = vasicek_credit_var(1e6, pd=1e-6, lgd=0.6, asset_correlation=0.2, confidence=0.999)","handlingStrategy":"validation","validationCode":"pd = min(max(pd, 1e-6), 1.0 - 1e-6)\nif not 0.0 < pd < 1.0:\n    raise ValueError(f\"pd must be interior: {pd}\")\nvar = vasicek_credit_var(ead, pd, lgd, rho, conf)","typeGuard":"def is_interior_probability(p: float) -> bool:\n    return isinstance(p, (int, float)) and 0.0 < float(p) < 1.0","tryCatchPattern":"try:\n    var = vasicek_credit_var(ead, pd, lgd, rho, conf)\nexcept ValueError as e:\n    if 'pd' in str(e):\n        var = 0.0 if pd <= 0 else ead  # degenerate cases\n    else:\n        raise","preventionTips":["Exclude default-free (pd=0) and defaulted (pd=1) names from Vasicek batches","Clip PDs to (epsilon, 1-epsilon) after model estimation","Watch for percent-vs-decimal: 2 means 200% here"],"tags":["credit-var","vasicek","probability-of-default","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"}