next up previous contents index
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 $C_t$ be the cash flow at time $t$ and $r$ be the interest rate. Suppose we have $N$ future cash flows that occur at times $t_1, t_2, \cdots , t_N$.

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

\begin{displaymath}PV = \sum_{i=1}^N e^{-rt_i} C_{t_i} \end{displaymath}

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


\begin{displaymath}PV = \sum_{i=1}^N \frac{ C_{t_i} } { (1+r)^t } \end{displaymath}

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 up previous contents index
Next: Internal rate of return. Up: Cash flow algoritms. Previous: Cash flow algoritms.   Contents   Index
Bernt Arne Odegaard
1999-09-09