next up previous contents index
Next: Term structure approximations. Up: Term Structure algorithms. Previous: Term structure calculations.   Contents   Index

Subsections

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 yields.

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 find an intermediate time. For many purposes this is ``good enough.''

This interpolation can be on both yields and forward rates.

Computer algorithm, linear interpolation of yields.

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



// file lin_intp.cc
// author: Bernt A Oedegaard.
// given a set of yields, produce a term structure by linear interpolation.

#include "fin_algoritms.h"

double term_structure_yield_linearly_interpolated(double time, 
						  const vector<double>& obs_times, 
						  const vector<double>& obs_yields)
// assume the yields are in increasing time to maturity order.
{
  int no_obs = obs_times.size();
  if (no_obs<1) return 0;
    double t_min = obs_times[0];
    if (time <= t_min) return obs_yields[0];  // earlier than lowest obs.

    double t_max = obs_times[no_obs-1];  
    if (time >= t_max) return obs_yields[no_obs-1]; // later than latest obs

    int t=1;  // find which two observations we are between
    while ( (t<no_obs) && (time>obs_times[t])) 	{ ++t; }; 
    double lambda = (obs_times[t]-time)/(obs_times[t]-obs_times[t-1]);
    // by ordering assumption, time is  between t-1,t
    double r = obs_yields[t-1] * lambda + obs_yields[t] * (1.0-lambda); 
    return r;
};


As an alternative to

Computer algorithm, linear interpolation of forward rates.

Note that the algorithm assumes the rates are ordered in increasing order of time to maturity.



// file lin_intp.cc
// author: Bernt A Oedegaard.
// given a set of forward yields, produce a term structure by linear interpolation.

#include "fin_algoritms.h"
 
double term_structure_forward_linearly_interpolated(double time, 
						    const vector<double>& obs_times, 
						    const vector<double>& obs_forwards) {
// assume observations in increasing time to maturity order.
    int no_obs = obs_times.size();
    if (no_obs<1) return 0;
    double t_min = obs_times[0];
    if (time <= t_min) return obs_forwards[0];  // earlier than lowest obs.

    double t_max = obs_times[no_obs-1];  
    if (time >= t_max) return obs_forwards[no_obs-1]; // later than latest obs

    int t=1;  // find which two observations we are between
    while ( (t<no_obs) && (time>obs_times[t])) 	{ ++t; }; 
    double lambda = (obs_times[t]-time)/(obs_times[t]-obs_times[t-1]);
    // by ordering assumption, time is  between t-1,t
    double r = obs_forwards[t-1] * lambda + obs_forwards[t] * (1.0-lambda); 
    return r;
};



next up previous contents index
Next: Term structure approximations. Up: Term Structure algorithms. Previous: Term structure calculations.   Contents   Index
Bernt Arne Odegaard
1999-09-09