Bond Pricing
Bond Pricing, Present Value of Cash Flows and Present Value of Annuity Structures
A bond constitutes a legal obligation to repay investors a stream of pre-determined cash flows. The bond can be issued by a corporation or government entity and investors who purchased this contract are future beneficiaries to paying down the legal obligations. Investors are generally free to sell on the bond before and frequently this is the case. In past, it was not uncommon for investors/bondholders to be prepared to retain the bond for the full maturity. Today, it is more common to trade bonds more frequently and the bond or bond futures contract can be bought and sold to take advantage of movement in interest rates. The issuer may also be prepared to pay off the bond early, so that it can refinanced at a lower interest rate. If so, it can be useful to calculate the present value of the bond. The steps to follow in this process are listed below. First, we need to use several assumptions as we work through the calculation steps. The assumptions are:
The bond principal/face/nominal value or Par is $1,000
The maturity date of the bond is in three years
The bond pays 6% at the end of each year
The discount rate is 5.6%
This basic information is suffice to attribute a theoretical price to the bond using a time value conceptual framework. In the video below, we compute the present value of the bond using discrete discounting.
Verify the coupon rate being paid on the bond per year. This should be available with detail provided with issuance. In this instance, the amount is $60, which is calculated as $1,000 multiplied by the 6% coupon rate on the bond.
Determine the going market interest rate or discount rate for similar bonds. Sovereigns in good standing generally will enjoy a very low cost of borrowing or discount rate give risk is considered to be reduced. These bonds should have a similar maturity date and credit rating. In this case, the market interest rate is 5.6%, since similar bonds are priced to yield that amount. Given that the discount rate < the coupon rate, the bond will trade above par ($1,000)
In excel is simple to determine the discount factor i.e. 1/(1 + Discount Rate) ^ relevant year
Multiply discount factor by contemporaneous cash flows to estimate the Present Values of Coupons and Face.
Sum the Present Values to give the correct theoretical value of $1010.77 for Bond Price.
VBA Code to estimate the Present Value of Annuity for Bond Pricing
In the video below, we employ Excel VBA
Function PVBm(cpr, r, T, Face, m)
coup = Face * cpr / m
PVBm = (coup * (1 - (1 + r / m) ^ (-T * m)) / (r / m)) + Face * (1 + r / m) ^ (-T * m)
End Function
to estimate the effect of altering the coupon frequency on the Bond Price. By virtue of including m in code we can increase frequency of the coupon. Below, we consider PV annuity formulation to estimate the Present Value with the following details
The bond principal/face/nominal value or Par is $1,000
The maturity date of the bond is in three years
The bond pays 6% at the end of each year
The discount rate is 5.6%
The frequency of coupon per annum is 2 i.e. m = 2
This produces a stream of cash flows that can be discounted using r = 0.056/2 = 0.028
The Present Value of Annuity can be represented as follows:
In the video below, we not only consider the effect of changing the frequency of coupon but we will also consider the impact of changing the discount rate
In the video, we examine the effect of changing the discount rate and their impact on the bond's value. An Excel Data table is created to observed more closely sensitivities. We create a heat map to make output visually effective. It is clear that longer dated bonds are more sensitive to changes in interest rates.
Very Simple Python Code to estimate the Present value of a Bond using Annuity
m = 2
T = 3
r = 0.056
Face = 1000
cpr = 0.06
bond_price = ((Face*cpr/m*(1-(1+r/m)**(-m*T)))/(r/m)) + Face*(1+(r/m))**(-m*T)
print(bond_price)
Python Code for Bond Pricing and some graphing
%matplotlib inline
import matplotlib.pyplot as plt
plt.style.use('seaborn-whitegrid')
import numpy as np
fig = plt.figure()
ax = plt.axes()
m = 2
T = 20
r = x
Face = 1000
cpr = 0.06
def bond_price(m,T,r,Face,cpr):
return ((Face*cpr/m*(1-(1+r/m)**(-m*T)))/(r/m)) + Face*(1+(r/m))**(-m*T)
fig = plt.figure()
ax = plt.axes()
x = np.linspace(0.01, 0.14, 14)
ax.plot(x, bond_price(m,T,x,Face,cpr));
bond_price(m,T,x,Face,cpr), x
Estimating the Present Value of Bond using C++
// main.cpp
// DiscreteBondPrice
//
// Created by Brian Byrne on 10/12/2015.
#include <cmath>
#include <iostream>
using namespace std;
double PVB(double Face,double cr,double r,int m, double T)
{
// store the value of the bond
double BV=0.;
// add in coupons
int TNC=T*m;
double cpn = (cr/m)*Face;
for(int i=1;i<=TNC; i++)
{
double ti=double(i)/double(m);
BV = BV + cpn*pow((1+r/m),-ti*m);
}
// finally add principle
BV = BV + Face*pow((1+r/m),-T*m);
return BV;
}
int main()
{
double Face = 100;
double cr = 0.1;
double r =0.1;
int m = 2;
double T =3;
cout << " The Present Value of the Discrete bond is " << PVB(Face, cr, r, m, T) <<endl;
system ("PAUSE");
}
Below, we use Microsoft Visual Studio to implement the C++ code
Estimating the present value of Bond in Xcode using C++
C++ Code implemented in OnlineGDB compiler
Estimating the Bond Price using R package: Derivmkts
# install.packages("derivmkts")
library(derivmkts)
coupon <- 60; mat <- 3; freq <- 1; principal <- 1000; yield <- 0.056;
price <- bondpv(coupon, mat, yield, principal, freq)
price
bondpv(coupon, mat, yield, principal, freq)
bondyield(coupon, mat, price=price, principal, freq)
duration(price, coupon, mat, principal, freq, modified=FALSE)
duration(price, coupon, mat, principal, freq, modified=TRUE)
convexity(price, coupon, mat, principal, freq)
Bond Pricing, Yield to Maturity and Duration measurement - using the Derivmkts R package in Colab and Excel
Python Code for estimating the Present Value of a Bond
https://www.python.org/ provides a useful shell for creating apps. IDLE (short for Integrated Development and Learning Environment) is an integrated development environment for Python, It is completely written in Python and the Tkinter GUI toolkit.
The python below creates a user-interface for estimating the present value of a bond.
# https://exploringfinance.com/bond-price-python/
import tkinter as tk
root= tk.Tk()
canvas1 = tk.Canvas(root, width = 470, height = 480)
canvas1.pack()
label1 = tk.Label(root, text='Calculate Bond Price')
label1.config(font=('helvetica', 14))
canvas1.create_window(235, 40, window=label1)
entry1 = tk.Entry (root)
canvas1.create_window(330, 100, window=entry1)
entry2 = tk.Entry (root)
canvas1.create_window(330, 140, window=entry2)
entry3 = tk.Entry (root)
canvas1.create_window(330, 180, window=entry3)
entry4 = tk.Entry (root)
canvas1.create_window(330, 220, window=entry4)
entry5 = tk.Entry (root)
canvas1.create_window(330, 260, window=entry5)
entry6 = tk.Entry (root)
canvas1.create_window(240, 380, window=entry6)
label1 = tk.Label(root, text='Number of Payments Per Period: ')
label1.config(font=('helvetica', 10))
canvas1.create_window(160, 100, window=label1)
label2 = tk.Label(root, text='Number of Years to Maturity: ')
label2.config(font=('helvetica', 10))
canvas1.create_window(160, 140, window=label2)
label3 = tk.Label(root, text='Yield to Maturity (YTM): ')
label3.config(font=('helvetica', 10))
canvas1.create_window(160, 180, window=label3)
label4 = tk.Label(root, text='Face Value: ')
label4.config(font=('helvetica', 10))
canvas1.create_window(160, 220, window=label4)
label5 = tk.Label(root, text='Coupon Rate: ')
label5.config(font=('helvetica', 10))
canvas1.create_window(160, 260, window=label5)
def calcBondPrice ():
m = float(entry1.get())
t = float(entry2.get())
ytm = float(entry3.get())/100
fv = float(entry4.get())
c = float(entry5.get())/100
bondPrice = ((fv*c/m*(1-(1+ytm/m)**(-m*t)))/(ytm/m)) + fv*(1+(ytm/m))**(-m*t)
label6 = tk.Label(root, text= bondPrice,font=('helvetica', 10, 'bold'),bg='white')
canvas1.create_window(240, 380, window=label6)
button1 = tk.Button(text='Calculate Bond Price', command=calcBondPrice, bg='green', fg='white', font=('helvetica', 9, 'bold'))
canvas1.create_window(240, 330, window=button1)
root.mainloop()
Python Code for Bond Pricing from Jeffrey Liang Repository based on Bernt Odegaard Financial recipes
The python code below comes from Jeffrey Liang github. The examples are based on the workings of Bernt Arne Ødegaard. A copy of Financial Recipes can be found here. This is a vast treasure cove with ample C++ libraries to keep you stimulated and fascinated. Below we use Jeffrey's adaptation into Python. We will work through the same numerical example as provided above for discrete time estimation. We apply the loop structure proposed by Bernt to estimate the PV of the Bond.
# https://bit.ly/2R0yRy5
def bonds_price_discrete(times, cashflows, r):
p = 0
for i in range(len(times)):
p += cashflows[i] / np.power((1 + r), times[i])
return p
import numpy as np
c = np.array([60, 60, 1060])
t = np.arange(1, 4)
r = 0.056
d = (1. / np.power((1 + r), t))
B = np.sum(d * c)
print('bonds price = {:.3f}'.format(bonds_price_discrete(t, c, r)))