{"record":{"id":"15db7e9e775eccc7","repo":"HKUDS/Vibe-Trading","slug":"ead-must-be-strictly-positive-got-ead","errorCode":null,"errorMessage":"ead must be strictly positive, got {ead}","messagePattern":"ead must be strictly positive, got (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"agent/src/quantlib/credit.py","lineNumber":932,"sourceCode":"\n    Returns:\n        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)","sourceCodeStart":914,"sourceCodeEnd":950,"githubUrl":"https://github.com/HKUDS/Vibe-Trading/blob/80ffdda44c5c4db0dd84d70e051cca591cea67df/agent/src/quantlib/credit.py#L914-L950","documentation":"vasicek_credit_var computes portfolio credit VaR under the Vasicek single-factor model and requires ead (exposure at default) to be strictly positive, since VaR is scaled directly by exposure and a non-positive exposure makes the quantile meaningless.","triggerScenarios":"Calling vasicek_credit_var with ead = 0.0 or negative ead; note expected_loss allows ead = 0 but this stricter function does not.","commonSituations":"Zero exposures from filtered portfolios; reusing validation logic from expected_loss (which permits 0) and assuming the same here; negative net exposures from netting engines.","solutions":["Filter out zero-exposure entities before calling","Use a positive aggregate exposure for the portfolio","Route negative net exposures through a separate netting-aware model"],"exampleFix":"# before\nvar = vasicek_credit_var(ead=0.0, pd=0.02, lgd=0.6, asset_correlation=0.2, confidence=0.999)\n\n# after\nvar = vasicek_credit_var(ead=1_000_000.0, pd=0.02, lgd=0.6, asset_correlation=0.2, confidence=0.999)","handlingStrategy":"validation","validationCode":"if ead <= 0.0:\n    raise ValueError(f\"vasicek VaR needs positive exposure, got {ead}\")\nvar = vasicek_credit_var(ead, pd, lgd, asset_correlation, confidence)","typeGuard":"def is_positive_exposure(e: float) -> bool:\n    return math.isfinite(e) and e > 0.0","tryCatchPattern":"try:\n    var = vasicek_credit_var(ead, pd, lgd, rho, conf)\nexcept ValueError as e:\n    logger.warning(\"skipping entity in VaR batch: %s\", e)\n    var = 0.0","preventionTips":["Filter zero-exposure entities before the VaR loop","Remember this function is stricter than expected_loss (0 not allowed)","Aggregate portfolio exposure once and validate it is positive"],"tags":["credit-var","vasicek","exposure","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"}