bond_pricing
raw JSON → 0.7.3 verified Fri May 01 auth: no python
A library for bond pricing with YTM/zero-curve and NPV, IRR, annuities. Current version 0.7.3 (requires Python >=3.0). Release cadence: irregular.
pip install bond-pricing Common errors
error TypeError: __init__() got an unexpected keyword argument 'face_value' ↓
cause Importing from wrong module or version mismatch. Older version (<=0.6.x) used different parameter names.
fix
Upgrade to latest: pip install --upgrade bond-pricing
error AttributeError: 'Bond' object has no attribute 'ytm' ↓
cause Using an outdated version where method was named differently (e.g., 'yield_to_maturity').
fix
Update library or use bond.yield_to_maturity() for older versions.
error ValueError: Maturity must be positive ↓
cause Passing a negative or zero maturity value.
fix
Ensure maturity > 0.
Warnings
gotcha Face value must be provided as a number (int or float) and cannot be a string. Passing a string will raise a TypeError. ↓
fix Ensure face_value is numeric.
deprecated The method `price_from_ytm()` is deprecated in 0.7.0 in favor of `price()`. ↓
fix Use `bond.price(ytm=0.05)` instead of `bond.price_from_ytm(0.05)`.
breaking In version 0.7.0, the `zero_curve` function signature changed: the argument `spot_rates` renamed to `rates`. ↓
fix Use keyword argument `rates` instead of `spot_rates`.
Imports
- Bond
from bond_pricing import Bond - zero_curve
from bond_pricing import zero_curve - annuity
from bond_pricing import annuity - irr
from bond_pricing import irr
Quickstart
from bond_pricing import Bond
bond = Bond(face_value=1000, coupon_rate=0.05, maturity=10, price=950)
print(bond.ytm())