Duration Metrics
Calculates the bond duration for different coupon rates and years to maturity. It has the option to calculate the following type of bond durations:
- Macaulay’s Duration: The weighted average time to receive the bond’s cash flows.
- Modified Duration: The Macaulay’s duration divided by 1 plus the per-period yield (yield to maturity divided by the frequency).
- Effective Duration: The percentage change in the bond price for a 1% change in the yield to maturity.
- Dollar Duration: The modified duration multiplied by the bond price, divided by 100.
These duration measures can be used to estimate the sensitivity of a bond’s price to changes in interest rates as well as to compare the risk of different bonds. The modified duration is particularly useful for estimating the percentage change in the bond price for a 1% change in the yield to maturity. Note that it is a percentage sensitivity and therefore not the same as the dollar duration, the price value of a basis point (PVBP) or the dollar value of a 0.01% change (DV01), which are all expressed as a currency amount instead. The dollar duration is available through this method via duration_type='dollar' and the DV01 is calculated separately, see collect_bond_statistics.
Also known as: Macaulay duration, modified duration, bond price sensitivity.
No programming experience? With the Finance Toolkit MCP server, AI assistants such as Claude and ChatGPT can calculate the Duration Metrics for you. Just ask in plain English.
Calculate the Duration Metrics in Python
The Duration Metrics is available in the Fixed Income module of the open-source Finance Toolkit. Install it with:
pip install financetoolkit -U
Then call get_duration as shown below.
from financetoolkit import FixedIncome
fixedincome = FixedIncome()
fixedincome.get_duration(
duration_type='modified',
coupon_rate=[0.03, 0.05, 0.07],
years_to_maturity=[5, 10, 15],
show_input_info=False,
)
Which returns:
| Coupon Rate | 5 | 10 | 15 |
|---|---|---|---|
| 0.03 | 4.33 | 7.82 | 10.4 |
| 0.05 | 4.18 | 7.26 | 9.41 |
| 0.07 | 4.05 | 6.87 | 8.79 |
Parameters
get_duration accepts the following parameters:
- duration_type (str, optional): The type of duration to calculate. Defaults to ‘modified’ but can also be ‘macaulay’, ‘effective’ or ‘dollar’.
- par_value (float, optional): The par value (face value) of the bond. Defaults to 100.
- coupon_rate (float, optional): The coupon rate of the bond. If not provided, a range of coupon rates will be used. Defaults to None.
- years_to_maturity (float, optional): The years to maturity of the bond in years. If not provided, a range of years to maturity will be used. Defaults to None.
- yield_to_maturity (float, optional): The yield to maturity of the bond. Defaults to 0.08.
- frequency (int, optional): The frequency of coupon payments per year. Defaults to 1.
- show_input_info (bool, optional): Whether to display input information. Defaults to True.
Related Bond Valuations
The Fixed Income module page introduces the module, and the sidebar lists all of its functions.