Skip to content

Fixed income

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

DMac=1P∑jtjf CFj(1+y/f)tjD_{\mathrm{Mac}} = \frac{1}{P}\sum_j \frac{t_j}{f}\,\frac{CF_j}{(1 + y/f)^{t_j}}Dmod=DMac1+y/fD_{\mathrm{mod}} = \frac{D_{\mathrm{Mac}}}{1 + y/f}Deff=P(z−h)−P(z+h)2P(z)hD_{\mathrm{eff}} = \frac{P(z - h) - P(z + h)}{2 P(z) h}KRDk=P(z−hsk)−P(z+hsk)2P(z)h,∑ksk=1KRD_k = \frac{P(z - h s_k) - P(z + h s_k)}{2 P(z) h}, \quad \sum_k s_k = 1DV01=Dmod P×0.0001DV01 = D_{\mathrm{mod}}\,P \times 0.0001

Where

DMacD_{\mathrm{Mac}}
Macaulay duration, in years macaulay_duration
PP
Full price of the bond full_price
tjt_j
Time to cash flow j, in coupon periods from settlement
ff
Coupons per year frequency
CFjCF_j
The j-th remaining cash flow: a coupon, or the last coupon and the redemption
yy
Yield to maturity per year, compounded at the coupon frequency yield_to_maturity
DmodD_{\mathrm{mod}}
Modified duration: the relative fall in price for a rise of one in yield modified_duration
DeffD_{\mathrm{eff}}
Effective duration, off a spot curve effective_duration
P(z)P(z)
The price off the spot curve z
zz
The spot curve curve_rates
hh
The shift of the curve, up and down bump
KRDkKRD_k
Key-rate duration at key tenor k key_rate_durations
sks_k
The shape of the shift for key tenor k: 1 at that tenor, falling to 0 at its neighbours
DV01DV01
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
Inputs of the calculation macaulay_modified
NameDescription
SettlementsettlementdateSettlement date: the price is for this date
MaturitymaturitydateMaturity date: the last coupon and redemption (for a bond with n years left, n years after settlement)
Coupon ratecoupon_raterate · [0, 1]Annual coupon rate, paid in equal parts
FrequencyfrequencytextCoupons per year (also the yield's compounding)
Day countday_counttextDay count for accrued interest and stubs
Face valueface_valuemoney · [0.01, 1e+09]Face (par) value held: at 100, a price is per 100 of face value
Redemptionredemptionmoney · [1, 200]Amount repaid at maturity per 100 of face value
Issue dateissue_datedateDate interest starts to accrue, when the first coupon period is irregular; omitted (null) for a regular schedule
First periodfirst_periodtextWhether 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_monthflagKeep coupon dates at month ends when the maturity is one
CalculationcalculationtextMacaulay and modified duration
Yield to maturityyield_to_maturityrate · [-0.1, 1]Yield to maturity per year, compounded at the coupon frequency
Effective duration off a spot curve (effective): 14 inputs
Inputs of the calculation effective
NameDescription
SettlementsettlementdateSettlement date: the price is for this date
MaturitymaturitydateMaturity date: the last coupon and redemption (for a bond with n years left, n years after settlement)
Coupon ratecoupon_raterate · [0, 1]Annual coupon rate, paid in equal parts
FrequencyfrequencytextCoupons per year (also the yield's compounding)
Day countday_counttextDay count for accrued interest and stubs
Face valueface_valuemoney · [0.01, 1e+09]Face (par) value held: at 100, a price is per 100 of face value
Redemptionredemptionmoney · [1, 200]Amount repaid at maturity per 100 of face value
Issue dateissue_datedateDate interest starts to accrue, when the first coupon period is irregular; omitted (null) for a regular schedule
First periodfirst_periodtextWhether 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_monthflagKeep coupon dates at month ends when the maturity is one
Curve tenorscurve_tenorsyears (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]Spot rate at each tenor, compounded at the coupon frequency; linear between nodes and flat beyond them
Bumpbumprate · [1e-06, 0.01]Shift of the curve up and down for the central difference
CalculationcalculationtextEffective duration off a spot curve
Key-rate durations off a spot curve (key_rate): 15 inputs
Inputs of the calculation key_rate
NameDescription
SettlementsettlementdateSettlement date: the price is for this date
MaturitymaturitydateMaturity date: the last coupon and redemption (for a bond with n years left, n years after settlement)
Coupon ratecoupon_raterate · [0, 1]Annual coupon rate, paid in equal parts
FrequencyfrequencytextCoupons per year (also the yield's compounding)
Day countday_counttextDay count for accrued interest and stubs
Face valueface_valuemoney · [0.01, 1e+09]Face (par) value held: at 100, a price is per 100 of face value
Redemptionredemptionmoney · [1, 200]Amount repaid at maturity per 100 of face value
Issue dateissue_datedateDate interest starts to accrue, when the first coupon period is irregular; omitted (null) for a regular schedule
First periodfirst_periodtextWhether 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_monthflagKeep coupon dates at month ends when the maturity is one
Curve tenorscurve_tenorsyears (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]Spot rate at each tenor, compounded at the coupon frequency; linear between nodes and flat beyond them
Bumpbumprate · [1e-06, 0.01]Shift of the curve up and down for the central difference
CalculationcalculationtextKey-rate durations off a spot curve
Key tenorskey_tenorsyears (array) · length min 1, max 30; each (0, 100]Key tenors in years, increasing
Price value of a basis point (dv01): 12 inputs
Inputs of the calculation dv01
NameDescription
SettlementsettlementdateSettlement date: the price is for this date
MaturitymaturitydateMaturity date: the last coupon and redemption (for a bond with n years left, n years after settlement)
Coupon ratecoupon_raterate · [0, 1]Annual coupon rate, paid in equal parts
FrequencyfrequencytextCoupons per year (also the yield's compounding)
Day countday_counttextDay count for accrued interest and stubs
Face valueface_valuemoney · [0.01, 1e+09]Face (par) value held: at 100, a price is per 100 of face value
Redemptionredemptionmoney · [1, 200]Amount repaid at maturity per 100 of face value
Issue dateissue_datedateDate interest starts to accrue, when the first coupon period is irregular; omitted (null) for a regular schedule
First periodfirst_periodtextWhether 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_monthflagKeep coupon dates at month ends when the maturity is one
CalculationcalculationtextPrice value of a basis point
Yield to maturityyield_to_maturityrate · [-0.1, 1]Yield to maturity per year, compounded at the coupon frequency

Outputs

Macaulay and modified duration (macaulay_modified): 4 outputs
Outputs of the calculation macaulay_modified
NameDescription
CalculationcalculationtextMacaulay and modified duration
Macaulay durationmacaulay_durationyears · [0, 200]Present-value-weighted mean time to the payments
Modified durationmodified_durationyears · [0, 200]Macaulay duration over 1 + y/f: the relative price change per unit of yield
Full pricefull_pricemoney · [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
Outputs of the calculation effective
NameDescription
CalculationcalculationtextEffective duration off a spot curve
Effective durationeffective_durationyears · [0, 200](P_down - P_up) / (2 P bump): relative price change per unit shift
Full pricefull_pricemoney · [0, 1e+15]Full (dirty) price at settlement, of the face value held (per 100 by default)
Price downprice_downmoney · [0, 1e+15]Full price with the curve shifted down
Price upprice_upmoney · [0, 1e+15]Full price with the curve shifted up
Key-rate durations off a spot curve (key_rate): 4 outputs
Outputs of the calculation key_rate
NameDescription
CalculationcalculationtextKey-rate durations off a spot curve
Key rate durationskey_rate_durationsyears (array) · length max 30; each [0, 200]Duration to each key tenor's shift
Effective durationeffective_durationyears · [0, 200]Duration to a parallel shift
Full pricefull_pricemoney · [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
Outputs of the calculation dv01
NameDescription
CalculationcalculationtextPrice value of a basis point
DV01dv01money · [0, 1e+15]Modified duration x full price x 0.0001: the price change per basis point
Modified durationmodified_durationyears · [0, 200]Modified duration
Full pricefull_pricemoney · [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

  1. 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))
  2. 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
  3. 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, or run_model with 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:

Python
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())
Command line
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