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

Exercise

Plotting duration vs. the factor

Plotting a graph of duration against a factor such as maturity, coupons, or yields is a great way to see how the factor affects the duration of a bond.

In the video, we plotted a graph of duration against maturity. In this exercise, you are going to do the same thing for the coupon rate. You will use a 10 year bond with a yield of 5% and face value of USD 100.

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 coupons from 0 to 10 in increment sizes of 0.1, and convert to a pandas DataFrame.
  • Add four additional columns to the DataFrame; price, price_up, price_down, and duration for the bond.
  • Plot a graph with bond_coupon on the x-axis and duration on the y-axis.