![]() |
eFinancialPlanner
V1.0 (proof of concept)
Personal Financial Planning based on Maslowian Portfolio Theory
|
Public Member Functions | |
| investment_problem (int investor) | |
| Constructor. More... | |
| void | solve () |
| allocates means (with a benchmark) to goals More... | |
| int | get_nbr_goals () |
| int | get_max_month_for_lower_goals (int g) |
| void | javaGraph (int g, string xtra_var="", string xtra_label="", int followup_mnth=0) |
| void | prepare_javaVars_colors (int g, int followup_mnth) |
| void | parse_javaGraph (int g, string xtra_var="", string xtra_label="") |
| plots the chartOverview More... | |
| string | get_full_name () |
| float | age (int Mnbr=0) |
| int | months2simulate () |
| int | load_from_db (string investorID) |
| void | load_ER (int person=0, char person_type= 'i') |
| void | save_ER (int person=0, char person_type= 'i') |
| void | load_covar (int person, char person_type= 'i') |
| void | save_covar (int person, char person_type= 'i') |
| bool | get_portf_from_db (int id) |
| string | get_description () |
| void | set_mu (float(*AssetClass_mu)) |
| void | set_sigma (float(*AssetClass_varCov)) |
Public Attributes | |
| std::map< int, aGOAL > | goalZ |
| map containing all goals More... | |
| int | investor_id |
| string | user_name |
| string | first_name |
| string | last_name |
| string | password |
| string | currency |
| the default currency for that customer More... | |
| struct tm | birth_date |
| float | simulate_till_age |
| float * | assetClass_covar = new float[(NBR_ASSET_CLASSES + 1) * (NBR_ASSET_CLASSES + 1)] |
| float | assetClass_mu [(NBR_ASSET_CLASSES+1)] |
| note: index 0 not used More... | |
| std::map< int, string > | assetClass_name |
| note: index 0 not used More... | |
| std::map< int, float > | ER |
| std::map< int, std::map< int, float > > | covar |
| int | portfolio_id |
| string | description |
| float | weights [NBR_ASSET_CLASSES] |
| the weights of the asset classes (ordered as the asset classes) More... | |
| float | pMu |
| the MONTHLY return More... | |
| float | pLogR |
| the MONTHLY log-return More... | |
| float | pSigma |
| the MONTHLY volatility More... | |
Protected Member Functions | |
| void | set_followup_color_prae (float Vlow, float Vmed, float Vhigh, int g) |
| void | set_followup_color_post (float V, int g) |
| int | age2monthNbr (float theAge) |
| string | dateStr2Age (string the_date) |
| bool | save () |
| int | get_from_db (string investorID, string password) |
| bool | add_to_db () |
| bool | exists (int iid) |
| void | load_preferences () |
| sets the experience, knowledge and desirability vectors More... | |
| bool | save_preferences () |
| sets the experience, knowledge and desirability vectors More... | |
| void | set_max_exposure () |
| sets the max_exposure vector based on the experience, knowledge and desirability More... | |
| bool | set_scale (string scale_type, int ac, int val) |
| void | reload_ER (int person, char person_type= 'i') |
| TODO: the ER and assetClass_mu as well as the covar and assetClass_covar are redundant ==> eliminate the C-style assetClass_*. More... | |
| void | reload_covar (int person, char what2do, char person_type= 'i') |
Protected Attributes | |
| std::map< int, portfolio > | portfolios |
| the standard portfolios More... | |
| std::map< int, int > | experience |
| std::map< int, int > | knowledge |
| std::map< int, int > | desirability |
| std::map< int, float > | max_exposure |
| the maximum exposure per asset class More... | |
Private Member Functions | |
| void | set_assets () |
| add the assets to means[1] More... | |
| void | set_cfs () |
| void | set_goals () |
| void | set_means_goal (int g) |
| set the cash flows that are implied by the goal (eg. regular income from portfolio) More... | |
| void | expand_cf (float amount, string freq="M", string fromStr="", string tillStr="", int goal_nbr=0) |
| void | set_portfolios () |
| sets the portfolios More... | |
| float | get_optimal_portfolio (int g) |
| finds the portfolio with minimal investment More... | |
| float | calc_alpha (int priority, int monthNbr) |
| estimates $$ More... | |
| void | set_priorityLimits () |
| sets priorityMax and priorityMin More... | |
| float | goal_seek_means (int g, int p) |
| finds the minimal means needed (first free, then remaining, etc); sets tmp_means and calls the next function More... | |
| void | goal_seek_tmp_means (float *perc, int g, int p) |
| finds the minimal percentage needed of tmp_means More... | |
| float | calc_risk (int g, int p) |
| calculate the risk More... | |
| float | calc_V_high (int g, int p=0) |
| calculates the 1-alpha quantile portfolio for the goal alpha at realization_monthNbr More... | |
| void | set_goal_color (int g, float opt_perc) |
| allocates a color to each goal after the benchmark is found More... | |
| void | set_goal_remarks (int g) |
| adds remarks about the benchmark afther the benchmark is found More... | |
| void | allocate_to_unallocated_goal (int unallocated_goal_nbr) |
| if necessary create an unallocated goal and put the means_left there More... | |
| int | get_portfolio_safest () |
| returns the portfolio id of the safest acceptable portfolio More... | |
| int | get_portfolio_riskiest () |
| returns the portfolio id of the riskiest acceptable portfolio More... | |
| bool | set_unallocated_goal () |
Private Attributes | |
| std::map< int, float > | means |
| sum of cash flows and assets per month (not to be changed) More... | |
| std::map< int, float > | means_left |
| the percentage left to be invested of each cash-flow (carried over to next goal) More... | |
| std::map< int, float > | means_used |
| the means already used for THIS particular goal More... | |
| std::map< int, float > | means_block |
| next block of means to be used for a certain percentage More... | |
| std::map< int, float > | means_tmp |
| copy of block for goal-seek More... | |
| int | nbr_portfolios |
| the number of standard portfolios More... | |
| int | nbr_goals |
| the total number of goals More... | |
| int | nbr_assets = 0 |
| the total number of assets More... | |
| int | nbr_cfs |
| the total number of cash flows More... | |
| std::map< int, bool > | portfolio_suitable |
| int | priorityMax |
| int | priorityMin |
class investment_problem
copyright: (c) Philippe De Brouwer 2014
last modification: 2014-08-25
This class is the cornerstone of this software. This class solves the investment problem. The key attribute to access this class is the function solve(), that can be called once an invester is loaded and he/she has stated goals and reported assets and savings capacity.
Definition at line 15 of file investment_problem.class.cpp.
| investment_problem::investment_problem | ( | int | investor | ) |
Constructor.
CONSTRUCTOR : investment_problem
initalize assets, cash flows and goals ==> all but the goals are converted to the base currency for the customer.
initialize the market parameters
some testing
Definition at line 85 of file investment_problem.class.cpp.
|
protectedinherited |
add_to_db
does not check data any more, simply tries to push it to the DB only returns 0 if the userID already exists.
Definition at line 313 of file investor.class.cpp.
|
inlineinherited |
returns the age of a customer in years (with decimal part)
Definition at line 108 of file investor.class.cpp.
|
inlineprotectedinherited |
age2monthNbr
returns the month number for a given age note that this is negative for ages younger than the actual age.
Definition at line 200 of file investor.class.cpp.
|
private |
if necessary create an unallocated goal and put the means_left there
allocate_to_unallocated_goal
if necessary create one goal of type "unallocated" and allocate all remaining resources to that goal
Definition at line 604 of file investment_problem.class.cpp.
|
inlineprivate |
estimates $$
calc_alpha estimates $$ based on the priority rank as into
Definition at line 318 of file investment_problem.class.cpp.
|
private |
calculate the risk
calc_risk
calculates the risk (Expected Shortfall)
< the alpha'th quantile of the portfolio
< expected value of the portfolio
< the cash flows for a month (= means_used[m] + means_tmp[m] - goalZ[g].means_goal[m];)
< the weighted average standard deviation of the portfolio
< a reweight of the month number to account for large cash flows
| g | the number of the goal |
| p | the number of the portfolio |
Definition at line 809 of file investment_problem.class.cpp.
|
private |
calculates the 1-alpha quantile portfolio for the goal alpha at realization_monthNbr
calc_V_high
calculates the 1-alpha quantile (for the highest limit of alpha that is plotted) at goal expiration.
Definition at line 1260 of file investment_problem.class.cpp.
|
inlineprotectedinherited |
dateStr2Age
Definition at line 209 of file investor.class.cpp.
|
protectedinherited |
exists
checks if a given investor-id really exists
Definition at line 343 of file investor.class.cpp.
|
private |
expand_CF
the string from and till are in the format YYYY-MM-DD
Definition at line 155 of file investment_problem.class.cpp.
|
inherited |
returns the label of the portfolio
Definition at line 86 of file portfolio.class.cpp.
|
protectedinherited |
get_from_db returns the investor_id if successful (otherwise 0)
Definition at line 249 of file investor.class.cpp.
|
inherited |
overloading << operator overload the << operator to output the goal in a readable format get_full_name returns the full name of an investor
Definition at line 103 of file investor.class.cpp.
| int investment_problem::get_max_month_for_lower_goals | ( | int | g | ) |
returns the maximum term of all the other LOWER ranking goals. The higher ranking goals already have allocated all the means that they require, so we can disregard them here.
goal_type = 0 is the unallocated goal type, so this goal should not be taken into account here.
Definition at line 945 of file investment_problem.class.cpp.
| int investment_problem::get_nbr_goals | ( | ) |
returns the number of goals
Definition at line 936 of file investment_problem.class.cpp.
|
private |
finds the portfolio with minimal investment
get_optimal_portfolio
finds the optimal portfolio by finding that one that needs the least resources to satisfy the investment problem and adapts means_left accordingly
calculate for each portfolio how much means are used:
find the optimal portfolio
< NOTE: the consequence of the = sign is that this will select the last portfolio if the goal is not attainable!! (eg. the 100% equity portfolio)
Definition at line 677 of file investment_problem.class.cpp.
|
inherited |
load the definitions from the database
note: we have to create a second instance of the sql connection as this is called while the object db is in use!
Definition at line 32 of file portfolio.class.cpp.
|
private |
returns the portfolio id of the riskiest acceptable portfolio
get_portfolio_riskiest
Definition at line 1363 of file investment_problem.class.cpp.
|
private |
returns the portfolio id of the safest acceptable portfolio
get_portfolio_safest
Definition at line 1345 of file investment_problem.class.cpp.
|
private |
finds the minimal means needed (first free, then remaining, etc); sets tmp_means and calls the next function
goal_seek_means
returns the percentage of the given block of this->means_block that is needed to satisfy the given goal and the given portfolio. One should seek to get all these percentages and then find the lowest one (that will then indicate which portfolio to use)
NOTE: it leaves means_block untouched
try if 0% works (if goal is in the past, etc.)
try if 100% is sufficient, if yes iterate, if not return 100%
if we're still here, then it is possible and we goal-seek the percentage
TODO: FOR INCOME FROM/TO WE SHOULD FIRST TRY IF ONE CAN SAVE ONLY BEFORE THE START_DATE
| g | the goal to be satisfied |
| p | the portfolio to be used |
Definition at line 745 of file investment_problem.class.cpp.
|
inlineprivate |
finds the minimal percentage needed of tmp_means
goal_seek_tmp_means
this if statement could be omited but it should save time for the asap goals
Definition at line 779 of file investment_problem.class.cpp.
| void investment_problem::javaGraph | ( | int | g, |
| string | xtra_var = "", |
||
| string | xtra_label = "", |
||
| int | followup_mnth = 0 |
||
| ) |
javaGraph
plots the overview-graph for the given goal
xtav_Var and xtra_label add a series of data that is delivered in text format xtra_var = [45,2000], [45.5,2200] xtra_label = "history" followup_mnth = 0 for feedback and simulation screen, and for the follow up screen it is the number of months we look into the future.
Definition at line 1089 of file investment_problem.class.cpp.
|
inherited |
load_covar
< note: person_type = 'i' for persons (later to provide for 'a' advisor, organization, etc.)
< TODO eliminate this
if we did not find a personalized expectation for each asset class, then we load the default values
< TODO eliminate this
Definition at line 135 of file market.class.cpp.
|
inherited |
load_ER
< note: person_type = 'i' for persons (later to provide for 'a' advisor, organization, etc.)
Definition at line 61 of file market.class.cpp.
|
inherited |
returns the investor_id if successful (otherwise 0) NOTE for user interaction use get_from_db(uid, password) for password verification!!
Definition at line 134 of file investor.class.cpp.
|
protectedinherited |
sets the experience, knowledge and desirability vectors
set_preferences
Definition at line 383 of file investor.class.cpp.
|
inlineinherited |
months2simulate
Definition at line 124 of file investor.class.cpp.
| void investment_problem::parse_javaGraph | ( | int | g, |
| string | xtra_var = "", |
||
| string | xtra_label = "" |
||
| ) |
plots the chartOverview
parse_javaGraph
parses the line plot of the three scenarios and the goal to the output (webbrowser). It parses as well the
Definition at line 1103 of file investment_problem.class.cpp.
| void investment_problem::prepare_javaVars_colors | ( | int | g, |
| int | followup_mnth | ||
| ) |
prepare_javaVars_colors
followup_mnth is used as the startmonth for the followUp-Screen (in all other graphs it will be zero – its default)
exp = expected value med = median low = alpha quantile high = 1- alpha quantile
< the weighted average of the number of months that investments are in portfolio
TODO in the function below use another rate for NEGATIVE amounts, to mymic lending!
parse_javaGraph(g, s1, s2, s3, s4, xtra_var, xtra_label);
< place al the variables
Definition at line 970 of file investment_problem.class.cpp.
|
protectedinherited |
reload_vol
the situation here is more complex as the user expect that only the volatilities will be reset to the default values and not the correlations ...
what2do = [v|c|b] as in [vol | corr | both]
< both
< volatilities
< correlations
Definition at line 281 of file market.class.cpp.
|
protectedinherited |
TODO: the ER and assetClass_mu as well as the covar and assetClass_covar are redundant ==> eliminate the C-style assetClass_*.
set_mu
the expect value for all asset classes set_covar
the expect value for all assets reload_ER
note: person_type = 'i' for persons (later to provide for 'a' advisor, organization, etc.)
this function simply deletes the personalized expected returns. This is sufficient because later we check if they exists and only then load them (see function load_ER().
Definition at line 247 of file market.class.cpp.
|
protectedinherited |
save
Definition at line 220 of file investor.class.cpp.
|
inherited |
save_covar
Definition at line 172 of file market.class.cpp.
|
inherited |
save_ER
Definition at line 109 of file market.class.cpp.
|
protectedinherited |
sets the experience, knowledge and desirability vectors
Definition at line 416 of file investor.class.cpp.
|
private |
add the assets to means[1]
set_assets
puts the value of the today's savings into means[1] (all converted to the base currency of the investor)
Definition at line 122 of file investment_problem.class.cpp.
|
private |
set_cfs
load, expand and sum the expansion of all cash flows into the variable means[] (all converted to the base currency of the investor)
Definition at line 202 of file investment_problem.class.cpp.
|
inlineprotected |
set_followup_color_post sets the color of the goal in case the simulation is LONGER than the realization date of the goal
Definition at line 1246 of file investment_problem.class.cpp.
|
inlineprotected |
set_followup_color_prae
sets the color of the goal in case the simulations ends PRIOR to the realization date of the goal
Definition at line 1234 of file investment_problem.class.cpp.
|
private |
allocates a color to each goal after the benchmark is found
set_color_info()
set the appropriate color and remarks
Definition at line 546 of file investment_problem.class.cpp.
|
private |
adds remarks about the benchmark afther the benchmark is found
set_goal_remarks
Definition at line 588 of file investment_problem.class.cpp.
|
private |
loads all goals into this->goalZ[]
the realization_monthNbr and target_amount have to be set in function of the goal_type
calculate the means that are implied by the goal (eg as income "from/till"
and means that are allocated to this goal)
if someone has changed his/her age this has to be corrected for the means[m] vectors not to run out of index
Definition at line 225 of file investment_problem.class.cpp.
|
protectedinherited |
sets the max_exposure vector based on the experience, knowledge and desirability
get_max_exposure
sets the map max_exposure in this object
Definition at line 363 of file investor.class.cpp.
|
private |
set the cash flows that are implied by the goal (eg. regular income from portfolio)
set_goalZ[g].means_goal(int g)
only to be used for goals of type "income from/to"
creates the cash flow related to the goal and puts it into goalZ[g].means_goal
add_to_means is set to false –> the amount will be added to goalZ[g].means_goal
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx for all goal types we add the means that are allocated by the user to this goal xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx TODO
Definition at line 654 of file investment_problem.class.cpp.
|
inherited |
sets the expected return for the portfolio
Definition at line 94 of file portfolio.class.cpp.
|
private |
sets the portfolios
sets the map portfolios[]
also set the portfolio_suitable array
Definition at line 341 of file investment_problem.class.cpp.
|
private |
sets priorityMax and priorityMin
set_priorityLimits
sets the minimum and maximum of the ranking used by a given investor and stores them in this->priorityMax and priorityMin
Definition at line 300 of file investment_problem.class.cpp.
|
protectedinherited |
set_scale
Definition at line 402 of file investor.class.cpp.
|
inherited |
sets the standard deviation for the portfolio: this->sigma
Definition at line 112 of file portfolio.class.cpp.
|
private |
set_unallocated_goal
finds if for the given investor an unallocated goal exists, if not creates it, loads it and allocates the content to the pointer
create a new one
Definition at line 1285 of file investment_problem.class.cpp.
| void investment_problem::solve | ( | ) |
allocates means (with a benchmark) to goals
solve is the main attribute to be used by other classes
a cls_currency object that will facilitate currency conversions
note: set_assets, set_cfs,set_goals,set_mu are done in the constructor
< initialize means_left for g=1 (all in investor.currency)
< initialize means_left for g=1 (all in investor.currency)
< do nothing right now for unallocated goals, so take the next goal (for loop)
try the free means (not used by other –lower ranking– goals)
< initialize
and means that are allocated to this goal):
for the asap-goals we take the first cash flows first
for all other goal types we take the last possible
if the free means are not sufficient, try all the previous also
block the resources for this goal
set the benchmark
set comments and colors:
add the risk info
put all the remaining means into the unallocated goal
Definition at line 396 of file investment_problem.class.cpp.
|
inherited |
Definition at line 16 of file market.class.cpp.
|
inherited |
note: index 0 not used
Definition at line 17 of file market.class.cpp.
|
inherited |
note: index 0 not used
Definition at line 18 of file market.class.cpp.
|
inherited |
Definition at line 20 of file investor.class.cpp.
|
inherited |
Definition at line 26 of file market.class.cpp.
|
inherited |
the default currency for that customer
Definition at line 19 of file investor.class.cpp.
|
inherited |
Definition at line 15 of file portfolio.class.cpp.
|
protectedinherited |
Definition at line 41 of file investor.class.cpp.
|
inherited |
Definition at line 25 of file market.class.cpp.
|
protectedinherited |
Definition at line 39 of file investor.class.cpp.
|
inherited |
Definition at line 16 of file investor.class.cpp.
| std::map<int, aGOAL> investment_problem::goalZ |
map containing all goals
Definition at line 22 of file investment_problem.class.cpp.
|
inherited |
Definition at line 14 of file investor.class.cpp.
|
protectedinherited |
Definition at line 40 of file investor.class.cpp.
|
inherited |
Definition at line 17 of file investor.class.cpp.
|
protectedinherited |
the maximum exposure per asset class
Definition at line 42 of file investor.class.cpp.
|
private |
sum of cash flows and assets per month (not to be changed)
Definition at line 35 of file investment_problem.class.cpp.
|
private |
next block of means to be used for a certain percentage
Definition at line 38 of file investment_problem.class.cpp.
|
private |
the percentage left to be invested of each cash-flow (carried over to next goal)
Definition at line 36 of file investment_problem.class.cpp.
|
private |
copy of block for goal-seek
Definition at line 39 of file investment_problem.class.cpp.
|
private |
the means already used for THIS particular goal
Definition at line 37 of file investment_problem.class.cpp.
|
private |
the total number of assets
Definition at line 44 of file investment_problem.class.cpp.
|
private |
the total number of cash flows
Definition at line 45 of file investment_problem.class.cpp.
|
private |
the total number of goals
Definition at line 43 of file investment_problem.class.cpp.
|
private |
the number of standard portfolios
Definition at line 41 of file investment_problem.class.cpp.
|
inherited |
Definition at line 18 of file investor.class.cpp.
|
inherited |
the MONTHLY log-return
Definition at line 25 of file portfolio.class.cpp.
|
inherited |
the MONTHLY return
Definition at line 24 of file portfolio.class.cpp.
|
inherited |
Definition at line 14 of file portfolio.class.cpp.
|
private |
Definition at line 67 of file investment_problem.class.cpp.
|
protected |
the standard portfolios
Definition at line 29 of file investment_problem.class.cpp.
|
private |
Definition at line 72 of file investment_problem.class.cpp.
|
private |
Definition at line 73 of file investment_problem.class.cpp.
|
inherited |
the MONTHLY volatility
Definition at line 26 of file portfolio.class.cpp.
|
inherited |
Definition at line 21 of file investor.class.cpp.
|
inherited |
Definition at line 15 of file investor.class.cpp.
|
inherited |
the weights of the asset classes (ordered as the asset classes)
Definition at line 17 of file portfolio.class.cpp.