Bond duration
Macaulay and modified duration from a yield, effective and key-rate duration off a spot curve, and DV01 of a fixed-coupon bond.
- Model id
fixed_income.duration, version 2- Domain
- Fixed income
- Evidence
- standard
- Cost class
- light: A short numerical method; a hosted run may take up to 10 seconds.
Formula
Where
- Macaulay duration, in years
macaulay_duration - Full price of the bond
full_price - Time to cash flow j, in coupon periods from settlement
- Coupons per year
frequency - The j-th remaining cash flow: a coupon, or the last coupon and the redemption
- Yield to maturity per year, compounded at the coupon frequency
yield_to_maturity - Modified duration: the relative fall in price for a rise of one in yield
modified_duration - Effective duration, off a spot curve
effective_duration - The price off the spot curve z
- The spot curve
curve_rates - The shift of the curve, up and down
bump - Key-rate duration at key tenor k
key_rate_durations - The shape of the shift for key tenor k: 1 at that tenor, falling to 0 at its neighbours
- Change in the price of the holding for a fall of one basis point in yield
dv01
Each symbol's field is named beside it; the inputs and outputs, with their units and bounds, are under Variables, and the citations give each formula's source.
Variables
Rates, returns and yields are decimals: 0.05 is five percent. Bounds in brackets include their end; in parentheses they exclude it.
Inputs
Macaulay and modified duration (macaulay_modified): 12 inputs
| Name | Unit | Bounds | Description |
|---|---|---|---|
Settlementsettlementdate | date | Settlement date: the price is for this date | |
Maturitymaturitydate | date | Maturity date: the last coupon and redemption (for a bond with n years left, n years after settlement) | |
Coupon ratecoupon_raterate · [0, 1] | rate | [0, 1] | Annual coupon rate, paid in equal parts |
Frequencyfrequencytext | text | Coupons per year (also the yield's compounding) | |
Day countday_counttext | text | Day count for accrued interest and stubs | |
Face valueface_valuemoney · [0.01, 1e+09] | money | [0.01, 1e+09] | Face (par) value held: at 100, a price is per 100 of face value |
Redemptionredemptionmoney · [1, 200] | money | [1, 200] | Amount repaid at maturity per 100 of face value |
Issue dateissue_datedate | date | Date interest starts to accrue, when the first coupon period is irregular; omitted (null) for a regular schedule | |
First periodfirst_periodtext | text | Whether an irregular first period ends at the first coupon date after the issue date (short) or at the one after that (long) | |
End of monthend_of_monthflag | flag | Keep coupon dates at month ends when the maturity is one | |
Calculationcalculationtext | text | Macaulay and modified duration | |
Yield to maturityyield_to_maturityrate · [-0.1, 1] | rate | [-0.1, 1] | Yield to maturity per year, compounded at the coupon frequency |
Effective duration off a spot curve (effective): 14 inputs
| Name | Unit | Bounds | Description |
|---|---|---|---|
Settlementsettlementdate | date | Settlement date: the price is for this date | |
Maturitymaturitydate | date | Maturity date: the last coupon and redemption (for a bond with n years left, n years after settlement) | |
Coupon ratecoupon_raterate · [0, 1] | rate | [0, 1] | Annual coupon rate, paid in equal parts |
Frequencyfrequencytext | text | Coupons per year (also the yield's compounding) | |
Day countday_counttext | text | Day count for accrued interest and stubs | |
Face valueface_valuemoney · [0.01, 1e+09] | money | [0.01, 1e+09] | Face (par) value held: at 100, a price is per 100 of face value |
Redemptionredemptionmoney · [1, 200] | money | [1, 200] | Amount repaid at maturity per 100 of face value |
Issue dateissue_datedate | date | Date interest starts to accrue, when the first coupon period is irregular; omitted (null) for a regular schedule | |
First periodfirst_periodtext | text | Whether an irregular first period ends at the first coupon date after the issue date (short) or at the one after that (long) | |
End of monthend_of_monthflag | flag | Keep coupon dates at month ends when the maturity is one | |
Curve tenorscurve_tenorsyears (array) · length min 1, max 100; each (0, 100] | years (array) | length min 1, max 100; each (0, 100] | Tenors of the spot curve's nodes, in years, increasing |
Curve ratescurve_ratesrate (array) · length min 1, max 100; each [-0.1, 1] | rate (array) | length min 1, max 100; each [-0.1, 1] | Spot rate at each tenor, compounded at the coupon frequency; linear between nodes and flat beyond them |
Bumpbumprate · [1e-06, 0.01] | rate | [1e-06, 0.01] | Shift of the curve up and down for the central difference |
Calculationcalculationtext | text | Effective duration off a spot curve |
Key-rate durations off a spot curve (key_rate): 15 inputs
| Name | Unit | Bounds | Description |
|---|---|---|---|
Settlementsettlementdate | date | Settlement date: the price is for this date | |
Maturitymaturitydate | date | Maturity date: the last coupon and redemption (for a bond with n years left, n years after settlement) | |
Coupon ratecoupon_raterate · [0, 1] | rate | [0, 1] | Annual coupon rate, paid in equal parts |
Frequencyfrequencytext | text | Coupons per year (also the yield's compounding) | |
Day countday_counttext | text | Day count for accrued interest and stubs | |
Face valueface_valuemoney · [0.01, 1e+09] | money | [0.01, 1e+09] | Face (par) value held: at 100, a price is per 100 of face value |
Redemptionredemptionmoney · [1, 200] | money | [1, 200] | Amount repaid at maturity per 100 of face value |
Issue dateissue_datedate | date | Date interest starts to accrue, when the first coupon period is irregular; omitted (null) for a regular schedule | |
First periodfirst_periodtext | text | Whether an irregular first period ends at the first coupon date after the issue date (short) or at the one after that (long) | |
End of monthend_of_monthflag | flag | Keep coupon dates at month ends when the maturity is one | |
Curve tenorscurve_tenorsyears (array) · length min 1, max 100; each (0, 100] | years (array) | length min 1, max 100; each (0, 100] | Tenors of the spot curve's nodes, in years, increasing |
Curve ratescurve_ratesrate (array) · length min 1, max 100; each [-0.1, 1] | rate (array) | length min 1, max 100; each [-0.1, 1] | Spot rate at each tenor, compounded at the coupon frequency; linear between nodes and flat beyond them |
Bumpbumprate · [1e-06, 0.01] | rate | [1e-06, 0.01] | Shift of the curve up and down for the central difference |
Calculationcalculationtext | text | Key-rate durations off a spot curve | |
Key tenorskey_tenorsyears (array) · length min 1, max 30; each (0, 100] | years (array) | length min 1, max 30; each (0, 100] | Key tenors in years, increasing |
Price value of a basis point (dv01): 12 inputs
| Name | Unit | Bounds | Description |
|---|---|---|---|
Settlementsettlementdate | date | Settlement date: the price is for this date | |
Maturitymaturitydate | date | Maturity date: the last coupon and redemption (for a bond with n years left, n years after settlement) | |
Coupon ratecoupon_raterate · [0, 1] | rate | [0, 1] | Annual coupon rate, paid in equal parts |
Frequencyfrequencytext | text | Coupons per year (also the yield's compounding) | |
Day countday_counttext | text | Day count for accrued interest and stubs | |
Face valueface_valuemoney · [0.01, 1e+09] | money | [0.01, 1e+09] | Face (par) value held: at 100, a price is per 100 of face value |
Redemptionredemptionmoney · [1, 200] | money | [1, 200] | Amount repaid at maturity per 100 of face value |
Issue dateissue_datedate | date | Date interest starts to accrue, when the first coupon period is irregular; omitted (null) for a regular schedule | |
First periodfirst_periodtext | text | Whether an irregular first period ends at the first coupon date after the issue date (short) or at the one after that (long) | |
End of monthend_of_monthflag | flag | Keep coupon dates at month ends when the maturity is one | |
Calculationcalculationtext | text | Price value of a basis point | |
Yield to maturityyield_to_maturityrate · [-0.1, 1] | rate | [-0.1, 1] | Yield to maturity per year, compounded at the coupon frequency |
Outputs
Macaulay and modified duration (macaulay_modified): 4 outputs
| Name | Unit | Bounds | Description |
|---|---|---|---|
Calculationcalculationtext | text | Macaulay and modified duration | |
Macaulay durationmacaulay_durationyears · [0, 200] | years | [0, 200] | Present-value-weighted mean time to the payments |
Modified durationmodified_durationyears · [0, 200] | years | [0, 200] | Macaulay duration over 1 + y/f: the relative price change per unit of yield |
Full pricefull_pricemoney · [0, 1e+15] | money | [0, 1e+15] | Full (dirty) price at settlement, of the face value held (per 100 by default) |
Effective duration off a spot curve (effective): 5 outputs
| Name | Unit | Bounds | Description |
|---|---|---|---|
Calculationcalculationtext | text | Effective duration off a spot curve | |
Effective durationeffective_durationyears · [0, 200] | years | [0, 200] | (P_down - P_up) / (2 P bump): relative price change per unit shift |
Full pricefull_pricemoney · [0, 1e+15] | money | [0, 1e+15] | Full (dirty) price at settlement, of the face value held (per 100 by default) |
Price downprice_downmoney · [0, 1e+15] | money | [0, 1e+15] | Full price with the curve shifted down |
Price upprice_upmoney · [0, 1e+15] | money | [0, 1e+15] | Full price with the curve shifted up |
Key-rate durations off a spot curve (key_rate): 4 outputs
| Name | Unit | Bounds | Description |
|---|---|---|---|
Calculationcalculationtext | text | Key-rate durations off a spot curve | |
Key rate durationskey_rate_durationsyears (array) · length max 30; each [0, 200] | years (array) | length max 30; each [0, 200] | Duration to each key tenor's shift |
Effective durationeffective_durationyears · [0, 200] | years | [0, 200] | Duration to a parallel shift |
Full pricefull_pricemoney · [0, 1e+15] | money | [0, 1e+15] | Full (dirty) price at settlement, of the face value held (per 100 by default) |
Price value of a basis point (dv01): 4 outputs
| Name | Unit | Bounds | Description |
|---|---|---|---|
Calculationcalculationtext | text | Price value of a basis point | |
DV01dv01money · [0, 1e+15] | money | [0, 1e+15] | Modified duration x full price x 0.0001: the price change per basis point |
Modified durationmodified_durationyears · [0, 200] | years | [0, 200] | Modified duration |
Full pricefull_pricemoney · [0, 1e+15] | money | [0, 1e+15] | Full (dirty) price at settlement, of the face value held (per 100 by default) |
Calculator
Run the model on your own inputs, starting from its example. Rates are decimals: 0.05 is five percent. The run goes to the pyeconomics API on this site: your values travel only in the request, and nothing is stored.
Loading the calculator…
Worked example
A five-year bond with a 4% annual coupon at a 5% yield, settled on a coupon date: a Macaulay duration of 4.6203 years and a modified duration of 4.4003.
Example five_year_annual. Inputs:
{
"calculation": "macaulay_modified",
"coupon_rate": 0.04,
"day_count": "act_act_icma",
"end_of_month": true,
"face_value": 100,
"first_period": "short",
"frequency": "annual",
"issue_date": null,
"maturity": "2031-01-15",
"redemption": 100,
"settlement": "2026-01-15",
"yield_to_maturity": 0.05
}Outputs:
{
"calculation": "macaulay_modified",
"full_price": 95.67052332936917,
"macaulay_duration": 4.620322347961273,
"modified_duration": 4.400306998058355
}Assumptions
- Times t_j are counted in coupon periods from settlement, as in fixed_income.bond_pricing; the yield compounds at the coupon frequency, under street convention.
- The spot curve is linear in its rates between nodes and flat beyond them; its rates compound at the coupon frequency.
- A key tenor's shift is 1 at the tenor, falls linearly to 0 at its neighbours, and stays at 1 beyond the first and last keys.
- The bond has no embedded option, so its cash flows do not move with rates.
Limitations
- A price above 1e15, which only a face value near 1e9 off a curve near -10% for a century, shifted down, reaches, raises DomainError.
- Effective and key-rate durations are central differences: their error is second order in the bump.
- Options, prepayments and credit are out of scope.
Evidence
Status: standard. Textbook consensus, such as bond duration or the CAPM formula.
Every model declares one status: standard (textbook consensus), practitioner (a widely used convention), contested (under active debate), rejected (failed out of sample) or historical (a superseded methodology).
Syllabus
The 2027 CFA® Program's topic areas this model relates to, as factual tags. Each links to CFA Institute's page for its level; pyeconomics holds none of the curriculum's text.
Citations
- Macaulay, F. R. (1938). Some Theoretical Problems Suggested by the Movements of Interest Rates, Bond Yields and Stock Prices in the United States since 1856. National Bureau of Economic Research. https://www.nber.org/books-and-chapters/some-theoretical-problems-suggested-movements-interest-rates-bond-yields-and-stock-prices-united/concept-long-term-interest-rates (Chapter II, The Concept of Long Term Interest Rates, pp. 24-53 (duration as the weighted mean time to a bond's payments))
- Hull, J. C. (2018). Options, Futures, and Other Derivatives, 10th ed. Pearson. https://openlibrary.org/isbn/9780134472089 (Chapter 4, Table 4.6 (calculation of duration) and modified duration). ISBN 9780134472089
- Ho, T. S. Y. (1992). Key Rate Durations: Measures of Interest Rate Risks. The Journal of Fixed Income 2(2), 29-44. doi:10.3905/jfi.1992.408049 (Key rate shifts (triangular shifts that sum to a parallel shift))
Changelog
- Version 1: First version.
- Version 2: Correct US 30/360 long-stub accrual and discount times (#89).
Use it elsewhere
- Documentation
- The model's reference page
- REST API
GET or POST /v1/models/fixed_income.duration/run- MCP tool
fixed_income_duration, orrun_modelwith the model's id; both give the same result. Connect an assistant- Command line
pyeconomics models run fixed_income.duration --help
The worked example, from Python and from the command line:
import pyeconomics
inputs = {
"calculation": "macaulay_modified",
"coupon_rate": 0.04,
"day_count": "act_act_icma",
"end_of_month": True,
"face_value": 100,
"first_period": "short",
"frequency": "annual",
"issue_date": None,
"maturity": "2031-01-15",
"redemption": 100,
"settlement": "2026-01-15",
"yield_to_maturity": 0.05,
}
result = pyeconomics.run("fixed_income.duration", inputs)
print(result.to_json())
pyeconomics models run fixed_income.duration --inputs - <<'JSON'
{
"calculation": "macaulay_modified",
"coupon_rate": 0.04,
"day_count": "act_act_icma",
"end_of_month": true,
"face_value": 100,
"first_period": "short",
"frequency": "annual",
"issue_date": null,
"maturity": "2031-01-15",
"redemption": 100,
"settlement": "2026-01-15",
"yield_to_maturity": 0.05
}
JSON