# ConsPortfolioModel¶

This file contains classes and functions for representing, solving, and simulating agents who must allocate their resources among consumption, saving in a risk-free asset (with a low return), and saving in a risky asset (with higher average return).

class HARK.ConsumptionSaving.ConsPortfolioModel.ConsPortfolioDiscreteSolver(solution_next, ShockDstn, IncShkDstn, RiskyDstn, LivPrb, DiscFac, CRRA, Rfree, PermGroFac, BoroCnstArt, aXtraGrid, ShareGrid, vFuncBool, AdjustPrb, DiscreteShareBool, ShareLimit, IndepDstnBool)

Define an object-oriented one period solver. Solve the one period problem for a portfolio-choice consumer. This solver is used when the income and risky return shocks are independent and the allowed optimal share is discrete over a finite set of points in ShareGrid.

make_ShareFuncAdj()

Construct the risky share function when the agent can adjust

optimize_share()

Optimization of Share on the discrete set ShareGrid

solve()

Solve the one period problem for a portfolio-choice consumer.

Returns: solution_now (PortfolioSolution) The solution to the single period consumption-saving with portfolio choice problem. Includes two consumption and risky share functions (one for when) the agent can adjust his portfolio share (Adj) and when he can’t (Fxd).
class HARK.ConsumptionSaving.ConsPortfolioModel.ConsPortfolioJointDistSolver(solution_next, ShockDstn, IncShkDstn, RiskyDstn, LivPrb, DiscFac, CRRA, Rfree, PermGroFac, BoroCnstArt, aXtraGrid, ShareGrid, vFuncBool, AdjustPrb, DiscreteShareBool, ShareLimit, IndepDstnBool)

Define an object-oriented one period solver. Solve the one period problem for a portfolio-choice consumer. This solver is used when the income and risky return shocks are not independent. The optimal share can be continuous or discrete.

calc_EndOfPrdvP()

Calculate end-of-period marginal value of assets and shares at each point in aNrm and ShareGrid. Does so by taking expectation of next period marginal values across income and risky return shocks.

m_nrm_next(shocks, a_nrm, r_port)

Calculate future realizations of market resources

make_EndOfPrdvFunc()

Construct the end-of-period value function for this period, storing it as an attribute of self for use by other methods.

prepare_to_calc_EndOfPrdvP()

Prepare to calculate end-of-period marginal values by creating an array of market resources that the agent could have next period, considering the grid of end-of-period assets and the distribution of shocks he might experience next period.

r_port(shocks, share)

Calculate future realizations of market resources

set_and_update_values()

Unpacks some of the inputs (and calculates simple objects based on them), storing the results in self for use by other methods.

solve()

Solve the one period problem for a portfolio-choice consumer.

Returns: solution_now (PortfolioSolution) The solution to the single period consumption-saving with portfolio choice problem. Includes two consumption and risky share functions (one for when) the agent can adjust his portfolio share (Adj) and when he can’t (Fxd).
class HARK.ConsumptionSaving.ConsPortfolioModel.ConsPortfolioSolver(solution_next, ShockDstn, IncShkDstn, RiskyDstn, LivPrb, DiscFac, CRRA, Rfree, PermGroFac, BoroCnstArt, aXtraGrid, ShareGrid, vFuncBool, AdjustPrb, DiscreteShareBool, ShareLimit, IndepDstnBool)

Define an object-oriented one period solver. Solve the one period problem for a portfolio-choice consumer. This solver is used when the income and risky return shocks are independent and the allowed optimal share is continuous.

Parameters: solution_next (PortfolioSolution) – Solution to next period’s problem. ShockDstn ([np.array]) – List with four arrays: discrete probabilities, permanent income shocks, transitory income shocks, and risky returns. This is only used if the input IndepDstnBool is False, indicating that income and return distributions can’t be assumed to be independent. IncShkDstn (distribution.Distribution) – Discrete distribution of permanent income shocks and transitory income shocks. This is only used if the input IndepDsntBool is True, indicating that income and return distributions are independent. RiskyDstn ([np.array]) – List with two arrays: discrete probabilities and risky asset returns. This is only used if the input IndepDstnBool is True, indicating that income and return distributions are independent. LivPrb (float) – Survival probability; likelihood of being alive at the beginning of the succeeding period. DiscFac (float) – Intertemporal discount factor for future utility. CRRA (float) – Coefficient of relative risk aversion. Rfree (float) – Risk free interest factor on end-of-period assets. PermGroFac (float) – Expected permanent income growth factor at the end of this period. BoroCnstArt (float or None) – Borrowing constraint for the minimum allowable assets to end the period with. In this model, it is required to be zero. aXtraGrid (np.array) – Array of “extra” end-of-period asset values– assets above the absolute minimum acceptable level. ShareGrid (np.array) – Array of risky portfolio shares on which to define the interpolation of the consumption function when Share is fixed. vFuncBool (boolean) – An indicator for whether the value function should be computed and included in the reported solution. AdjustPrb (float) – Probability that the agent will be able to update his portfolio share. DiscreteShareBool (bool) – Indicator for whether risky portfolio share should be optimized on the continuous [0,1] interval using the FOC (False), or instead only selected from the discrete set of values in ShareGrid (True). If True, then vFuncBool must also be True. ShareLimit (float) – Limiting lower bound of risky portfolio share as mNrm approaches infinity. IndepDstnBool (bool) – Indicator for whether the income and risky return distributions are in- dependent of each other, which can speed up the expectations step.
add_save_points()
add_vFunc()

Creates the value function for this period and adds it to the solution.

calc_EndOfPrdvP()

Calculate end-of-period marginal value of assets and shares at each point in aNrm and ShareGrid. Does so by taking expectation of next period marginal values across income and risky return shocks.

def_utility_funcs()

Define temporary functions for utility and its derivative and inverse

m_nrm_next(shocks, b_nrm_next)

Calculate future realizations of market resources

make_EndOfPrdvFunc()

Construct the end-of-period value function for this period, storing it as an attribute of self for use by other methods.

make_ShareFuncAdj()

Construct the risky share function when the agent can adjust

make_basic_solution()

Given end of period assets and end of period marginal values, construct the basic solution for this period.

make_porfolio_solution()
make_vFunc()

Creates the value functions for this period, defined over market resources m when agent can adjust his portfolio, and over market resources and fixed share when agent can not adjust his portfolio. self must have the attribute EndOfPrdvFunc in order to execute.

optimize_share()

Optimization of Share on continuous interval [0,1]

prepare_to_calc_EndOfPrdvP()

Prepare to calculate end-of-period marginal values by creating an array of market resources that the agent could have next period, considering the grid of end-of-period assets and the distribution of shocks he might experience next period.

prepare_to_solve()

Perform preparatory work.

set_and_update_values()

Unpacks some of the inputs (and calculates simple objects based on them), storing the results in self for use by other methods.

solve()

Solve the one period problem for a portfolio-choice consumer.

Returns: solution_now (PortfolioSolution) The solution to the single period consumption-saving with portfolio choice problem. Includes two consumption and risky share functions (one for when) the agent can adjust his portfolio share (Adj) and when he can’t (Fxd).
class HARK.ConsumptionSaving.ConsPortfolioModel.ConsSequentialPortfolioSolver(solution_next, ShockDstn, IncShkDstn, RiskyDstn, LivPrb, DiscFac, CRRA, Rfree, PermGroFac, BoroCnstArt, aXtraGrid, ShareGrid, vFuncBool, AdjustPrb, DiscreteShareBool, ShareLimit, IndepDstnBool)
add_SequentialShareFuncAdj(solution)

Construct the risky share function as a function of savings when the agent can adjust.

solve()

Solve the one period problem for a portfolio-choice consumer.

Returns: solution_now (PortfolioSolution) The solution to the single period consumption-saving with portfolio choice problem. Includes two consumption and risky share functions (one for when) the agent can adjust his portfolio share (Adj) and when he can’t (Fxd).
class HARK.ConsumptionSaving.ConsPortfolioModel.PortfolioConsumerType(verbose=False, quiet=False, **kwds)

Bases: HARK.ConsumptionSaving.ConsRiskyAssetModel.IndShockRiskyAssetConsumerType

A consumer type with a portfolio choice. This agent type has log-normal return factors. Their problem is defined by a coefficient of relative risk aversion, intertemporal discount factor, risk-free interest factor, and time sequences of permanent income growth rate, survival probability, and permanent and transitory income shock standard deviations (in logs). The agent may also invest in a risky asset, which has a higher average return than the risk-free asset. He might have age-varying beliefs about the risky-return; if he does, then “true” values of the risky asset’s return distribution must also be specified.

get_controls()

Calculates consumption cNrmNow and risky portfolio share ShareNow using the policy functions in the attribute solution. These are stored as attributes.

Parameters: None – None
initialize_sim()

Initialize the state of simulation attributes. Simply calls the same method for IndShockConsumerType, then sets the type of AdjustNow to bool.

Parameters: None – None
pre_solve()

A method that is run immediately before the model is solved, to check inputs or to prepare the terminal solution, perhaps.

Parameters: none – none
sim_birth(which_agents)

Create new agents to replace ones who have recently died; takes draws of initial aNrm and pLvl, as in ConsIndShockModel, then sets Share and Adjust to zero as initial values. :param which_agents: Boolean array of size AgentCount indicating which agents should be “born”. :type which_agents: np.array

Returns: None
time_inv_ = ['CRRA', 'DiscFac', 'BoroCnstArt', 'BoroCnstArt', 'vFuncBool', 'CubicBool', 'PortfolioBisect', 'AdjustPrb', 'DiscreteShareBool']
update()

Update the income process, the assets grid, and the terminal solution.

Parameters: None – None
update_solution_terminal()

Solves the terminal period of the portfolio choice problem. The solution is trivial, as usual: consume all market resources, and put nothing in the risky asset (because you have nothing anyway).

Parameters: None – None
class HARK.ConsumptionSaving.ConsPortfolioModel.PortfolioSolution(cFuncAdj=None, ShareFuncAdj=None, vFuncAdj=None, vPfuncAdj=None, cFuncFxd=None, ShareFuncFxd=None, vFuncFxd=None, dvdmFuncFxd=None, dvdsFuncFxd=None, aGrid=None, Share_adj=None, EndOfPrddvda_adj=None, ShareGrid=None, EndOfPrddvda_fxd=None, EndOfPrddvds_fxd=None, AdjPrb=None)

A class for representing the single period solution of the portfolio choice model.

distance_criteria = ['vPfuncAdj']
class HARK.ConsumptionSaving.ConsPortfolioModel.SequentialPortfolioConsumerType(verbose=False, quiet=False, **kwds)