Bond prices vs. bond yields

Bond Valuation and Analysis in Python

Joshua Mayhew

Options Trader

Historical government bond yields

Bond Valuation and Analysis in Python

Plotting bond prices vs. yields

import numpy as np
import numpy_financial as npf
import pandas as pd
import matplotlib.pyplot as plt
bond_yields = np.arange(0, 20, 0.1)
print(bond_yields)
[0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 1.1 1.2 1.3
...
18.5 18.6 18.7 18.8 18.9 19.0 19.1 19.2 19.3 19.4 19.5 19.6 19.7 19.8 19.9]
Bond Valuation and Analysis in Python

Plotting bond prices vs. yields

bond = pd.DataFrame(bond_yields, columns=['bond_yield'])
print(bond)
     bond_yield
0           0.0
1           0.1
..          ...
198        19.8
199        19.9
[200 rows x 1 columns]
Bond Valuation and Analysis in Python

Plotting bond prices vs. yields

bond['bond_price'] = -npf.pv(rate=bond['bond_yield'] / 100, nper=10, pmt=5, fv=100)
print(bond)
     bond_yield  bond_price
0           0.0  150.000000
1           0.1  148.731575
..          ...         ...
198        19.8   37.527719
199        19.9   37.319493
[200 rows x 2 columns]
Bond Valuation and Analysis in Python

Plotting bond prices vs. yields

plt.plot(bond['bond_yield'], bond['bond_price'])

plt.xlabel('Yield (%)')
plt.ylabel('Bond Price (USD)')
plt.title("10 Year Bond 5% Annual Coupon")
plt.show()

Bond Valuation and Analysis in Python

The relationship between price and yield

Prices move inversely to yields

Higher yield = higher discount rate = lower PV

Higher price lowers the return on investment (yield)

Bond Valuation and Analysis in Python

The relationship between price and yield

Bond premium vs. bond discount

Premium: Price > 100, Yield < Coupon

Discount: Price < 100, Yield > Coupon

Par: Price = 100, Yield = Coupon

Bond Valuation and Analysis in Python

The relationship between price and yield

Price/yield relationship is non-linear

The line we have plotted is not a straight line

This is due to something called convexity

Bond Valuation and Analysis in Python

The relationship between price and yield

Summary of key points:

  • Prices and yields move inversely
  • Premium: Price > 100, Yield < Coupon
  • Discount: Price < 100, Yield > Coupon
  • Par: Price = 100, Yield = Coupon
  • The price/yield relationship is non-linear

Bond Valuation and Analysis in Python

Let's practice!

Bond Valuation and Analysis in Python

Preparing Video For Download...