next up previous contents index
Next: Exotic options. Up: Bond Algoritms. Previous: Duration.   Contents   Index

Convexity

Convexity measures the curvature of the approximation done when using duration. It is calculated as

\begin{displaymath}\sum_{i=1}^nc_it_i^2e^{-yt_i}\end{displaymath}



// file bonds_convexity.cc
// author: Bernt A Oedegaard.
// calculate convexity of a bond.

#include <cmath>
#include <vector>

double bonds_convexity(const vector<double>& cashflow_times,   
		       const vector<double>& cashflow_amounts,
		       const double& y ) 
{
    double C=0;
    for (unsigned i=0;i<cashflow_times.size();i++){
	double t = cashflow_times[i];
	C+= cashflow_amounts[i] * t * t * exp(-y*t);
    };
    return C;
};



next up previous contents index
Next: Exotic options. Up: Bond Algoritms. Previous: Duration.   Contents   Index
Bernt Arne Odegaard
1999-09-09