#include<cmath>
#include<vector>
#include<iostream>
#include"cash_flow.h"

using namespace std;

cash_flow::cash_flow() { times.push_back(0.0); amounts.push_back(0.0);};

cash_flow::cash_flow(istream& is)
{
	double t,c;
	cout<<"Enter times and amounts:\n";
	while(is>>t>>c)
	{
		times.push_back(t);
		amounts.push_back(c);
	}

};

cash_flow::cash_flow(vector<double> &t,vector<double> &a)
{
	times=t;
	amounts=a;
};


vector<double> cash_flow::get_times(){
	return times;
};
vector<double> cash_flow::get_amounts(){
	return amounts;
};


double cash_flow::principal_value_discrete(const double &r) {

	double PV=0.0;
	/*vector<double>::const_iterator t=times.begin();
	vector<double>::const_iterator a=amounts.begin();

		for(t=times.begin();t!=times.end();++t,++a)
		{
			PV+=*a/pow(1+r,*t);
		}
		return PV;
}*/
	for(size_t t=0;t<times.size();t++)
	{
		PV+=amounts[t]/pow((1+r),times[t]);
	}
	return PV;
}

double cash_flow::principal_value_cont(const double& r) {

	double PV=0.0;

/*	for(size_t t=0;t<times.size();t++)
	{
		PV+=exp(-r*times[t])*amounts[t];
	}
	return PV;
}*/
vector<double>::const_iterator t=times.begin();
	vector<double>::const_iterator a=amounts.begin();

		for(t=times.begin();t!=times.end();++t,++a)
		{
			PV+=*a*exp(-r*(*t));
		}
		return PV;
}
double cash_flow::IRR()
{
	return 0;
}



	


	
		




	

