Exercise

Plotting convexity vs. the factor

Another way to check what effect a certain factor has on bond convexity is to directly plot a graph of this factor against the bond's convexity.

In this exercise, you will price a 20 year bond with a 6% coupon and face value of USD 100, then find the convexity of this bond for different levels of yields.

numpy, numpy_financial, pandas, and matplotlib have already been imported for you as np, npf, pd, and plt, respectively.

Instructions

100 XP
  • Create an array of bond yields from 0 to 20 in increments of 0.1 and convert to a pandas DataFrame.
  • Find the price of the bond, shift the yields up and down and reprice, then calculate the convexity of the bond.
  • Plot a graph of bond yields on the x-axis against convexity on the y-axis.