next up previous contents index
Next: Yield to maturity. Up: Bond Algoritms. Previous: Bond Algoritms.   Contents   Index


Bond Price.

The price of a bond is the present value of its future cashflows. If we consider a coupon bond like a US goverment bond (T-Bond), the cash flows look like

\begin{displaymath}
\begin{array}{lcccccc}
t=& 0&1&2&3&\cdots&T\\
\textrm{Coupo...
...C&C&\cdots&C\\
\textrm{Face value} & & & & & &F\\
\end{array}\end{displaymath}

The current price of the bond is

\begin{displaymath}P_0 = \sum_{t=1}^T \frac{C}{(1 + r)^{t}} + \frac{F}{(1+r)^T} \end{displaymath}

with discrete compounding, and

\begin{displaymath}P_0 = \sum_{t=1}^T e^{-rt}C + e^{-rT}F \end{displaymath}

with continous compounding. The interest rate $r$ is fixed, which means that the term structure is ``flat.''

Let us look at two versions of the bond price algorithm for the continous case.



// file bonds_price_both.cc
// author: Bernt A Oedegaard.

#include <cmath>
#include <vector>

double bonds_price(const vector<double>& coupon_times,
		   const vector<double>& coupon_amounts,
		   const vector<double>& principal_times,
		   const vector<double>& principal_amounts, 
		   const double& r) 
  // calculate bond price when term structure is flat, 
  // given both coupon and principals
{ 
    double p = 0; 
    for (unsigned i=0;i<coupon_times.size();i++) { 
	p += exp(-r*coupon_times[i])*coupon_amounts[i];
    };
    for (unsigned i=0;i<principal_times.size();i++) { 
	p += exp(-r*principal_times[i])*principal_amounts[i]; 
    }; 
    return p; 
};




// file bonds_price.cc
// author: Bernt A Oedegaard.

#include <cmath>
#include <vector>

double bonds_price(const vector<double>& cashflow_times,
		   const vector<double>& cashflows,
		   const double& r) { 
    // calculate bond price when term structure is flat, 
    double p=0;
    for (unsigned i=0;i<cashflow_times.size();i++) { 
	p += exp(-r*cashflow_times[i])*cashflows[i];
    };
    return p; 
};


There are two version of the routine listed, one which is called with both interest and principal vectors, another which is simply called with the cashflows. I put up both to make one think about the fact that for most purposes the distinction between coupons and principals is not necessary to make, what counts is the cashflows, which is the sum of coupons and principal. There are cases where the distinction is important, for example when taxes are involved. Then we need to keep track of what is interest and what is principal. But in the simple cases considered here we stick to the case of cashflows, it makes the routines easier to follow.

Let us also look at the case of discrete (annual) compounding:



// file bonds_price.cc
// author: Bernt A Oedegaard.

#include <cmath>
#include <vector>

double bonds_price_discrete(const vector<double>& cashflow_times,
			    const vector<double>& cashflows,
			    const double& r) { 
    // calculate bond price when term structure is flat, 
    double p=0;
    for (unsigned i=0;i<cashflow_times.size();i++) { 
	p +=cashflows[i]/(pow((1+r),cashflow_times[i]));
    };
    return p; 
};


In the previous we assumed the term structure was flat. In most cases that is not a reasonable assumption, we need to use a general term_structure for discounting.

\begin{displaymath}P_0 = \sum_{t=1}^T d(t)C + d(T)F, \end{displaymath}

where $d(t)$ is a function that discounts a payment at time $t$ to its value today. For example, a flat term structure has the following simple discount function:

\begin{displaymath}d(t) = \frac{1}{(1+r)^t}. \end{displaymath}

For routines involving the term structure a term_structure class is assumed available.10.1 For the purposes of the ``algoritms paper,'' think of it as an abstract function that either return a discount_factor or a yield.



// file bonds_price_termstru.cc 
// author: Bernt Arne Odegaard

#include <vector>
#include "term_structure_class.h"

double bonds_price(const vector<double>& cashflow_times,  
		   const vector<double>& cashflows,
		   const term_structure_class& d) { 
    double p = 0; 
    for (unsigned i=0;i<cashflow_times.size();i++) { 
	p += d.discount_factor(cashflow_times[i])*cashflows[i];
    };
    return p; 
}; 



next up previous contents index
Next: Yield to maturity. Up: Bond Algoritms. Previous: Bond Algoritms.   Contents   Index
Bernt Arne Odegaard
1999-09-09