LINEBURG

 << Пред. стр. страница 3(всего 20)ОГЛАВЛЕНИЕ След. стр. >>

Code 2.4: Test for uniqueness of IRR

15
2.3 Bonds

In this part we look at the treatment of bonds and similar п¬Ѓxed income securities. What distinguishes bonds
is that the future payments (of coupon, principal) are decided when the security is issued. We again limit
ourselves to the case of a п¬‚at term structure, and return to bond pricing with more general term structures
later.

2.3.1 Bond Price

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

В·В·В· T
t= 01 2 3
В·В·В· C
Coupon C C C
Face value F

The current price of the bond is
T
C F
P0 = +
(1 + r)t (1 + r)T
t=1

with discrete compounding, and
T
eв€’rt C + eв€’rT F
P0 =
t=1

with continous compounding. The interest rate r is п¬Ѓxed, which means that the term structure is вЂњп¬‚at.вЂќ
Let us look at two versions of the bond price algorithm for the continous case.

#include <cmath>
#include <vector>
using namespace std;

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) {
double p = 0;
for (int i=0;i<coupon times.size();i++) {
p += exp(в€’r*coupon times[i])*coupon amounts[i];
};
for (int i=0;i<principal times.size();i++) {
p += exp(в€’r*principal times[i])*principal amounts[i];
};
return p;
};

Code 2.5: Bond price

There are two version of the routine listed, one which is called with both interest and principal vectors
(code 2.5) and another (code 2.6) which is simply called with the cashп¬‚ows. I show 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 cashп¬‚ows, 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

16
#include <cmath>
#include <vector>
using namespace std;

double bonds price(const vector<double>& cashп¬‚ow times,
const vector<double>& cashп¬‚ows,
const double& r) {
double p=0;
for (int i=0;i<cashп¬‚ow times.size();i++) {
p += exp(в€’r*cashп¬‚ow times[i])*cashп¬‚ows[i];
};
return p;
};

Code 2.6: Bond price

and what is principal. But in the simple cases considered here I stick to the case of one set of cashп¬‚ows, it
makes the routines easier to follow.
Let us also look at the case of discrete (annual) compounding, shown in code 2.7.

#include <cmath>
#include <vector>
using namespace std;

double bonds price discrete(const vector<double>& cashп¬‚ow times,
const vector<double>& cashп¬‚ows,
const double& r) {
double p=0;
for (int i=0;i<cashп¬‚ow times.size();i++) {
p +=cashп¬‚ows[i]/(pow((1+r),cashп¬‚ow times[i]));
};
return p;
};

Code 2.7: Bond price

2.3.2 Yield to maturity.

The yield to maturity is the interest rate that makes the present value of the future coupon payments equal
to the current bondprice, that is, for a known price P0 , the yield is the solution y to the equation
T
eв€’yt C + eв€’yT F
P0 =
t=1

Note that this is the same as п¬Ѓnding the internal rate of return, if we include in the cash п¬‚ows the price of
the bond as a negative cash п¬‚ow вЂњtodayвЂќ. The algoritm shown in code 2.8 is simple bisection, we know that
the yield is above zero, and п¬Ѓnd a maximium yield which the yield is below, and then bisect the interval
until we are вЂњclose enough.вЂќ

17
#include <cmath>
#include "fin_recipes.h"

double bonds yield to maturity( const vector<double>& cashп¬‚ow times,
const vector<double>& cashп¬‚ow amounts,
const double& bondprice) {
const п¬‚oat ACCURACY = 1eв€’5;
const int MAX ITERATIONS = 200;
double bot=0, top=1.0;
while (bonds price(cashп¬‚ow times, cashп¬‚ow amounts, top) > bondprice) {
top = top*2;
};
double r = 0.5 * (top+bot);
for (int i=0;i<MAX ITERATIONS;i++){
double diп¬Ђ = bonds price(cashп¬‚ow times, cashп¬‚ow amounts,r) в€’ bondprice;
if (std::fabs(diп¬Ђ)<ACCURACY) return r;
if (diп¬Ђ>0.0) { bot=r;}
{ top=r; };
else
r = 0.5 * (top+bot);
};
return r;
};

Code 2.8: Bond yield

18
2.3.3 Duration.

The duration of a bond is the вЂњweighted average maturityвЂќ of the bond.

tCt Pt
Duration =
Bond Price
t

where

вЂў Ct is the cash п¬‚ow in period t, and
вЂў Pt is the discount factor, the current price of a discount bond paying \$1 at time t.

There are two versions of the duration calculation, based on how one estimate the bond price. One assumes
the current interest rate r and calculates
T
eв€’rt Ct
Bond price =
t=1

which gives the duration calculation shown in code 2.9

#include <cmath>
#include <vector>
using namespace std;

double bonds duration(const vector<double>& cashп¬‚ow times,
const vector<double>& cashп¬‚ows,
const double& r) {
double S=0;
double D1=0;
for (int i=0;i<cashп¬‚ow times.size();i++){
S += cashп¬‚ows[i] * exp(в€’r*cashп¬‚ow times[i]);
D1 += cashп¬‚ow times[i] * cashп¬‚ows[i] * exp(в€’r*cashп¬‚ow times[i]);
};
return D1 / S;
};

Code 2.9: Bond duration

Alternatively one can calculate the yield to maturity for the bond, and use that in estimating the bond price.
This is called Macaulay Duration First one calculates y, the yield to maturity, from
T
eв€’yt Ct
Bond price =
t=1

and then use this y in the duration calculation:

tCt eв€’yt
Macaulay duration =
eв€’yt Ct

Code 2.10

Modiп¬Ѓed Duration
duration
Modiп¬Ѓed Duration =
yield

19
#include "fin_recipes.h"

double bonds duration macaulay(const vector<double>& cashп¬‚ow times,
const vector<double>& cashп¬‚ows,
const double& bond price) {
double y = bonds yield to maturity(cashп¬‚ow times, cashп¬‚ows, bond price);
return bonds duration(cashп¬‚ow times, cashп¬‚ows, y); // use YTM in duration
};

Code 2.10: Calculating the Macaulay duration of a bond

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

double bonds duration modiп¬Ѓed (const vector<double>& cashп¬‚ow times,
const vector<double>& cashп¬‚ow amounts,
const double& bond price,
const double& r){
double dur = bonds duration(cashп¬‚ow times, cashп¬‚ow amounts, r);
double y = bonds yield to maturity(cashп¬‚ow times, cashп¬‚ow amounts, bond price);
return dur/(1+y);
};

Code 2.11: Modiп¬Ѓed duration

Bond convexity

Convexity measures the curvature of the approximation done when using duration. It is calculated as
n
ci t2 eв€’yti
i
i=1

#include <cmath>
#include <vector>
using namespace std;

double bonds convexity(const vector<double>& cashп¬‚ow times,
const vector<double>& cashп¬‚ow amounts,
const double& y ) {
double C=0;
for (int i=0;i<cashп¬‚ow times.size();i++){
double t = cashп¬‚ow times[i];
C+= cashп¬‚ow amounts[i] * t * t * exp(в€’y*t);
};
return C;
};

Code 2.12: Bond convexity

20
Chapter 3

The term structure of interest rates and an object lesson
Contents
3.1 Term structure calculations . . . . . . . . . . . . . . . . . . .......... . . 21
3.2 Using the currently observed term structure. . . . . . . . .......... . . 22
3.2.1 Linear Interpolation. . . . . . . . . . . . . . . . . . . . . . . ........... . . 22
3.3 The term structure as an object . . . . . . . . . . . . . . . .......... . . 22
3.4 Implementing a term structure class . . . . . . . . . . . . . .......... . . 23
3.4.1 Base class . . . . . . . . . . . . . . . . . . . . . . . . . . . . ........... . . 23
3.4.2 Flat term structure. . . . . . . . . . . . . . . . . . . . . . . ........... . . 25
3.4.3 Interpolated term structure. . . . . . . . . . . . . . . . . . . ........... . . 26
3.5 Bond calculations using the term structure class . . . . . .......... . . 28

In this chapter we look at various algorithms that has been used to estimate a вЂњterm structure,вЂќ i e a relation
between length of period for investment and interest rate.
The term structure is the current price for a future (time t) payment of one dollar (discount factor). It can
also be viewed as the yield on a zero coupon bond paying one dollar at time t. Alternatively one can think
about forward interest rates, the yield on borrowing at some future date t1 and repaying it at a later date
t2 . Knowing one of these one also knows the others, since there are one-to-one transforms moving one into
the other.

3.1 Term structure calculations

Let us show some useful transformations for moving between these three alternative views of the term
structure. . Let r(t) be the yield on a tвЂ“period discount bond, and d(t) the discount factor for time t (the
current price of a bond that pays \$1 at time t. Then

d(t) = eв€’r(t)t

в€’ ln(d(t))
r(t) =
t

Also, the forward rate for borrowing at time t1 for delivery at time T is calculated as

d(T ) d(t1 )
в€’ ln ln
d(t1 ) d(T )
ft (t1 , T ) = =
T в€’ t1 T в€’ t1

The forward rate can also be calculated directly from yields as

T в€’t t1 в€’ t
в€’ rd (t, t1 )
fd (t, t1 , T ) = rd (t, T )
T в€’ t1 T в€’ t1

Note that this assumes continously compounded interest rates.
Code 3.1 shows the implementation of these transformations.

21
#include <cmath>
using namespace std;

double term structure yield from discount factor(const double& dfact,
const double& t) {
return (в€’log(dfact)/t);
}

double term structure discount factor from yield(const double& r,
const double& t) {
return exp(в€’r*t);
};

double term structure forward rate from disc facts(const double& d t,
const double& d T,
const double& time) {
return (log (d t/d T))/time;
};

double term structure forward rate from yields(const double& r t1,
const double& r T,
const double& t1,
const double& T) {
return (r T*(T/(Tв€’t1))в€’r t1*(t1/T));
};

Code 3.1: Term structure transformations

3.2 Using the currently observed term structure.

To just use todays term structure, we need to take the observations of yields that is observed in the market
and use these to generate a term structure. The simplest possible way of doing this is to linearly interpolate
the currently observable zero coupon yields.

3.2.1 Linear Interpolation.

If we are given a set of yields for various maturities, the simplest way to construct a term structure is by
straightforward linear interpolation between the observations we have to п¬Ѓnd an intermediate time. For
many purposes this is вЂњgood enough.вЂќ This interpolation can be on either yields, discount factors or forward
rates, we illustrate the case of linear interpolation of spot rates.

Computer algorithm, linear interpolation of yields. Note that the algorithm assumes the yields are
ordered in increasing order of time to maturity.

3.3 The term structure as an object

To actually use the term structure one has to specify one of these three alternative views of the term stucuture
for all possible future dates. This is of course not feasible, so one will need to have a method for specifying
the term structure, such as the linear interpolation above. Next this term structure will have to be made
available for use in other contexts. This is perfect for specifying a class, so we will use this as the prime
example of the uses of a class. One can think of the term structure class as an abstract function that either
return a discount factor or a yield.
 << Пред. стр. страница 3(всего 20)ОГЛАВЛЕНИЕ След. стр. >>