HKUDS/Vibe-Trading · error · ValueError
confidence must be in (0.0, 1.0), got {confidence}
Error message
confidence must be in (0.0, 1.0), got {confidence} What it means
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.
Source
Thrown at agent/src/quantlib/credit.py:940
Raises:
ValueError: If parameters violate domain constraints.
"""
ead = _require_finite(ead, "ead")
pd = _require_finite(pd, "pd")
lgd = _require_finite(lgd, "lgd")
asset_correlation = _require_finite(asset_correlation, "asset_correlation")
confidence = _require_finite(confidence, "confidence")
if ead <= 0.0:
raise ValueError(f"ead must be strictly positive, got {ead}")
if not (0.0 < pd < 1.0):
raise ValueError(f"pd must be in (0.0, 1.0), got {pd}")
if not (0.0 <= lgd <= 1.0):
raise ValueError(f"lgd must be in [0.0, 1.0], got {lgd}")
if not (0.0 <= asset_correlation < 1.0):
raise ValueError(f"asset_correlation must be in [0.0, 1.0), got {asset_correlation}")
if not (0.0 < confidence < 1.0):
raise ValueError(f"confidence must be in (0.0, 1.0), got {confidence}")
rho = asset_correlation
inv_pd = float(norm.ppf(pd))
inv_conf = float(norm.ppf(confidence))
numerator = inv_pd + np.sqrt(rho) * inv_conf
denominator = np.sqrt(1.0 - rho)
wcdr = float(norm.cdf(numerator / denominator))
el = expected_loss(ead, pd, lgd)
wcl = float(ead * lgd * wcdr)
ul = float(max(0.0, wcl - el))
capital_ratio = float(ul / ead) if ead > 0 else 0.0
return {
"expected_loss": el,
"wcdr": wcdr,
"worst_case_loss": wcl,View on GitHub (pinned to 80ffdda44c)
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
Example fix
# before var = vasicek_credit_var(1e6, 0.02, 0.6, 0.2, confidence=99.9) # after var = vasicek_credit_var(1e6, 0.02, 0.6, 0.2, confidence=0.999)
Defensive patterns
Strategy: validation
Validate before calling
confidence = confidence / 100.0 if confidence > 1.0 else confidence confidence = min(max(confidence, 1e-12), 1.0 - 1e-12) var = vasicek_credit_var(ead, pd, lgd, rho, confidence)
Type guard
def is_valid_confidence(c: float) -> bool:
return isinstance(c, (int, float)) and 0.0 < float(c) < 1.0 Try / catch
try:
var = vasicek_credit_var(ead, pd, lgd, rho, conf)
except ValueError as e:
if 'confidence' in str(e):
var = vasicek_credit_var(ead, pd, lgd, rho, 0.999)
else:
raise Prevention
- 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
When it happens
Trigger: Calling vasicek_credit_var with confidence = 0.0, 1.0, 99.9 (percent), or values like 1.001 from rounding.
Common situations: 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.
Related errors
- ead must be strictly positive, got {ead}
- pd must be in (0.0, 1.0), got {pd}
- asset_correlation must be in [0.0, 1.0), got {asset_correlat
- survival_prob must be in (0.0, 1.0], got {survival_prob}
- tenor_years must be strictly positive, got {tenor_years}
AI-assisted analysis of HKUDS/Vibe-Trading@80ffdda44c (2026-08-28).
Data as JSON: /api/errors/bb7e73a448596f45.
Report an issue: GitHub.