Using the curvature of the price/yield line
In addition to using the steepness of the price/yield line to estimate the duration of a bond, you can also use its curvature to estimate the convexity of a bond.
In this exercise, you are going to plot a price/yield graph of two bonds in order to see which bond has the greatest convexity. Both bonds will pay a 5% annual coupon, have a 5% yield and a face value of USD 100, but the first bond will be a 5 year bond, and the second a 20 year bond.
numpy
, numpy_financial
, pandas
, and matplotlib
have already been imported for you as np
, npf
, pd
, and plt
, respectively.
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.
# Create array of yields and convert to pandas DataFrame
bond_yields = ____
bond = ____(____, ____)