Next: Internal rate of return. Up: Cash flow algoritms. Previous: Cash flow algoritms.   Contents   Index

# Present value.

The calculation of present value is one of the basics of finance. The present value is the current value of a stream of future payments. Let be the cash flow at time and be the interest rate. Suppose we have future cash flows that occur at times .

If compounding is continous, would calculate the present value as follows

This calculation is implemented as follows:

// file cflow_pv.cc
// author: Bernt Arne Oedegaard.

#include <cmath>
#include <vector>

double cash_flow_pv( vector<double>& cflow_times, vector<double>& cflow_amounts, double r){
// calculate present value of cash flow, continous discounting
double PV=0.0;
for (unsigned int t=0; t<cflow_times.size();t++) {
PV += cflow_amounts[t] * exp( -r * cflow_times[t]);
};
return PV;
};


If discounting was discrete, would calculate the present value as

which is implemented as

// file cflow_pv_discrete.cc
// author: Bernt Arne Oedegaard.
// calculate the present value of a stream of cash flows using discrete compounding

#include <cmath>
#include <vector>

double cash_flow_pv_discrete( vector<double>& cflow_times,
vector<double>& cflow_amounts,
double r){
double PV=0.0;
for (unsigned int t=0; t<cflow_times.size();t++) {
PV += cflow_amounts[t] / pow(1+r,cflow_times[t]);
};
return PV;
};


Next: Internal rate of return. Up: Cash flow algoritms. Previous: Cash flow algoritms.   Contents   Index
Bernt Arne Odegaard
1999-09-09