Exercise

Plotting bond prices against yields

Being able to plot a graph of bond prices against yields can help to investigate what will happen to a bond or portfolio of bonds for different levels of interest rates in the market.

Now you are going to create a graph of bond prices against yields, but this time for two bonds of different maturities. You will do this by giving your pandas DataFrame extra columns for each additional bond. The bonds you will consider will both pay a 5% coupon, but now you will plot a 5 year and a 10 year bond.

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 (not inclusive) in increments of 0.1.
  • Convert this array into a pandas DataFrame and name the column bond_yield.
  • Add two more columns, one for each bond (5-year and 10-year), and find the price for a given level of yield.
  • Plot a graph of these bonds, setting the x-axis label to Yield (%) and y-axis label to Bond Price (USD).