eFinancialPlanner  V1.0 (proof of concept)
Personal Financial Planning based on Maslowian Portfolio Theory
 All Classes Namespaces Files Functions Variables Typedefs Friends Macros Pages
efp.cpp
Go to the documentation of this file.
1 
63 //#define LEND_RATE 0.1 ///< the rate at which people can lend money expressed as a percentage per year (eg. 0.1 = 10%)
65 #define SECONDS_IN_MONTH 2629800
66 #define MAX_AGE 150
67 #define MIN_ALPHA 0.075
68 #define MAX_ALPHA 0.25
69 #define ALPHA_UPPER_LIMIT 0.4
70 #define ALPHA_LOWER_LIMIT 0.1
71 #define ALPHA_PLOT_LOW 0.1
72 #define ALPHA_PLOT_HIGH 0.9
73 #define RAINY_DAY_MONTH_NBR 3
74 #define RETIREMENT_AGE 65
75 #define SIMULATE_TILL_DEFAULT 90
76 #define MIN_YEARS_TO_SIMULATE 2
77 #define NBR_ITERATIONS 20
78 #define PRECISSION 0.000001
79 #define CURR_LEN 14
80 #define NBR_TABS 7
81 #define NBR_SUB_TABS 3
82 #define NBR_RIGHT_MENU 3
83 #define INPUT_WIDTH_TEXT 15
84 #define INPUT_WIDTH_FLOAT 5
85 #define INPUT_WIDTH_INT 2
86 //define NBR_COLS_SP
87 #define MAX_MONTHS_TO_SAFEST 3
88 #define NBR_SCALE 5
89 #define DEFAULT_SCALE 3
90 #define MAX_SCALE 5
91 #define MIN_SCALE 1
92 #define MAX_MNTHS_2_SIMULATE 600
93 #define MIN_MNTHS_2_SIMULATE 1
94 //#define SHOW_Vexp_not_Vmed
95 
96 // TODO find automatically:
97 #define NBR_ASSET_CLASSES 10
98 // uses previous
99 //#define INDEX(x,y) ((x-1)+((NBR_ASSET_CLASSES)*(y-1))) ///< this macro allows to address int cell = array[INDEX(2,3)]; in stead of array[2+NBR_ASSET_CLASSES*3]; (using a one dimensional array to store a two dimnesional one!)
100 #define INDEX(x,y) ((y-1)+((NBR_ASSET_CLASSES)*(x-1)))
101 /*#define INDEX(x,y) ((x)+((NBR_ASSET_CLASSES)*(y))) ///< this macro allows to address int cell = array[INDEX(2,3)]; in stead of array[2+NBR_ASSET_CLASSES*3]; (using a one dimensional array to store a two dimnesional one!)*/
102 
103 
104 
105 //#define DEBUG
106 
107 
108 #include <iostream>
109 #include <string>
110 #include <ctime>
111 #include <vector>
112 #include <map>
113 #include <unordered_map>
114 #include <math.h>
115 #include <locale>
116 #include <iomanip> // used in the curr_format() function
117 #include <errno.h>
118 
119 #include "normdist.h" // has to be loaded before cgicc, conflicts with typedef class cgicc::HTMLBooleanElement<cgicc::aTag> cgicc::a
120 
121 #include <cgicc/Cgicc.h>
122 #include <cgicc/HTTPHTMLHeader.h>
123 #include <cgicc/HTMLClasses.h>
124 #include <cppconn/prepared_statement.h>
125 
126 using namespace std;
127 using namespace cgicc;
128 
129 Cgicc cgi;
130 
132 string error_message = "";
133 string std_message = "";
134 #ifdef DEBUG
135 std::string debug_info = "";
136 #endif
137 
139 #include <mysql_connection.h>
140 #include <driver.h>
141 #include <exception.h>
142 #include <resultset.h>
143 #include <statement.h>
144 #include <string.h>
145 #include <cmath>
146 
148 #include "config.class.cpp"
150 
151 #include "t_personalize_Eng_UK.h"
152 #include "texts_Eng_UK.h"
153 #include "t_disclaimer_Eng_UK.h"
154 #include "global_functions.h"
155 
156 #include "bootstrap.namespace.cpp"
157 using namespace bootstrap;
158 
160 unordered_map<string, int> goal_type_s2i =
161 {
162  {"unallocated", 0},
163  {"amount@date", 1},
164  {"income from/to", 2},
165  {"rainy day savings", 3},
166  {"amount asap", 4}
167 };
168 unordered_map<int, string> goal_type_i2s =
169 {
170  {0, "unallocated"},
171  {1, "amount@date"},
172  {2, "income from/to"},
173  {3, "rainy day savings"}
174 };
175 
176 
178 //#include "breadcrumb.struct.cpp"
179 #include "html_helper.class.cpp"
181 
182 #include "db_helper.class.cpp"
184 
185 #include "frequency.class.cpp"
186 #include "currency.class.cpp"
188 
189 #include "asset_class.class.cpp"
191 
192 #include "asset.class.cpp"
194 
195 #include "column.class.cpp"
196 #include "bona.class.cpp"
197 #include "bona_goal.class.cpp"
199 #include "bona_cf.class.cpp"
201 
202 #include "portfolio.class.cpp"
203 #include "market.class.cpp"
204 #include "investor.class.cpp" // requires market.class
205 #include "aGOAL.struct.cpp"
206 #include "investment_problem.class.cpp" // requires investor.class and portfolio.class
207 #include "simulation.class.cpp" // requires investment_problem.class
208 #include "follow_up.class.cpp" // requires simulation.class
209 #include "investor_ui.class.cpp" // requires investor.class
210 
212 
218 int main (int argc, char **argv)
219 {
220  oInvestor.set_investor_id_fromEnv(); // prune is_logged_in, get cookie, then check
221  // if is_logged_in then the investor_id is set (otherwise it is 0)
223 
224  string action = cgi("a");
225 
226  /*
227  // TEST
228  action = "rERvol";
229  oInvestor.investor_id = 1;
230  // END TEST
231  */
232 
233  if (action=="h" || action=="") oInvestor.home_screen();
234  else if (action=="rf") oInvestor.register_form();
235  else if (action=="re") oInvestor.register_exec();
236  else if (action=="lf") oInvestor.login_form();
237  else if (action=="le") oInvestor.login_exec();
238  else if (action=="io") oInvestor.logout();
239  else if (action=="d") oInvestor.show_disclaimer();
240  else if (action=="gh") oInvestor.goal_help_form();
241  else // so for al other action codes check if the user is allowed to do it
242  {
243  if (oInvestor.investor_id == 0)
244  {
245  error_message = error_message + t_errMsg["loginFirst"];
247  }
248  else
249  {
250  if (action=="if") oInvestor.show_inventory_form();
251  else if (action=="p") oInvestor.personalize_screen();
252  else if (action=="ps") oInvestor.personalize_save();
253  else if ((action=="rERvol") || (action=="rER") || (action=="rvol") || (action=="rcorr")) oInvestor.personalize_reload(action);
254  else if (action=="aa") oInvestor.asset_add();
255  else if (action=="ae") oInvestor.asset_edit();
256  else if (action=="as") oInvestor.asset_save();
257  else if (action=="ad") oInvestor.asset_delete();
258  else if (action=="gh") oInvestor.goal_help_form();
259  else if (action=="ghs") oInvestor.goal_help_save();
260  else if (action=="gl") oInvestor.goal_list();
261  else if (action=="ga") oInvestor.goal_add();
262  else if (action=="ge") oInvestor.goal_edit();
263  else if (action=="gs") oInvestor.goal_save();
264  else if (action=="gd") oInvestor.goal_delete();
265  else if (action=="cl") oInvestor.cash_flow_list();
266  else if (action=="ca") oInvestor.cash_flow_add();
267  else if (action=="ce") oInvestor.cash_flow_edit();
268  else if (action=="cs") oInvestor.cash_flow_save();
269  else if (action=="cd") oInvestor.cash_flow_delete();
270  else if (action=="f") oInvestor.feedback();
271  else if (action=="s") oInvestor.show_simulation();
272  else if (action=="fu") oInvestor.show_follow_up();
273  else if (action=="ie") oInvestor.account_form();
274  else if (action=="is") oInvestor.account_save();
275  else {oInvestor.home_screen();}
277  }
278  }
279  return 0; // to avoid Apache errors
280 }
cash_flow oCF
Definition: efp.cpp:200
goal oGoal
Definition: efp.cpp:198
int main(int argc, char **argv)
Definition: efp.cpp:218
investor_ui oInvestor
Definition: efp.cpp:211
cls_currency oCurrency
Definition: efp.cpp:187
void update_last_activity_at()
unordered_map< int, string > goal_type_i2s
Definition: efp.cpp:168
asset_class oAssetClass
Definition: efp.cpp:190
string error_message
global message variables
Definition: efp.cpp:132
asset oAsset
Definition: efp.cpp:193
html_helper hh
own c++ classes
Definition: efp.cpp:180
void personalize_reload(string action)
db_helper db
Definition: efp.cpp:183
Cgicc cgi
Definition: efp.cpp:129
void show_inventory_form()
unordered_map< string, string > t_errMsg
Definition: texts_Eng_UK.h:86
bool set_investor_id_fromEnv()
string std_message
Definition: efp.cpp:133
config oConfig
mysql connection mysql connector from dev.mysql.com
Definition: efp.cpp:149
int load_from_db(string investorID)
unordered_map< string, int > goal_type_s2i
Global lists.
Definition: efp.cpp:160