HKUDS/Vibe-Trading · error · ValueError
price, face, par_amount must be positive and spread_duration
Error message
price, face, par_amount must be positive and spread_duration non-negative
What it means
credit_spread_dv01 computes spread DV01 as spread_duration * (price/face) * 1e-4 * par_amount. price, face, and par_amount enter as denominators/scalars and must be positive, while spread_duration only scales the sensitivity and may be zero. A single combined message covers all four checks.
Source
Thrown at agent/src/quantlib/credit.py:992
Args:
spread_duration: Modified/spread duration in years.
price: Current clean market price of the credit instrument.
face: Quoted par base (standard 100.0).
par_amount: Total par notional held in position.
Returns:
Dollar loss for a 1 bp increase in credit spread (positive float).
Raises:
ValueError: If price, face, or par_amount is not positive, or if
spread_duration is negative.
"""
spread_duration = _require_finite(spread_duration, "spread_duration")
price = _require_finite(price, "price")
face = _require_finite(face, "face")
par_amount = _require_finite(par_amount, "par_amount")
if face <= 0.0 or price <= 0.0 or par_amount <= 0.0 or spread_duration < 0.0:
raise ValueError("price, face, par_amount must be positive and spread_duration non-negative")
return float(spread_duration * (price / face) * 1e-4 * par_amount)
View on GitHub (pinned to 80ffdda44c)
Solutions
- Inspect all four arguments; the message does not say which one failed
- Use positive prices/faces/par amounts; use abs() on booked shorts and flip result signs yourself
- Default spread_duration to 0.0 (allowed) rather than -1 or None placeholders
Example fix
# before dv01 = credit_spread_dv01(spread_duration=4.5, price=0.0, face=100.0, par_amount=1_000_000) # after dv01 = credit_spread_dv01(spread_duration=4.5, price=98.5, face=100.0, par_amount=1_000_000)
Defensive patterns
Strategy: validation
Validate before calling
if min(price, face, par_amount) <= 0.0 or spread_duration < 0.0:
raise ValueError(f"bad dv01 inputs: price={price}, face={face}, par={par_amount}, dur={spread_duration}")
dv01 = credit_spread_dv01(spread_duration, price, face, par_amount) Type guard
def is_valid_dv01_inputs(price: float, face: float, par: float, dur: float) -> bool:
return all(math.isfinite(v) and v > 0 for v in (price, face, par)) and math.isfinite(dur) and dur >= 0 Try / catch
try:
dv01 = credit_spread_dv01(dur, price, face, par)
except ValueError:
logger.warning("skipping instrument with invalid dv01 inputs: price=%s face=%s par=%s", price, face, par)
dv01 = 0.0 Prevention
- Check all four args since the error message is combined
- Filter out non-positive priced (defaulted) instruments before risk aggregation
- Use 0.0 (not -1 or None) as the spread_duration default placeholder
When it happens
Trigger: Calling credit_spread_dv01 with price <= 0, face <= 0, par_amount <= 0, or a negative spread_duration; e.g. price=0 for a defaulted bond or face passed as a negative booked amount.
Common situations: Distressed/defaulted bond prices of 0; negative face amounts from short positions in booking systems; zero-initialized struct fields; sign errors in duration calculations.
Related errors
- survival_prob must be in (0.0, 1.0], got {survival_prob}
- tenor_years must be strictly positive, got {tenor_years}
- recovery_rate must be in [0.0, 1.0), got {recovery_rate}
- notional must be strictly positive, got {notional}
- payment_frequency must be positive, got {payment_frequency}
AI-assisted analysis of HKUDS/Vibe-Trading@80ffdda44c (2026-08-28).
Data as JSON: /api/errors/d597977d9475fbe4.
Report an issue: GitHub.