Present value.

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; };