ConsHabitModel#

This module has consumption-models with habit formation. Right now, it only has a single basic model with permanent and transitory income shocks, one risk-free asset, and a habit stock that evolves as a weighted average of current consumption and the prior habit stock.

HARK.ConsumptionSaving.ConsHabitModel.make_lognormal_habit_init_dstn(hLogInitMean, hLogInitStd, HabitInitCount, RNG)#

Construct a lognormal distribution for (normalized) initial habit stock of newborns, hNrm. This is the default constructor for HabitInitDstn.

Parameters:
  • hLogInitMean (float) – Mean of log habit stock for newborns.

  • hLogInitStd (float) – Stdev of log habit stock for newborns.

  • HabitInitCount (int) – Number of points in the discretization.

  • RNG (np.random.RandomState) – Agent’s internal RNG.

Returns:

HabitInitDstn – Discretized distribution of initial habit stock for newborns.

Return type:

DiscreteDistribution

class HARK.ConsumptionSaving.ConsHabitModel.HabitFormationInverter(CRRA, HabitRte, HabitWgt, ChiMax, ChiCount, ChiOrder, HabitMax, HabitCount, HabitOrder)#

Bases: object

A class for solving the first order conditions of a consumption-saving model with habit formation. In this notation, HabitRte is a parameter on the unit interval representing how fast the habit stock evolves; a value of zero means no habit dynamics and a value of one means that H_t = c_t, complete updating. HabitWgt is also on the unit interval and represents the exponent on the habit stock, which is used as a divisor on consumption in the utility function.

Instances of this class take two arguments when called as a function: end-of- period habit stock H and transformed end-of-period marginal value chi.

chi = (W_a(a,H) - lambda * W_H(a,H)) ** (-1/rho)

a = m - c H = lambda * c + (1-lambda) * h m’ = R a / psi + theta h’ = H / psi

Parameters:
  • CRRA (float) – Coefficient of relative risk aversion, rho.

  • HabitRte (float) – Rate of habit stock updating with new consumption, lambda. Must be greater than zero but less than one.

  • HabitWgt (float) – Weight of habit stock in preferences, alpha; exponent on habits as a divisor in utility function. Must be greater than zero but less than one.

  • ChiMax (float) – Largest value of “transformed marginal value” to consider in the grid. The minimum value is always zero. These chi values are “consumption-like”.

  • ChiCount (int) – Number of gridpoints in the “transformed marginal value” grid.

  • ChiOrder (float) – Strictly positive exponential order for the “transformed marginal value” grid.

  • HabitMax (float) – Largest value in the habit grid to consider; minimum is always zero.

  • HabitCount (int) – Number of gridpoints in the habit stock grid.

  • HabitOrder (float) – Strictly positive exponential order for the habit stock grid.

cFunc(H, chi)#
HARK.ConsumptionSaving.ConsHabitModel.make_habit_inverter(CRRA, HabitRte, HabitWgt, ChiMax, ChiCount, ChiOrder, HabitMax, HabitCount, HabitOrder)#
HARK.ConsumptionSaving.ConsHabitModel.make_habit_grid(HabitMin, HabitMax, HabitCount, HabitOrder)#
HARK.ConsumptionSaving.ConsHabitModel.make_dense_grids(HabitMin, HabitMax, HabitCount, HabitOrder, aXtraMin, aXtraMax, aXtraCount, aXtraNestFac, aXtraExtra, DenseFactor)#
HARK.ConsumptionSaving.ConsHabitModel.make_habit_solution_terminal()#

Make a pseudo-terminal solution for the habit formation model, which has zero functions for (marginal) value.

HARK.ConsumptionSaving.ConsHabitModel.calc_marg_values(S, k, hpre, rho, R, Gamma, alpha, lamda, beta, C, Vp)#

Helper function for computing expected marginal value with respect to market resources and habit stock. Used internally by solve_one_period_ConsHabit.

The code here uses “math notation” for quick programming. See the only place in the code where this function is used for a translation of the symbols.

HARK.ConsumptionSaving.ConsHabitModel.calc_mid_dvds(shocks, w_nrm, H_nrm, share, rfree, dvdkFunc_next)#

Compute middle-of-period marginal value of risky asset share by taking expec- tations over risky return shocks. Uses the next period’s marginal value func- tions directly (they already integrate over income shocks).

Parameters:
  • shocks (float or np.array) – Risky return realizations.

  • w_nrm (np.array) – Pre-return savings (w = m - c).

  • H_nrm (np.array) – End-of-period habit stock.

  • share (np.array) – Risky share.

  • rfree (float) – Risk-free return factor.

  • dvdkFunc_next (callable) – Next period’s marginal value of capital, dvdk(k, hPre).

Returns:

dvds – Marginal value of risky share (zero at optimum).

Return type:

np.array

HARK.ConsumptionSaving.ConsHabitModel.calc_mid_dvdx(shocks, w_nrm, H_nrm, share, rfree, dvdkFunc_next, dvdhFunc_next)#

Compute middle-of-period marginal value of wealth and habit stock by taking expectations over risky return shocks. Uses the next period’s marginal value function directly (they already integrate over income shocks).

Parameters:
  • shocks (float or np.array) – Risky return realizations.

  • w_nrm (np.array) – Pre-return savings (w = m - c).

  • H_nrm (np.array) – End-of-period habit stock.

  • share (np.array) – Risky share.

  • rfree (float) – Risk-free return factor.

  • dvdkFunc_next (callable) – Next period’s marginal value of capital, dvdk(k, hPre).

  • dvdhFunc_next (callable) – Next period’s marginal value of habit stock, dvdh(k, hPre).

Returns:

  • dvdw (np.array) – Marginal value of pre-return savings.

  • dvdH (np.array) – Marginal value of end-of-period habit stock.

HARK.ConsumptionSaving.ConsHabitModel.solve_one_period_ConsHabit(solution_next, IncShkDstn, LivPrb, DiscFac, CRRA, Rfree, PermGroFac, BoroCnstArt, aXtraGrid, HabitGrid, FOCinverter, HabitWgt, HabitRte, mXtraGrid, hGridDense)#

Solve one period of the consumption-saving model with habit formation.

Parameters:
  • solution_next (dict) – Dictionary with next period’s solution.

  • IncShkDstn (DiscreteDistribution) – Discretized permanent and transitory income shock distribution this period.

  • LivPrb (float) – Survival probability at the end of this period.

  • DiscFac (float) – Intertemporal discount factor.

  • CRRA (float) – Coefficient of relative risk aversion.

  • Rfree (float) – Interest factor on capital at the start of this period.

  • PermGroFac (float) – Permanent income growth factor at the start of this period.

  • BoroCnstArt (float or None) – Artificial borrowing constraint on assets at the end of this period, as a fraction of permanent income.

  • aXtraGrid (np.array) – Grid of “assets above minimum”.

  • HabitGrid (np.array) – Grid of consumption habit stocks on which to solve the problem.

  • FOCinverter (HabitFormationInverter) – Function that inverts the first order conditions to yield optimal consumption and the decision-time habit stock from which it was chosen.

  • HabitWgt (float) – Exponent on habit stock, which is used as a divisor on consumption in the utility function: U(c,h) = u(c / h**alpha). Should be on unit interval.

  • HabitRte (float) – Rate at which habit stock is updated by new consumption: H = lambda*c + (1-lambda)*h. Should be on the unit interval.

  • mXtraGrid (np.array) – Dense grid of market resources, used to “re-interpolate” the curvilinear consumption function onto a rectilinear grid.

  • hGridDense (np.array) – Dense grid of habit stocks, used to “re-interpolate” the curvilinear consumption function onto a rectilinear grid.

Returns:

solution_now – Solution to this period’s problem, with the following keys: cFunc : Consumption function over (mNrm, hNrm). dvdkFunc : Marginal value of beginning-of-period capital, defined on (kNrm, hPre). dvdhFunc : Marginal value of beginning-of-period habit stock, defined on (kNrm, hPre). kNrmMin : Minimum allowable beginning-of-period capital.

Return type:

dict

HARK.ConsumptionSaving.ConsHabitModel.solve_optimal_share_habit(solution_next, RiskyDstn, LivPrb, DiscFac, CRRA, Rfree, BoroCnstArt, aXtraGrid, HabitGrid, ShareGrid, ShareLimit)#

Solve only the portfolio allocation problem of the consumption-saving model with habit formation.

Parameters:
  • solution_next (dict) – Dictionary with next period’s solution.

  • RiskyDstn (DiscreteDistribution) – Discretized risky asset return distribution.

  • LivPrb (float) – Survival probability at the end of this period.

  • DiscFac (float) – Intertemporal discount factor.

  • CRRA (float) – Coefficient of relative risk aversion.

  • Rfree (float) – Interest factor on risk-free asset.

  • BoroCnstArt (float or None) – Artificial borrowing constraint on end-of-period assets.

  • aXtraGrid (np.array) – Grid of “assets above minimum”.

  • HabitGrid (np.array) – Grid of habit stock values.

  • ShareGrid (np.array) – Grid of risky share values on [0,1].

  • ShareLimit (float) – Merton-Samuelson limiting share as wealth -> infinity.

Returns:

solution_mid – Solution to the portfolio allocation problem, which has a similar form as the solution to the period overall. The dictionary key dvdkFunc refers to dvdwFunc, marginal value of post-consumption wealth. The key dvdHfunc is the mid-period marginal value of post-consumption habit stock, just before the portfolio allocation decision is made.

Return type:

dict

HARK.ConsumptionSaving.ConsHabitModel.solve_one_period_HabitPortfolio(solution_next, IncShkDstn, RiskyDstn, LivPrb, DiscFac, CRRA, Rfree, PermGroFac, BoroCnstArt, aXtraGrid, HabitGrid, ShareGrid, ShareLimit, FOCinverter, HabitWgt, HabitRte, mXtraGrid, hGridDense)#

Solve one period of the consumption-saving model with habit formation and portfolio choice. This version uses a “modular” structure, solving the portfolio problem and consumption problem using separate sub-functions. The latter sub- function is literally the basic habit formation solver with some parameters turned off (i.e. set to 1.0) because they were handled in the portfolio block.

Parameters:
  • solution_next (dict) – Dictionary with next period’s solution.

  • IncShkDstn (DiscreteDistribution) – Discretized permanent and transitory income shock distribution this period.

  • RiskyDstn (DiscreteDistribution) – Discretized risky asset return distribution.

  • LivPrb (float) – Survival probability at the end of this period.

  • DiscFac (float) – Intertemporal discount factor.

  • CRRA (float) – Coefficient of relative risk aversion.

  • Rfree (float) – Interest factor on capital at the start of this period.

  • PermGroFac (float) – Permanent income growth factor at the start of this period.

  • BoroCnstArt (float or None) – Artificial borrowing constraint on assets at the end of this period, as a fraction of permanent income.

  • aXtraGrid (np.array) – Grid of “assets above minimum”.

  • HabitGrid (np.array) – Grid of consumption habit stocks on which to solve the problem.

  • ShareGrid (np.array) – Grid of risky share values on [0,1].

  • ShareLimit (float) – Merton-Samuelson limiting share as wealth -> infinity.

  • FOCinverter (HabitFormationInverter) – Function that inverts the first order conditions to yield optimal consumption and the decision-time habit stock from which it was chosen.

  • HabitWgt (float) – Exponent on habit stock, which is used as a divisor on consumption in the utility function: U(c,h) = u(c / h**alpha). Should be on unit interval.

  • HabitRte (float) – Rate at which habit stock is updated by new consumption: H = lambda*c + (1-lambda)*h. Should be on the unit interval.

  • mXtraGrid (np.array) – Dense grid of market resources, used to “re-interpolate” the curvilinear consumption function onto a rectilinear grid.

  • hGridDense (np.array) – Dense grid of habit stocks, used to “re-interpolate” the curvilinear consumption function onto a rectilinear grid.

Returns:

solution_now – Solution to this period’s problem, with the following keys: cFunc : Consumption function over (mNrm, hNrm). ShareFunc : Risky share function over (wNrm, HNrm). dvdkFunc : Marginal value of beginning-of-period capital, defined on (kNrm, hPre). dvdhFunc : Marginal value of beginning-of-period habit stock, defined on (kNrm, hPre). kNrmMin : Minimum allowable beginning-of-period capital.

Return type:

dict

class HARK.ConsumptionSaving.ConsHabitModel.HabitConsumerType(solution_terminal=None, pseudo_terminal=True, tolerance=1e-06, verbose=1, quiet=False, seed=0, construct=True, use_defaults=True, **kwds)#

Bases: AgentType

A class for representing consumers who form consumption habits. Agents get flow utility according to a CRRA felicity function that depends on both current consumption and the habit stock h_t. The habit stock evolves as a weighted average of current consumption and prior habit stock. Consumers can save in a single risk-free asset, so this model is an extension of the workhorse IndShockConsumerType to include a habit stock.

\[ \begin{align}\begin{aligned}\newcommand{\CRRA}{\rho} \newcommand{\LivPrb}{\mathsf{S}} \newcommand{\PermGroFac}{\Gamma} \newcommand{\Rfree}{\mathsf{R}} \newcommand{\DiscFac}{\beta} \newcommand{\HabitWgt}{\alpha} \newcommand{\HabitRte}{\lambda}\\\begin{split}\begin{align*} v_t(m_t,h_t) &= \max_{c_t}u(c_t,h_t) + \DiscFac \LivPrb_t \mathbb{E}_{t} \left[ (\PermGroFac_{t+1} \psi_{t+1})^{(1-\HabitWgt)(1-\CRRA)} v_{t+1}(m_{t+1}, h_{t+1}) \right] \\ & \text{s.t.} \\ a_t &= m_t - c_t, \\ H_t &= \HabitRte c_t + (1-\HabitRte) h_t, \\ a_t &\geq \underline{a}, \\ m_{t+1} &= a_t \Rfree_{t+1}/(\PermGroFac_{t+1} \psi_{t+1}) + \theta_{t+1}, \\ h_{t+1} &= H_t / (\PermGroFac_{t+1} \psi_{t+1}), \\ (\psi_{t+1},\theta_{t+1}) &\sim F_{t+1}, \\ \mathbb{E}[\psi] &= 1, \\ u(c,h) &= \frac{(c/h^\HabitWgt)^{1-\CRRA}}{1-\CRRA}. \end{align*}\end{split}\end{aligned}\end{align} \]
default_ = {'model': 'ConsHabit.yaml', 'params': {'AgentCount': 10000, 'BoroCnstArt': 0.0, 'CRRA': 2.0, 'ChiCount': 251, 'ChiMax': 50.0, 'ChiOrder': 1.5, 'DenseFactor': 3, 'DiscFac': 0.96, 'HabitCount': 41, 'HabitInitCount': 15, 'HabitMax': 5.0, 'HabitMin': 0.2, 'HabitOrder': 2.0, 'HabitRte': 0.2, 'HabitWgt': 0.5, 'IncUnemp': 0.3, 'IncUnempRet': 0.0, 'LivPrb': [0.98], 'PermGroFac': [1.01], 'PermShkCount': 7, 'PermShkStd': [0.1], 'Rfree': [1.03], 'T_age': None, 'T_cycle': 1, 'T_retire': 0, 'TranShkCount': 7, 'TranShkStd': [0.1], 'UnempPrb': 0.05, 'UnempPrbRet': 0.005, 'aXtraCount': 72, 'aXtraExtra': None, 'aXtraMax': 30, 'aXtraMin': 0.001, 'aXtraNestFac': 2, 'constructors': {'DenseGrids': <function make_dense_grids>, 'FOCinverter': <function make_habit_inverter>, 'HabitGrid': <function make_habit_grid>, 'HabitInitDstn': <function make_lognormal_habit_init_dstn>, 'IncShkDstn': <function construct_lognormal_income_process_unemployment>, 'PermShkDstn': <function get_PermShkDstn_from_IncShkDstn>, 'TranShkDstn': <function get_TranShkDstn_from_IncShkDstn>, 'aXtraGrid': <function make_assets_grid>, 'hGridDense': <HARK.utilities.get_it_from object>, 'kNrmInitDstn': <function make_lognormal_kNrm_init_dstn>, 'mXtraGrid': <HARK.utilities.get_it_from object>, 'pLvlInitDstn': <function make_lognormal_pLvl_init_dstn>, 'solution_terminal': <function make_habit_solution_terminal>}, 'cycles': 1, 'hLogInitMean': -0.5, 'hLogInitStd': 0.2, 'kLogInitMean': -12.0, 'kLogInitStd': 0.0, 'kNrmInitCount': 15, 'pLogInitMean': 0.0, 'pLogInitStd': 0.0, 'pLvlInitCount': 15, 'pseudo_terminal': True}, 'solver': <function solve_one_period_ConsHabit>, 'track_vars': ['aNrm', 'cNrm', 'mNrm', 'hNrm', 'pLvl']}#
time_inv_ = ['DiscFac', 'CRRA', 'BoroCnstArt', 'aXtraGrid', 'HabitGrid', 'FOCinverter', 'HabitWgt', 'HabitRte', 'mXtraGrid', 'hGridDense']#
time_vary_ = ['IncShkDstn', 'Rfree', 'PermGroFac', 'LivPrb']#
shock_vars_ = ['PermShk', 'TranShk']#
distributions = ['IncShkDstn', 'PermShkDstn', 'TranShkDstn', 'kNrmInitDstn', 'pLvlInitDstn', 'HabitInitDstn']#
class HARK.ConsumptionSaving.ConsHabitModel.HabitPortfolioConsumerType(solution_terminal=None, pseudo_terminal=True, tolerance=1e-06, verbose=1, quiet=False, seed=0, construct=True, use_defaults=True, **kwds)#

Bases: HabitConsumerType

A class for representing consumers who form consumption habits and can allocate their wealth between a risky and riskless asset. Agents get flow utility according to a CRRA felicity function that depends on both current consumption and the habit stock h_t. The habit stock evolves as a weighted average of current consumption and prior habit stock.

This type’s solver uses a “modular” approach that separates the portfolio allo- cation and consumption-saving problems into two functions. The latter function is just the solver for HabitConsumerType. Consequently, the consumption function is defined over (m,h) but the risky share function is defined over (w,H).

\[ \begin{align}\begin{aligned}\newcommand{\CRRA}{\rho} \newcommand{\LivPrb}{\mathsf{S}} \newcommand{\PermGroFac}{\Gamma} \newcommand{\Rfree}{\mathsf{R}} \newcommand{\Risky}{\mathfrak{R}} \newcommand{\DiscFac}{\beta} \newcommand{\HabitWgt}{\alpha} \newcommand{\HabitRte}{\lambda}\\\begin{split}\begin{align*} v_t(m_t,h_t) &= \max_{c_t, s_t} u(c_t,h_t) + \DiscFac \LivPrb_t \mathbb{E}_{t} \left[ (\PermGroFac_{t+1} \psi_{t+1})^{(1-\HabitWgt)(1-\CRRA)} v_{t+1}(m_{t+1}, h_{t+1}) \right] \\ & \text{s.t.} \\ w_t &= m_t - c_t, \\ H_t &= \HabitRte c_t + (1-\HabitRte) h_t, \\ w_t &\geq 0, \\ s_t &\in [0,1], \\ a_t &= R_t w_t, \\ R_{t} &= s_t \Risky_{t} + (1-s_t) \Rfree_{t}, \\ m_{t+1} &= a_t / (\PermGroFac_{t+1} \psi_{t+1}) + \theta_{t+1}, \\ h_{t+1} &= H_t / (\PermGroFac_{t+1} \psi_{t+1}), \\ (\psi_{t+1}, \theta_{t+1}) &\sim F_{t+1}, \\ \Risky_{t} & \sim G, \\ u(c,h) &= \frac{(c/h^\HabitWgt)^{1-\CRRA}}{1-\CRRA}. \end{align*}\end{split}\end{aligned}\end{align} \]
default_ = {'model': 'ConsHabitPortfolio.yaml', 'params': {'AgentCount': 10000, 'BoroCnstArt': 0.0, 'CRRA': 2.0, 'ChiCount': 251, 'ChiMax': 50.0, 'ChiOrder': 1.5, 'DenseFactor': 3, 'DiscFac': 0.96, 'HabitCount': 41, 'HabitInitCount': 15, 'HabitMax': 5.0, 'HabitMin': 0.2, 'HabitOrder': 2.0, 'HabitRte': 0.2, 'HabitWgt': 0.5, 'IncUnemp': 0.3, 'IncUnempRet': 0.0, 'LivPrb': [0.98], 'PermGroFac': [1.01], 'PermShkCount': 7, 'PermShkStd': [0.1], 'Rfree': [1.03], 'RiskyAvg': 1.08, 'RiskyCount': 5, 'RiskyStd': 0.18, 'ShareCount': 26, 'T_age': None, 'T_cycle': 1, 'T_retire': 0, 'TranShkCount': 7, 'TranShkStd': [0.1], 'UnempPrb': 0.05, 'UnempPrbRet': 0.005, 'aXtraCount': 72, 'aXtraExtra': None, 'aXtraMax': 30, 'aXtraMin': 0.001, 'aXtraNestFac': 2, 'constructors': {'DenseGrids': <function make_dense_grids>, 'FOCinverter': <function make_habit_inverter>, 'HabitGrid': <function make_habit_grid>, 'HabitInitDstn': <function make_lognormal_habit_init_dstn>, 'IncShkDstn': <function construct_lognormal_income_process_unemployment>, 'PermShkDstn': <function get_PermShkDstn_from_IncShkDstn>, 'RiskyDstn': <function make_lognormal_RiskyDstn>, 'ShareGrid': <function make_simple_ShareGrid>, 'ShareLimit': <function calc_ShareLimit_for_CRRA>, 'TranShkDstn': <function get_TranShkDstn_from_IncShkDstn>, 'aXtraGrid': <function make_assets_grid>, 'hGridDense': <HARK.utilities.get_it_from object>, 'kNrmInitDstn': <function make_lognormal_kNrm_init_dstn>, 'mXtraGrid': <HARK.utilities.get_it_from object>, 'pLvlInitDstn': <function make_lognormal_pLvl_init_dstn>, 'solution_terminal': <function make_habit_solution_terminal>}, 'cycles': 1, 'hLogInitMean': -0.5, 'hLogInitStd': 0.2, 'kLogInitMean': -12.0, 'kLogInitStd': 0.0, 'kNrmInitCount': 15, 'pLogInitMean': 0.0, 'pLogInitStd': 0.0, 'pLvlInitCount': 15, 'pseudo_terminal': True}, 'solver': <function solve_one_period_HabitPortfolio>, 'track_vars': ['aNrm', 'cNrm', 'mNrm', 'hNrm', 'Share', 'pLvl']}#
time_inv_ = ['DiscFac', 'CRRA', 'BoroCnstArt', 'aXtraGrid', 'HabitGrid', 'FOCinverter', 'HabitWgt', 'HabitRte', 'mXtraGrid', 'hGridDense', 'RiskyDstn', 'ShareGrid']#
time_vary_ = ['IncShkDstn', 'Rfree', 'PermGroFac', 'LivPrb', 'ShareLimit']#
shock_vars_ = ['PermShk', 'TranShk', 'Risky']#
distributions = ['IncShkDstn', 'PermShkDstn', 'TranShkDstn', 'kNrmInitDstn', 'pLvlInitDstn', 'HabitInitDstn', 'RiskyDstn']#