Comparing the duration of two bonds directly
A quick way to check the impact of a factor on duration is to find the duration of two different bonds where you increase this factor and see what effect it has on the bond's duration.
In this exercise, you will calculate the duration of a 10 year and a 20 year bond, both paying an annual coupon of 3%, with a face value of USD 100, and yield to maturity of 5%.
numpy_financial
is already imported for you as npf
.
This exercise is part of the course
Bond Valuation and Analysis in Python
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Find & print duration of 10 year bond with 3% coupon & 5% yield
price_10y = -npf.pv(rate=0.05, nper=____, pmt=____, fv=____)
price_up_10y = -npf.pv(rate=0.06, nper=____, pmt=____, fv=____)
price_down_10y = -npf.pv(rate=0.04, nper=____, pmt=____, fv=____)
duration_10y = (____ - ____) / (____ * ____ * ____)
print("10 Year Bond: ", ____)