ConsPrefShockModel#

Extensions to ConsIndShockModel concerning models with preference shocks. It currently only two models:

  1. An extension of ConsIndShock, but with an iid lognormal multiplicative shock each period.

  2. A combination of (1) and ConsKinkedR, demonstrating how to construct a new model by inheriting from multiple classes.

class HARK.ConsumptionSaving.ConsPrefShockModel.PrefShockConsumerType(**kwds)#

Bases: IndShockConsumerType

A consumer type based on IndShockConsumerType, with multiplicative shocks to utility each period.

\[\begin{split}\newcommand{\CRRA}{\rho} \newcommand{\DiePrb}{\mathsf{D}} \newcommand{\PermGroFac}{\Gamma} \newcommand{\Rfree}{\mathsf{R}} \newcommand{\DiscFac}{\beta} \begin{align*} v_t(m_t,\eta_t) &=\max_{c_t} \eta_{t} u(c_t) + \DiscFac (1 - \DiePrb_{t+1}) \mathbb{E}_{t} \left[ (\PermGroFac_{t+1} \psi_{t+1})^{1-\CRRA} v_{t+1}(m_{t+1},\eta_{t+1}) \right], \\ & \text{s.t.} \\ a_t &= m_t - c_t, \\ a_t &\geq \underline{a}, \\ m_{t+1} &= a_t \Rfree_{t+1}/(\PermGroFac_{t+1} \psi_{t+1}) + \theta_{t+1}, \\ (\psi_{t+1},\theta_{t+1},\eta_{t+1}) &\sim F_{t+1}, \\ \mathbb{E}[\psi]=\mathbb{E}[\theta] &= 1, \\ u(c) &= \frac{c^{1-\CRRA}}{1-\CRRA} \\ \end{align*}\end{split}\]
Constructors:
Solving Parameters:
  • cycles (int) – 0 specifies an infinite horizon model, 1 specifies a finite model.

  • T_cycle (int) – Number of periods in the cycle for this agent type.

  • CRRA (float, \(\rho\)) – Coefficient of Relative Risk Aversion.

  • Rfree (float or list[float], time varying, \(\mathsf{R}\)) – Risk Free interest rate. Pass a list of floats to make Rfree time varying.

  • DiscFac (float, \(\beta\)) – Intertemporal discount factor.

  • LivPrb (list[float], time varying, \(1-\mathsf{D}\)) – Survival probability after each period.

  • PermGroFac (list[float], time varying, \(\Gamma\)) – Permanent income growth factor.

  • BoroCnstArt (float, \(\underline{a}\)) – The minimum Asset/Perminant Income ratio, None to ignore.

  • vFuncBool (bool) – Whether to calculate the value function during solution.

  • CubicBool (bool) – Whether to use cubic spline interpoliation.

Simulation Parameters:
  • AgentCount (int) – Number of agents of this kind that are created during simulations.

  • T_age (int) – Age after which to automatically kill agents, None to ignore.

  • T_sim (int, required for simulation) – Number of periods to simulate.

  • track_vars (list[strings]) – List of variables that should be tracked when running the simulation. For this agent, the options are ‘PermShk’, ‘PrefShk’, ‘TranShk’, ‘aLvl’, ‘aNrm’, ‘bNrm’, ‘cNrm’, ‘mNrm’, ‘pLvl’, and ‘who_dies’.

    PermShk is the agent’s permanent income shock

    PrefShk is the agent’s preference shock

    TranShk is the agent’s transitory income shock

    aLvl is the nominal asset level

    aNrm is the normalized assets

    bNrm is the normalized resources without this period’s labor income

    cNrm is the normalized consumption

    mNrm is the normalized market resources

    pLvl is the permanent income level

    who_dies is the array of which agents died

  • aNrmInitMean (float) – Mean of Log initial Normalized Assets.

  • aNrmInitStd (float) – Std of Log initial Normalized Assets.

  • pLvlInitMean (float) – Mean of Log initial permanent income.

  • pLvlInitStd (float) – Std of Log initial permanent income.

  • PermGroFacAgg (float) – Aggregate permanent income growth factor (The portion of PermGroFac attributable to aggregate productivity growth).

  • PerfMITShk (boolean) – Do Perfect Foresight MIT Shock (Forces Newborns to follow solution path of the agent they replaced if True).

  • NewbornTransShk (boolean) – Whether Newborns have transitory shock.

Attributes:
  • solution (list[Consumer solution object]) – Created by the solve() method. Finite horizon models create a list with T_cycle+1 elements, for each period in the solution. Infinite horizon solutions return a list with T_cycle elements for each period in the cycle.

    For this model, cFunc is defined over normalized market resources and \(\eta\), cNrm = cFunc(mNrm, \(\eta\)).

    Visit HARK.ConsumptionSaving.ConsIndShockModel.ConsumerSolution for more information about the solution.

  • history (Dict[Array]) – Created by running the simulate() method. Contains the variables in track_vars. Each item in the dictionary is an array with the shape (T_sim,AgentCount). Visit HARK.core.AgentType.simulate for more information.

IncShkDstn_defaults = {'IncUnemp': 0.3, 'IncUnempRet': 0.0, 'PermShkCount': 7, 'PermShkStd': [0.1], 'T_retire': 0, 'TranShkCount': 7, 'TranShkStd': [0.1], 'UnempPrb': 0.05, 'UnempPrbRet': 0.005}#
aXtraGrid_defaults = {'aXtraCount': 48, 'aXtraExtra': None, 'aXtraMax': 20, 'aXtraMin': 0.001, 'aXtraNestFac': 3}#
PrefShkDstn_defaults = {'PrefShkCount': 12, 'PrefShkStd': [0.3], 'PrefShk_tail_N': 4}#
solving_defaults = {'BoroCnstArt': 0.0, 'CRRA': 2.0, 'CubicBool': False, 'DiscFac': 0.96, 'LivPrb': [0.98], 'PermGroFac': [1.01], 'Rfree': 1.03, 'T_cycle': 1, 'constructors': {'IncShkDstn': <function construct_lognormal_income_process_unemployment>, 'PermShkDstn': <function get_PermShkDstn_from_IncShkDstn>, 'PrefShkDstn': <function make_lognormal_PrefShkDstn>, 'TranShkDstn': <function get_TranShkDstn_from_IncShkDstn>, 'aXtraGrid': <function make_assets_grid>, 'solution_terminal': <function make_basic_CRRA_solution_terminal>}, 'cycles': 1, 'vFuncBool': False}#
simulation_defaults = {'AgentCount': 10000, 'NewbornTransShk': False, 'PerfMITShk': False, 'PermGroFacAgg': 1.0, 'T_age': None, 'aNrmInitMean': 0.0, 'aNrmInitStd': 1.0, 'neutral_measure': False, 'pLvlInitMean': 0.0, 'pLvlInitStd': 0.0}#
shock_vars_ = ['PermShk', 'TranShk', 'PrefShk']#
pre_solve()#

Method that is run automatically just before solution by backward iteration. Solves the (trivial) terminal period and does a quick check on the borrowing constraint and MaxKinks attribute (only relevant in constrained, infinite horizon problems).

update()#

Updates the assets grid, income process, terminal period solution, and preference shock process. A very slight extension of IndShockConsumerType.update() for the preference shock model.

Parameters:

None

Return type:

None

update_pref_shock_process()#

Make a discrete preference shock structure for each period in the cycle for this agent type, storing them as attributes of self for use in the solution (and other methods).

Parameters:

none

Return type:

none

reset_rng()#

Reset the RNG behavior of this type. This method is called automatically by initialize_sim(), ensuring that each simulation run uses the same sequence of random shocks; this is necessary for structural estimation to work. This method extends IndShockConsumerType.reset_rng() to also reset elements of PrefShkDstn.

Parameters:

None

Return type:

None

get_shocks()#

Gets permanent and transitory income shocks for this period as well as preference shocks.

Parameters:

None

Return type:

None

get_controls()#

Calculates consumption for each consumer of this type using the consumption functions.

Parameters:

None

Return type:

None

calc_bounding_values()#

Calculate human wealth plus minimum and maximum MPC in an infinite horizon model with only one period repeated indefinitely. Store results as attributes of self. Human wealth is the present discounted value of expected future income after receiving income this period, ignoring mort- ality. The maximum MPC is the limit of the MPC as m –> mNrmMin. The minimum MPC is the limit of the MPC as m –> infty.

NOT YET IMPLEMENTED FOR THIS CLASS

Parameters:

None

Return type:

None

make_euler_error_func(mMax=100, approx_inc_dstn=True)#

Creates a “normalized Euler error” function for this instance, mapping from market resources to “consumption error per dollar of consumption.” Stores result in attribute eulerErrorFunc as an interpolated function. Has option to use approximate income distribution stored in self.IncShkDstn or to use a (temporary) very dense approximation.

NOT YET IMPLEMENTED FOR THIS CLASS

Parameters:
  • mMax (float) – Maximum normalized market resources for the Euler error function.

  • approx_inc_dstn (Boolean) – Indicator for whether to use the approximate discrete income distri- bution stored in self.IncShkDstn[0], or to use a very accurate discrete approximation instead. When True, uses approximation in IncShkDstn; when False, makes and uses a very dense approximation.

Return type:

None

Notes

This method is not used by any other code in the library. Rather, it is here for expository and benchmarking purposes.

class HARK.ConsumptionSaving.ConsPrefShockModel.KinkyPrefConsumerType(**kwds)#

Bases: PrefShockConsumerType, KinkedRconsumerType

A consumer type based on PrefShockConsumerType, with different interest rates for saving (\(\mathsf{R}_{save}\)) and borrowing (\(\mathsf{R}_{boro}\)).

Solver for this class is currently only compatible with linear spline interpolation.

\[\begin{split}\newcommand{\CRRA}{\rho} \newcommand{\DiePrb}{\mathsf{D}} \newcommand{\PermGroFac}{\Gamma} \newcommand{\Rfree}{\mathsf{R}} \newcommand{\DiscFac}{\beta} \begin{align*} v_t(m_t,\eta_t) &= \max_{c_t} \eta_{t} u(c_t) + \DiscFac (1-\DiePrb_{t+1}) \mathbb{E}_{t} \left[(\PermGroFac_{t+1}\psi_{t+1})^{1-\CRRA} v_{t+1}(m_{t+1},\eta_{t+1}) \right], \\ a_t &= m_t - c_t, \\ a_t &\geq \underline{a}, \\ m_{t+1} &= \Rfree_t/(\PermGroFac_{t+1} \psi_{t+1}) a_t + \theta_{t+1}, \\ \Rfree_t &= \begin{cases} \Rfree_{boro} & \text{if } a_t < 0\\ \Rfree_{save} & \text{if } a_t \geq 0, \end{cases}\\ \Rfree_{boro} &> \Rfree_{save}, \\ (\psi_{t+1},\theta_{t+1},\eta_{t+1}) &\sim F_{t+1}, \\ \mathbb{E}[\psi]=\mathbb{E}[\theta] &= 1. \\ u(c) &= \frac{c^{1-\CRRA}}{1-\CRRA} \\ \end{align*}\end{split}\]
Constructors:
Solving Parameters:
  • cycles (int) – 0 specifies an infinite horizon model, 1 specifies a finite model.

  • T_cycle (int) – Number of periods in the cycle for this agent type.

  • CRRA (float, \(\rho\)) – Coefficient of Relative Risk Aversion.

  • Rfree (float or list[float], time varying, \(\mathsf{R}\)) – Risk Free interest rate. Pass a list of floats to make Rfree time varying.

  • Rboro (float, \(\mathsf{R}_{boro}\)) – Risk Free interest rate when assets are negative.

  • Rsave (float, \(\mathsf{R}_{save}\)) – Risk Free interest rate when assets are positive.

  • DiscFac (float, \(\beta\)) – Intertemporal discount factor.

  • LivPrb (list[float], time varying, \(1-\mathsf{D}\)) – Survival probability after each period.

  • PermGroFac (list[float], time varying, \(\Gamma\)) – Permanent income growth factor.

  • BoroCnstArt (float, \(\underline{a}\)) – The minimum Asset/Perminant Income ratio, None to ignore.

  • vFuncBool (bool) – Whether to calculate the value function during solution.

  • CubicBool (bool) – Whether to use cubic spline interpoliation.

Simulation Parameters:
  • AgentCount (int) – Number of agents of this kind that are created during simulations.

  • T_age (int) – Age after which to automatically kill agents, None to ignore.

  • T_sim (int, required for simulation) – Number of periods to simulate.

  • track_vars (list[strings]) – List of variables that should be tracked when running the simulation. For this agent, the options are ‘PermShk’, ‘PrefShk’, ‘TranShk’, ‘aLvl’, ‘aNrm’, ‘bNrm’, ‘cNrm’, ‘mNrm’, ‘pLvl’, and ‘who_dies’.

    PermShk is the agent’s permanent income shock

    PrefShk is the agent’s preference shock

    TranShk is the agent’s transitory income shock

    aLvl is the nominal asset level

    aNrm is the normalized assets

    bNrm is the normalized resources without this period’s labor income

    cNrm is the normalized consumption

    mNrm is the normalized market resources

    pLvl is the permanent income level

    who_dies is the array of which agents died

  • aNrmInitMean (float) – Mean of Log initial Normalized Assets.

  • aNrmInitStd (float) – Std of Log initial Normalized Assets.

  • pLvlInitMean (float) – Mean of Log initial permanent income.

  • pLvlInitStd (float) – Std of Log initial permanent income.

  • PermGroFacAgg (float) – Aggregate permanent income growth factor (The portion of PermGroFac attributable to aggregate productivity growth).

  • PerfMITShk (boolean) – Do Perfect Foresight MIT Shock (Forces Newborns to follow solution path of the agent they replaced if True).

  • NewbornTransShk (boolean) – Whether Newborns have transitory shock.

Attributes:
  • solution (list[Consumer solution object]) – Created by the solve() method. Finite horizon models create a list with T_cycle+1 elements, for each period in the solution. Infinite horizon solutions return a list with T_cycle elements for each period in the cycle.

    For this model, cFunc is defined over normalized market resources and \(\eta\), cNrm = cFunc(mNrm, \(\eta\)).

    Visit HARK.ConsumptionSaving.ConsIndShockModel.ConsumerSolution for more information about the solution.

  • history (Dict[Array]) – Created by running the simulate() method. Contains the variables in track_vars. Each item in the dictionary is an array with the shape (T_sim,AgentCount). Visit HARK.core.AgentType.simulate for more information.

IncShkDstn_defaults = {'IncUnemp': 0.3, 'IncUnempRet': 0.0, 'PermShkCount': 7, 'PermShkStd': [0.1], 'T_retire': 0, 'TranShkCount': 7, 'TranShkStd': [0.1], 'UnempPrb': 0.05, 'UnempPrbRet': 0.005}#
aXtraGrid_defaults = {'aXtraCount': 48, 'aXtraExtra': None, 'aXtraMax': 20, 'aXtraMin': 0.001, 'aXtraNestFac': 3}#
PrefShkDstn_defaults = {'PrefShkCount': 12, 'PrefShkStd': [0.3], 'PrefShk_tail_N': 4}#
solving_defaults = {'BoroCnstArt': None, 'CRRA': 2.0, 'CubicBool': False, 'DiscFac': 0.96, 'LivPrb': [0.98], 'PermGroFac': [1.01], 'Rboro': 1.2, 'Rfree': 1.03, 'Rsave': 1.02, 'T_cycle': 1, 'constructors': {'IncShkDstn': <function construct_lognormal_income_process_unemployment>, 'PermShkDstn': <function get_PermShkDstn_from_IncShkDstn>, 'PrefShkDstn': <function make_lognormal_PrefShkDstn>, 'TranShkDstn': <function get_TranShkDstn_from_IncShkDstn>, 'aXtraGrid': <function make_assets_grid>, 'solution_terminal': <function make_basic_CRRA_solution_terminal>}, 'cycles': 1, 'vFuncBool': False}#
simulation_defaults = {'AgentCount': 10000, 'NewbornTransShk': False, 'PerfMITShk': False, 'PermGroFacAgg': 1.0, 'T_age': None, 'aNrmInitMean': 0.0, 'aNrmInitStd': 1.0, 'neutral_measure': False, 'pLvlInitMean': 0.0, 'pLvlInitStd': 0.0}#
pre_solve()#

Method that is run automatically just before solution by backward iteration. Solves the (trivial) terminal period and does a quick check on the borrowing constraint and MaxKinks attribute (only relevant in constrained, infinite horizon problems).

get_Rfree()#

Returns an array of size self.AgentCount with self.Rfree in every entry.

Parameters:

None

Returns:

RfreeNow – Array of size self.AgentCount with risk free interest rate for each agent.

Return type:

np.array

HARK.ConsumptionSaving.ConsPrefShockModel.make_lognormal_PrefShkDstn(T_cycle, PrefShkStd, PrefShkCount, RNG, PrefShk_tail_N=0, PrefShk_tail_order=2.718281828459045, PrefShk_tail_bound=[0.02, 0.98])#

Make a discretized mean one lognormal preference shock distribution for each period of the agent’s problem.

\[\eta_t \sim \mathcal{N}(-\textbf{PrefShkStd}_{t}^{2}/2,\textbf{PrefShkStd}_{t}^2)\]
Parameters:
  • T_cycle (int) – Number of non-terminal periods in the agent’s cycle.

  • PrefShkStd ([float]) – Standard deviation of log preference shocks in each period.

  • PrefShkCount (int) – Number of equiprobable preference shock nodes in the “body” of the distribution.

  • RNG (RandomState) – The AgentType’s internal random number generator.

  • PrefShk_tail_N (int) – Number of shock nodes in each “tail” of the distribution (optional).

  • PrefShk_tail_order (float) – Scaling factor for tail nodes (optional).

  • PrefShk_tail_bound ([float,float]) – CDF bounds for tail nodes (optional).

Returns:

PrefShkDstn – List of discretized lognormal distributions for shocks.

Return type:

[DiscreteDistribution]