Aan de slagGa gratis aan de slag

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.

Deze oefening maakt deel uit van de cursus

Bond Valuation and Analysis in Python

Cursus bekijken

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

# 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: ", ____)
Code bewerken en uitvoeren