1#ifndef ECONOMIC_ENTITY_H
2#define ECONOMIC_ENTITY_H
6#include <unordered_map>
14 if (financial_data_.count(key) > 0) {
15 return financial_data_.find(key)->second;
17 throw std::runtime_error(
"Key '" + key +
18 "' not found in financial_data_");
26 financial_data_[key] = value;
37 for (
const auto& parameter : econ_params) {
51 virtual double PV(
int n,
double i,
double F,
double A)
const {
52 double pv_F = F / std::pow((1 + i), n);
57 pv_A = A * (1 - std::pow((1 + i), -n)) / i;
73 virtual double FV(
int n,
double i,
double P,
double A)
const {
74 double fv_P = P * std::pow((1 + i), n);
79 fv_A = A * (std::pow((1 + i), n) - 1) / i;
96 virtual double PMT(
int n,
double i,
double P,
double F)
const {
98 throw std::invalid_argument(
"n must be greater than or equal to zero!");
102 double f_term = F / std::pow((1 + i), n);
106 return (p_term + f_term) * i / (1 - std::pow((1 + i), -n));
108 return (p_term + f_term) / n;
119 virtual double PV(
double i,
const std::vector<double>& A)
const {
122 for (
int t = 0; t < A.size(); ++t) {
123 pv += A[t] / std::pow((1 + i), t + 1);
133 std::unordered_map<std::string, double> financial_data_;
virtual double PMT(int n, double i, double P, double F) const
computes the regular payment for n time periods that is equivalent to the combination of a single pay...
virtual double FV(int n, double i, double P, double A) const
calculates the future value of a series of payments, using compound rate i per time period,...
virtual double PV(double i, const std::vector< double > &A) const
calculates the present value of a series of payments described by the vector [A], occurring over a ti...
static constexpr int kDefaultUnitCost
void InitEconParameters()
Initialize the list of EconParameters from the ParamList.
virtual std::unordered_map< std::string, double > GenerateParamList() const
virtual void SetEconParameter(const std::string &key, double value)
Add a new EconParameter to financial_data_.
virtual double PV(int n, double i, double F, double A) const
calculates the present value of a series of payments, using discount rate i per time period,...
virtual double GetEconParameter(const std::string &key) const
Fetches the value corresponding to "key" from financial_data_.