HKUDS/Vibe-Trading · error · ValueError
notional must be strictly positive, got {notional}
Error message
notional must be strictly positive, got {notional} What it means
cds_price scales all premium and protection cash flows by notional, so the notional must be strictly positive. Zero or negative notionals would produce meaningless (zero or sign-flipped) mark-to-market values and usually indicate an input bug.
Source
Thrown at agent/src/quantlib/credit.py:808
Raises:
ValueError: If spread_bps < 0, recovery_rate not in [0, 1), tenor_years <= 0, or notional <= 0.
"""
spread_bps = _require_finite(spread_bps, "spread_bps")
recovery_rate = _require_finite(recovery_rate, "recovery_rate")
tenor_years = _require_finite(tenor_years, "tenor_years")
risk_free_rate = _require_finite(risk_free_rate, "risk_free_rate")
coupon_bps = _require_finite(coupon_bps, "coupon_bps")
notional = _require_finite(notional, "notional")
payment_frequency = _require_finite(payment_frequency, "payment_frequency")
if spread_bps < 0.0:
raise ValueError(f"spread_bps must be non-negative, got {spread_bps}")
if not (0.0 <= recovery_rate < 1.0):
raise ValueError(f"recovery_rate must be in [0.0, 1.0), got {recovery_rate}")
if tenor_years <= 0.0:
raise ValueError(f"tenor_years must be strictly positive, got {tenor_years}")
if notional <= 0.0:
raise ValueError(f"notional must be strictly positive, got {notional}")
if payment_frequency <= 0:
raise ValueError(f"payment_frequency must be positive, got {payment_frequency}")
s_dec = spread_bps / 10_000.0
c_dec = coupon_bps / 10_000.0
lgd = 1.0 - recovery_rate
# Implied hazard rate lambda ≈ s / LGD
lambda_hazard = float(s_dec / lgd) if lgd > 0 else 0.0
n_periods = max(1, int(round(tenor_years * payment_frequency)))
t_grid = np.linspace(tenor_years / n_periods, tenor_years, n_periods)
t_prev = np.r_[0.0, t_grid[:-1]]
dts = t_grid - t_prev
t_mid = 0.5 * (t_prev + t_grid)
# Survival probabilities Q(t) = exp(-lambda * t)
q_grid = np.exp(-lambda_hazard * t_grid)View on GitHub (pinned to 80ffdda44c)
Solutions
- Pass a positive notional in the same units you want the result (e.g. 10_000_000.0)
- Fix upstream trade records that store zero or negative notionals
- If direction matters, price with abs(notional) and flip the sign of the resulting MTM yourself
Example fix
# before pv = cds_price(250, 5.0, notional=-10_000_000) # after pv = cds_price(250, 5.0, notional=10_000_000)
Defensive patterns
Strategy: validation
Validate before calling
if notional <= 0.0:
notional = abs(notional) # normalize booked shorts
pv = cds_price(250.0, tenor_years=5.0, notional=notional) Type guard
def is_valid_notional(n: float) -> bool:
return math.isfinite(n) and n > 0.0 Try / catch
try:
pv = cds_price(250.0, tenor_years=5.0, notional=notional)
except ValueError as e:
logger.error("invalid notional %s: %s", notional, e)
pv = 0.0 Prevention
- Validate trade records at ingestion: notional > 0
- Handle sell-side direction by flipping the MTM sign, not the notional
- Use named arguments (notional=...) to avoid positional mixups with tenor
When it happens
Trigger: Calling cds_price with notional = 0.0 or a negative amount, or forgetting the argument and having it default incorrectly in your wrapper code.
Common situations: Zero-initialized notional from an upstream struct; sign conventions from internal booking systems that represent seller-side as negative; passing notional in thousands/millions inconsistently.
Related errors
- recovery_rate must be in [0.0, 1.0), got {recovery_rate}
- payment_frequency must be positive, got {payment_frequency}
- survival_prob must be in (0.0, 1.0], got {survival_prob}
- tenor_years must be strictly positive, got {tenor_years}
- spread_bps must be non-negative, got {spread_bps}
AI-assisted analysis of HKUDS/Vibe-Trading@80ffdda44c (2026-08-28).
Data as JSON: /api/errors/381c1154d87dab28.
Report an issue: GitHub.