financial.macaulay_duration¶
Calculate the Macaulay Duration of a bond. Reference: https://www.investopedia.com/terms/m/macaulayduration.asp
Functions¶
|
Calculates the Macaulay Duration of a bond. |
Module Contents¶
- financial.macaulay_duration.macaulay_duration(face_value: float, coupon_rate: float, periods: int, yield_rate: float) float¶
Calculates the Macaulay Duration of a bond.
- Parameters:
face_value – The final payout amount of the bond.
coupon_rate – The annual interest rate paid by the bond.
periods – The number of years until the bond matures.
yield_rate – The current market interest rate used to discount future cash flows.
- Returns:
The Macaulay Duration of the bond in years.
>>> round(macaulay_duration(1000.0, 0.05, 8, 0.04), 2) 6.83 >>> round(macaulay_duration(987435.34, 0.07, 5, 0.038), 2) 4.43 >>> round(macaulay_duration(3564.2, 0.023, 6, 0.071), 2) 5.62 >>> macaulay_duration(-1000.0, 0.05, 8, 0.04) Traceback (most recent call last): ... ValueError: face_value must be > 0 >>> macaulay_duration(1000.0, -0.05, 8, 0.04) Traceback (most recent call last): ... ValueError: coupon_rate must be >= 0 >>> macaulay_duration(1000.0, 0.05, 0, 0.04) Traceback (most recent call last): ... ValueError: periods must be > 0 >>> macaulay_duration(1000.0, 0.05, 8, -0.04) Traceback (most recent call last): ... ValueError: yield_rate must be > 0