IntermediateOptions, Derivatives & FinancePython
Run this module
Bond Duration, Convexity, and DV01¶
Fixed income sensitivity measures that quantify how bond prices respond to changes in interest rates.
Functions¶
| Function | Description |
|---|---|
bond_price(cashflows, times, ytm) |
PV of cash flows at given yield |
macaulay_duration(cashflows, times, ytm) |
Weighted average time to cash flows (years) |
modified_duration(cashflows, times, ytm) |
% price change per 1% yield change |
convexity(cashflows, times, ytm) |
Second-order yield sensitivity |
dv01(cashflows, times, ytm) |
Dollar value of 1 basis point |
price_change_approx(mod_dur, conv, price, dy) |
Taylor expansion price estimate |
build_cashflows(face, coupon_rate, maturity, freq) |
Generate coupon bond cash flows |
Key Concepts¶
- Macaulay Duration: Measures the weighted average maturity of cash flows. Zero-coupon bond has duration = maturity.
- Modified Duration:
D_mod = D_mac / (1 + y). A bond with mod duration 7 loses ~7% in price per +100bp yield move. - Convexity: The curve in the price-yield relationship. Positive convexity benefits investors — price rises more than duration predicts when yields fall.
- DV01: Practical measure for hedging. "My portfolio has DV01 of $5,000" means a +1bp move costs $5,000.
Example¶
from duration_convexity import build_cashflows, bond_price, modified_duration, dv01
cfs, ts = build_cashflows(face=1000, coupon_rate=0.05, maturity=10)
price = bond_price(cfs, ts, ytm=0.04) # ~1081.11
mod_dur = modified_duration(cfs, ts, 0.04) # ~7.99
dv = dv01(cfs, ts, 0.04) # ~0.086 per $1000
Duration Approximation¶
For a +100bp shock: duration term dominates. For large moves, convexity correction matters.
Continue in Options, Derivatives & Finance¶
-
This module covers advanced mathematical techniques for pricing financial derivatives. The focus is on models beyond the standard assumptions. Rather than assuming constant volatility, we explore dynamic and local volatility models. These models are crucial for correctly valuing exotic options and managing the risks of complex derivatives portfolios.
-
This module lets you price basic stock options (calls and puts) using the Black-Scholes formula, a foundation of modern financial analysis.
-
This utility lets you calculate the fair price of a bond or estimate its yield to maturity (YTM), two of the most basic (and important!) ideas in investing.
-
CAPM is the idea that won a Nobel Prize and still anchors how the industry
-
This tool calculates the present value of a series of future cash flows—the basic principle behind valuing businesses, real estate, projects, and stocks!
-
This utility does NOT use any external APIs. All data is managed locally for learning and experimentation.