1. Learn
  2. /
  3. Courses
  4. /
  5. Bond Valuation and Analysis in Python

Exercise

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.

Instructions 1/3

undefined XP
    1
    2
    3
  • Create an array of yields from 0 to 20 in steps of 0.1 using the np.arange() function.
  • Convert this array to a pandas DataFrame with the column title bond_yield.