# HARK.ConsumptionSaving.ConsAggShockModel¶

Consumption-saving models with aggregate productivity shocks as well as idiosyn- cratic income shocks. Currently only contains one microeconomic model with a basic solver. Also includes a subclass of Market called CobbDouglas economy, used for solving “macroeconomic” models with aggregate shocks.

Functions

 main() solveConsAggMarkov(solution_next, …) Solve one period of a consumption-saving problem with idiosyncratic and aggregate shocks (transitory and permanent). solveConsAggShock(solution_next, IncomeDstn, …) Solve one period of a consumption-saving problem with idiosyncratic and aggregate shocks (transitory and permanent).

Classes

 AggShockConsumerType([time_flow]) A class to represent consumers who face idiosyncratic (transitory and per- manent) shocks to their income and live in an economy that has aggregate (transitory and permanent) shocks to labor productivity. AggShockMarkovConsumerType(**kwds) A class for representing ex ante heterogeneous “types” of consumers who experience both aggregate and idiosyncratic shocks to productivity (both permanent and transitory), who lives in an environment where the macroeconomic state is subject to Markov-style discrete state evolution. AggShocksDynamicRule(AFunc) Just a container class for passing the dynamic rule in the aggregate shocks model to agents. AggregateSavingRule(intercept, slope) A class to represent agent beliefs about aggregate saving at the end of this period (AaggNow) as a function of (normalized) aggregate market resources at the beginning of the period (MaggNow). CobbDouglasAggVars(MaggNow, AaggNow, …) A simple class for holding the relevant aggregate variables that should be passed from the market to each type. CobbDouglasEconomy([agents, tolerance, act_T]) A class to represent an economy with a Cobb-Douglas aggregate production function over labor and capital, extending HARK.Market. CobbDouglasMarkovEconomy([agents, …]) A class to represent an economy with a Cobb-Douglas aggregate production function over labor and capital, extending HARK.Market. MargValueFunc2D(cFunc, CRRA) A class for representing a marginal value function in models where the standard envelope condition of dvdm(m,M) = u’(c(m,M)) holds (with CRRA utility). SmallOpenEconomy([agents, tolerance, act_T]) A class for representing a small open economy, where the wage rate and interest rate are exogenously determined by some “global” rate. SmallOpenMarkovEconomy([agents, tolerance, …]) A class for representing a small open economy, where the wage rate and interest rate are exogenously determined by some “global” rate.
class HARK.ConsumptionSaving.ConsAggShockModel.AggShockConsumerType(time_flow=True, **kwds)

A class to represent consumers who face idiosyncratic (transitory and per- manent) shocks to their income and live in an economy that has aggregate (transitory and permanent) shocks to labor productivity. As the capital- to-labor ratio varies in the economy, so does the wage rate and interest rate. “Aggregate shock consumers” have beliefs about how the capital ratio evolves over time and take aggregate shocks into account when making their decision about how much to consume.

Methods

 __call__(self, \*\*kwds) Assign an arbitrary number of attributes to this agent, as a convenience. addAggShkDstn(self, AggShkDstn) Updates attribute IncomeDstn by combining idiosyncratic shocks with aggregate shocks. addToTimeInv(self, \*params) Adds any number of parameters to time_inv for this instance. addToTimeVary(self, \*params) Adds any number of parameters to time_vary for this instance. assignParameters(self, \*\*kwds) Assign an arbitrary number of attributes to this agent. cFunc_terminal_(x) calcBoundingValues(self) Calculate human wealth plus minimum and maximum MPC in an infinite horizon model with only one period repeated indefinitely. checkConditions(self[, verbose, public_call]) This method checks whether the instance’s type satisfies the growth impatience condition (GIC), return impatience condition (RIC), absolute impatience condition (AIC), weak return impatience condition (WRIC), finite human wealth condition (FHWC) and finite value of autarky condition (FVAC). checkElementsOfTimeVaryAreLists(self) A method to check that elements of time_vary are lists. checkRestrictions(self) A method to check that various restrictions are met for the model class. clearHistory(self) Clears the histories of the attributes named in self.track_vars. delFromTimeInv(self, \*params) Removes any number of parameters from time_inv for this instance. delFromTimeVary(self, \*params) Removes any number of parameters from time_vary for this instance. distance(self, other) A generic distance method, which requires the existence of an attribute called distance_criteria, giving a list of strings naming the attributes to be considered by the distance metric. getAvg(self, varname, \*\*kwds) Calculates the average of an attribute of this instance. getControls(self) Calculates consumption for each consumer of this type using the consumption functions. getEconomyData(self, Economy) Imports economy-determined objects into self from a Market. getMortality(self) Simulates mortality or agent turnover according to some model-specific rules named simDeath and simBirth (methods of an AgentType subclass). getPostStates(self) Calculates end-of-period assets for each consumer of this type. getRfree(self) Returns an array of size self.AgentCount with self.RfreeNow in every entry. getShocks(self) Finds the effective permanent and transitory shocks this period by combining the aggregate and idiosyncratic shocks of each type. getStates(self) Calculates updated values of normalized market resources and permanent income level for each agent. initializeSim(self) Prepares this AgentType for a new simulation. makeEulerErrorFunc(self[, mMax, approx_inc_dstn]) 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. makeShockHistory(self) Makes a pre-specified history of shocks for the simulation. marketAction(self) In the aggregate shocks model, the “market action” is to simulate one period of receiving income and choosing how much to consume. postSolve(self) A method that is run immediately after the model is solved, to finalize the solution in some way. preSolve(self) A method that is run immediately before the model is solved, to check inputs or to prepare the terminal solution, perhaps. readShocks(self) Reads values of shock variables for the current period from history arrays. reset(self) Initialize this type for a new simulated history of K/L ratio. resetRNG(self) Reset the random number generator for this type. simBirth(self, which_agents) Makes new consumers for the given indices. simDeath(self) Randomly determine which consumers die, and distribute their wealth among the survivors. simOnePeriod(self) Simulates one period for this type. simulate(self[, sim_periods]) Simulates this agent type for a given number of periods (defaults to self.T_sim if no input). solution_terminal_(\*\*kwds) solve(self[, verbose]) Solve the model for this instance of an agent type by backward induction. timeFlip(self) Reverse the flow of time for this instance. timeFwd(self) Make time flow forward for this instance. timeReport(self) Report to the user the direction that time is currently “flowing” for this instance. timeRev(self) Make time flow backward for this instance. unpackcFunc(self) “Unpacks” the consumption functions into their own field for easier access. update(self) Update the income process, the assets grid, and the terminal solution. updateAssetsGrid(self) Updates this agent’s end-of-period assets grid by constructing a multi- exponentially spaced grid of aXtra values. updateIncomeProcess(self) Updates this agent’s income process based on his own attributes. updateSolutionTerminal(self) Updates the terminal period solution for an aggregate shock consumer. vFunc_terminal_(x)
 getMaggNow
addAggShkDstn(self, AggShkDstn)

Updates attribute IncomeDstn by combining idiosyncratic shocks with aggregate shocks.

Parameters: AggShkDstn : [np.array] Aggregate productivity shock distribution. First element is proba- bilities, second element is agg permanent shocks, third element is agg transitory shocks. None
calcBoundingValues(self)

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 None
getControls(self)

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

Parameters: None None
getEconomyData(self, Economy)

Imports economy-determined objects into self from a Market. Instances of AggShockConsumerType “live” in some macroeconomy that has attributes relevant to their microeconomic model, like the relationship between the capital-to-labor ratio and the interest and wage rates; this method imports those attributes from an “economy” object and makes them attributes of the ConsumerType.

Parameters: Economy : Market The “macroeconomy” in which this instance “lives”. Might be of the subclass CobbDouglasEconomy, which has methods to generate the relevant attributes. None
getRfree(self)

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

Parameters: None RfreeNow : np.array Array of size self.AgentCount with risk free interest rate for each agent.
getShocks(self)

Finds the effective permanent and transitory shocks this period by combining the aggregate and idiosyncratic shocks of each type.

Parameters: None None
makeEulerErrorFunc(self, 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.IncomeDstn 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.IncomeDstn[0], or to use a very accurate discrete approximation instead. When True, uses approximation in IncomeDstn; when False, makes and uses a very dense approximation. None
marketAction(self)

In the aggregate shocks model, the “market action” is to simulate one period of receiving income and choosing how much to consume.

Parameters: None None
preSolve(self)

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

Parameters: none none
reset(self)

Initialize this type for a new simulated history of K/L ratio.

Parameters: None None
simBirth(self, which_agents)

Makes new consumers for the given indices. Initialized variables include aNrm and pLvl, as well as time variables t_age and t_cycle. Normalized assets and permanent income levels are drawn from lognormal distributions given by aNrmInitMean and aNrmInitStd (etc).

Parameters: which_agents : np.array(Bool) Boolean array of size self.AgentCount indicating which agents should be “born”. None
simDeath(self)

Randomly determine which consumers die, and distribute their wealth among the survivors. This method only works if there is only one period in the cycle.

Parameters: None who_dies : np.array(bool) Boolean array of size AgentCount indicating which agents die.
updateSolutionTerminal(self)

Updates the terminal period solution for an aggregate shock consumer. Only fills in the consumption function and marginal value function.

Parameters: None None
class HARK.ConsumptionSaving.ConsAggShockModel.AggShockMarkovConsumerType(**kwds)

A class for representing ex ante heterogeneous “types” of consumers who experience both aggregate and idiosyncratic shocks to productivity (both permanent and transitory), who lives in an environment where the macroeconomic state is subject to Markov-style discrete state evolution.

Methods

 __call__(self, \*\*kwds) Assign an arbitrary number of attributes to this agent, as a convenience. addAggShkDstn(self, AggShkDstn) Variation on AggShockConsumerType.addAggShkDstn that handles the Markov state. addToTimeInv(self, \*params) Adds any number of parameters to time_inv for this instance. addToTimeVary(self, \*params) Adds any number of parameters to time_vary for this instance. assignParameters(self, \*\*kwds) Assign an arbitrary number of attributes to this agent. cFunc_terminal_(x) calcBoundingValues(self) Calculate human wealth plus minimum and maximum MPC in an infinite horizon model with only one period repeated indefinitely. checkConditions(self[, verbose, public_call]) This method checks whether the instance’s type satisfies the growth impatience condition (GIC), return impatience condition (RIC), absolute impatience condition (AIC), weak return impatience condition (WRIC), finite human wealth condition (FHWC) and finite value of autarky condition (FVAC). checkElementsOfTimeVaryAreLists(self) A method to check that elements of time_vary are lists. checkRestrictions(self) A method to check that various restrictions are met for the model class. clearHistory(self) Clears the histories of the attributes named in self.track_vars. delFromTimeInv(self, \*params) Removes any number of parameters from time_inv for this instance. delFromTimeVary(self, \*params) Removes any number of parameters from time_vary for this instance. distance(self, other) A generic distance method, which requires the existence of an attribute called distance_criteria, giving a list of strings naming the attributes to be considered by the distance metric. getAvg(self, varname, \*\*kwds) Calculates the average of an attribute of this instance. getControls(self) Calculates consumption for each consumer of this type using the consumption functions. getEconomyData(self, Economy) Imports economy-determined objects into self from a Market. getMortality(self) Simulates mortality or agent turnover according to some model-specific rules named simDeath and simBirth (methods of an AgentType subclass). getPostStates(self) Calculates end-of-period assets for each consumer of this type. getRfree(self) Returns an array of size self.AgentCount with self.RfreeNow in every entry. getShocks(self) Gets permanent and transitory income shocks for this period. getStates(self) Calculates updated values of normalized market resources and permanent income level for each agent. initializeSim(self) Prepares this AgentType for a new simulation. makeEulerErrorFunc(self[, mMax, approx_inc_dstn]) 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. makeShockHistory(self) Makes a pre-specified history of shocks for the simulation. marketAction(self) In the aggregate shocks model, the “market action” is to simulate one period of receiving income and choosing how much to consume. postSolve(self) A method that is run immediately after the model is solved, to finalize the solution in some way. preSolve(self) A method that is run immediately before the model is solved, to check inputs or to prepare the terminal solution, perhaps. readShocks(self) Reads values of shock variables for the current period from history arrays. reset(self) Initialize this type for a new simulated history of K/L ratio. resetRNG(self) Reset the random number generator for this type. simBirth(self, which_agents) Makes new consumers for the given indices. simDeath(self) Randomly determine which consumers die, and distribute their wealth among the survivors. simOnePeriod(self) Simulates one period for this type. simulate(self[, sim_periods]) Simulates this agent type for a given number of periods (defaults to self.T_sim if no input). solution_terminal_(\*\*kwds) solve(self[, verbose]) Solve the model for this instance of an agent type by backward induction. timeFlip(self) Reverse the flow of time for this instance. timeFwd(self) Make time flow forward for this instance. timeReport(self) Report to the user the direction that time is currently “flowing” for this instance. timeRev(self) Make time flow backward for this instance. unpackcFunc(self) “Unpacks” the consumption functions into their own field for easier access. update(self) Update the income process, the assets grid, and the terminal solution. updateAssetsGrid(self) Updates this agent’s end-of-period assets grid by constructing a multi- exponentially spaced grid of aXtra values. updateIncomeProcess(self) Updates this agent’s income process based on his own attributes. updateSolutionTerminal(self) Update the terminal period solution. vFunc_terminal_(x)
 getMaggNow getMrkvNow
addAggShkDstn(self, AggShkDstn)

Variation on AggShockConsumerType.addAggShkDstn that handles the Markov state. AggShkDstn is a list of aggregate productivity shock distributions for each Markov state.

getControls(self)

Calculates consumption for each consumer of this type using the consumption functions. For this AgentType class, MrkvNow is the same for all consumers. However, in an extension with “macroeconomic inattention”, consumers might misperceive the state and thus act as if they are in different states.

Parameters: None None
getShocks(self)

Gets permanent and transitory income shocks for this period. Samples from IncomeDstn for each period in the cycle. This is a copy-paste from IndShockConsumerType, with the addition of the Markov macroeconomic state. Unfortunately, the getShocks method for MarkovConsumerType cannot be used, as that method assumes that MrkvNow is a vector with a value for each agent, not just a single int.

Parameters: None None
updateSolutionTerminal(self)

Update the terminal period solution. This method should be run when a new AgentType is created or when CRRA changes.

Parameters: None None
class HARK.ConsumptionSaving.ConsAggShockModel.AggShocksDynamicRule(AFunc)

Just a container class for passing the dynamic rule in the aggregate shocks model to agents.

Methods

 __call__(self, \*\*kwds) Assign an arbitrary number of attributes to this agent, as a convenience. assignParameters(self, \*\*kwds) Assign an arbitrary number of attributes to this agent. distance(self, other) A generic distance method, which requires the existence of an attribute called distance_criteria, giving a list of strings naming the attributes to be considered by the distance metric. getAvg(self, varname, \*\*kwds) Calculates the average of an attribute of this instance.
class HARK.ConsumptionSaving.ConsAggShockModel.AggregateSavingRule(intercept, slope)

A class to represent agent beliefs about aggregate saving at the end of this period (AaggNow) as a function of (normalized) aggregate market resources at the beginning of the period (MaggNow).

Methods

 __call__(self, Mnow) Evaluates aggregate savings as a function of the aggregate market resources this period. assignParameters(self, \*\*kwds) Assign an arbitrary number of attributes to this agent. distance(self, other) A generic distance method, which requires the existence of an attribute called distance_criteria, giving a list of strings naming the attributes to be considered by the distance metric. getAvg(self, varname, \*\*kwds) Calculates the average of an attribute of this instance.
class HARK.ConsumptionSaving.ConsAggShockModel.CobbDouglasAggVars(MaggNow, AaggNow, KtoLnow, RfreeNow, wRteNow, PermShkAggNow, TranShkAggNow)

A simple class for holding the relevant aggregate variables that should be passed from the market to each type. Includes the capital-to-labor ratio, the interest factor, the wage rate, and the aggregate permanent and tran- sitory shocks.

Methods

 __call__(self, \*\*kwds) Assign an arbitrary number of attributes to this agent, as a convenience. assignParameters(self, \*\*kwds) Assign an arbitrary number of attributes to this agent. distance(self, other) A generic distance method, which requires the existence of an attribute called distance_criteria, giving a list of strings naming the attributes to be considered by the distance metric. getAvg(self, varname, \*\*kwds) Calculates the average of an attribute of this instance.
class HARK.ConsumptionSaving.ConsAggShockModel.CobbDouglasEconomy(agents=[], tolerance=0.0001, act_T=1000, **kwds)

A class to represent an economy with a Cobb-Douglas aggregate production function over labor and capital, extending HARK.Market. The “aggregate market process” for this market combines all individuals’ asset holdings into aggregate capital, yielding the interest factor on assets and the wage rate for the upcoming period.

Note: The current implementation assumes a constant labor supply, but this will be generalized in the future.

Methods

 __call__(self, \*\*kwds) Assign an arbitrary number of attributes to this agent, as a convenience. assignParameters(self, \*\*kwds) Assign an arbitrary number of attributes to this agent. calcAFunc(self, MaggNow, AaggNow) Calculate a new aggregate savings rule based on the history of the aggregate savings and aggregate market resources from a simulation. calcDynamics(self, MaggNow, AaggNow) Calculates a new dynamic rule for the economy: end of period savings as a function of aggregate market resources. calcRandW(self, aLvlNow, pLvlNow) Calculates the interest factor and wage rate this period using each agent’s capital stock to get the aggregate capital ratio. cultivate(self) Has each AgentType in agents perform their marketAction method, using variables sown from the market (and maybe also “private” variables). distance(self, other) A generic distance method, which requires the existence of an attribute called distance_criteria, giving a list of strings naming the attributes to be considered by the distance metric. getAvg(self, varname, \*\*kwds) Calculates the average of an attribute of this instance. getPermGroFacAggLR(self) A trivial function that returns self.PermGroFacAgg. makeAggShkDstn(self) Creates the attributes TranShkAggDstn, PermShkAggDstn, and AggShkDstn. makeAggShkHist(self) Make simulated histories of aggregate transitory and permanent shocks. makeHistory(self) Runs a loop of sow–>cultivate–>reap–>mill act_T times, tracking the evolution of variables X named in track_vars in attributes named X_hist. mill(self) Processes the variables collected from agents using the function millRule, storing the results in attributes named in aggr_sow. millRule(self, aLvlNow, pLvlNow) Function to calculate the capital to labor ratio, interest factor, and wage rate based on each agent’s current state. reap(self) Collects attributes named in reap_vars from each AgentType in the market, storing them in respectively named attributes of self. reset(self) Reset the economy to prepare for a new simulation. solve(self) “Solves” the market by finding a “dynamic rule” that governs the aggregate market state such that when agents believe in these dynamics, their actions collectively generate the same dynamic rule. solveAgents(self) Solves the microeconomic problem for all AgentTypes in this market. sow(self) Distributes attrributes named in sow_vars from self to each AgentType in the market, storing them in respectively named attributes. store(self) Record the current value of each variable X named in track_vars in an attribute named X_hist. update(self) Use primitive parameters (and perfect foresight calibrations) to make interest factor and wage rate functions (of capital to labor ratio), as well as discrete approximations to the aggregate shock distributions. updateDynamics(self) Calculates a new “aggregate dynamic rule” using the history of variables named in track_vars, and distributes this rule to AgentTypes in agents.
calcAFunc(self, MaggNow, AaggNow)

Calculate a new aggregate savings rule based on the history of the aggregate savings and aggregate market resources from a simulation.

Parameters: MaggNow : [float] List of the history of the simulated aggregate market resources for an economy. AaggNow : [float] List of the history of the simulated aggregate savings for an economy. (unnamed) : CapDynamicRule Object containing a new savings rule
calcDynamics(self, MaggNow, AaggNow)

Calculates a new dynamic rule for the economy: end of period savings as a function of aggregate market resources. Just calls calcAFunc().

calcRandW(self, aLvlNow, pLvlNow)

Calculates the interest factor and wage rate this period using each agent’s capital stock to get the aggregate capital ratio.

Parameters: aLvlNow : [np.array] Agents’ current end-of-period assets. Elements of the list correspond to types in the economy, entries within arrays to agents of that type. AggVarsNow : CobbDouglasAggVars An object containing the aggregate variables for the upcoming period: capital-to-labor ratio, interest factor, (normalized) wage rate, aggregate permanent and transitory shocks.
getPermGroFacAggLR(self)

A trivial function that returns self.PermGroFacAgg. Exists to be overwritten and extended by ConsAggShockMarkov model.

Parameters: None PermGroFacAggLR : float Long run aggregate permanent income growth, which is the same thing as aggregate permanent income growth.
makeAggShkDstn(self)

Creates the attributes TranShkAggDstn, PermShkAggDstn, and AggShkDstn. Draws on attributes TranShkAggStd, PermShkAddStd, TranShkAggCount, PermShkAggCount.

Parameters: None None
makeAggShkHist(self)

Make simulated histories of aggregate transitory and permanent shocks. Histories are of length self.act_T, for use in the general equilibrium simulation.

Parameters: None None
millRule(self, aLvlNow, pLvlNow)

Function to calculate the capital to labor ratio, interest factor, and wage rate based on each agent’s current state. Just calls calcRandW().

reset(self)

Reset the economy to prepare for a new simulation. Sets the time index of aggregate shocks to zero and runs Market.reset().

Parameters: None None
update(self)

Use primitive parameters (and perfect foresight calibrations) to make interest factor and wage rate functions (of capital to labor ratio), as well as discrete approximations to the aggregate shock distributions.

Parameters: None None
class HARK.ConsumptionSaving.ConsAggShockModel.CobbDouglasMarkovEconomy(agents=[], tolerance=0.0001, act_T=1000, **kwds)

A class to represent an economy with a Cobb-Douglas aggregate production function over labor and capital, extending HARK.Market. The “aggregate market process” for this market combines all individuals’ asset holdings into aggregate capital, yielding the interest factor on assets and the wage rate for the upcoming period. This small extension incorporates a Markov state for the “macroeconomy”, so that the shock distribution and aggregate productivity growth factor can vary over time.

Methods

 __call__(self, \*\*kwds) Assign an arbitrary number of attributes to this agent, as a convenience. assignParameters(self, \*\*kwds) Assign an arbitrary number of attributes to this agent. calcAFunc(self, MaggNow, AaggNow) Calculate a new aggregate savings rule based on the history of the aggregate savings and aggregate market resources from a simulation. calcDynamics(self, MaggNow, AaggNow) Calculates a new dynamic rule for the economy: end of period savings as a function of aggregate market resources. calcRandW(self, aLvlNow, pLvlNow) Calculates the interest factor and wage rate this period using each agent’s capital stock to get the aggregate capital ratio. cultivate(self) Has each AgentType in agents perform their marketAction method, using variables sown from the market (and maybe also “private” variables). distance(self, other) A generic distance method, which requires the existence of an attribute called distance_criteria, giving a list of strings naming the attributes to be considered by the distance metric. getAvg(self, varname, \*\*kwds) Calculates the average of an attribute of this instance. getPermGroFacAggLR(self) Calculates and returns the long run permanent income growth factor. makeAggShkDstn(self) Creates the attributes TranShkAggDstn, PermShkAggDstn, and AggShkDstn. makeAggShkHist(self) Make simulated histories of aggregate transitory and permanent shocks. makeHistory(self) Runs a loop of sow–>cultivate–>reap–>mill act_T times, tracking the evolution of variables X named in track_vars in attributes named X_hist. makeMrkvHist(self) Makes a history of macroeconomic Markov states, stored in the attribute MrkvNow_hist. mill(self) Processes the variables collected from agents using the function millRule, storing the results in attributes named in aggr_sow. millRule(self, aLvlNow, pLvlNow) Function to calculate the capital to labor ratio, interest factor, and wage rate based on each agent’s current state. reap(self) Collects attributes named in reap_vars from each AgentType in the market, storing them in respectively named attributes of self. reset(self) Reset the economy to prepare for a new simulation. solve(self) “Solves” the market by finding a “dynamic rule” that governs the aggregate market state such that when agents believe in these dynamics, their actions collectively generate the same dynamic rule. solveAgents(self) Solves the microeconomic problem for all AgentTypes in this market. sow(self) Distributes attrributes named in sow_vars from self to each AgentType in the market, storing them in respectively named attributes. store(self) Record the current value of each variable X named in track_vars in an attribute named X_hist. update(self) Use primitive parameters (and perfect foresight calibrations) to make interest factor and wage rate functions (of capital to labor ratio), as well as discrete approximations to the aggregate shock distributions. updateDynamics(self) Calculates a new “aggregate dynamic rule” using the history of variables named in track_vars, and distributes this rule to AgentTypes in agents.
calcAFunc(self, MaggNow, AaggNow)

Calculate a new aggregate savings rule based on the history of the aggregate savings and aggregate market resources from a simulation. Calculates an aggregate saving rule for each macroeconomic Markov state.

Parameters: MaggNow : [float] List of the history of the simulated aggregate market resources for an economy. AaggNow : [float] List of the history of the simulated aggregate savings for an economy. (unnamed) : CapDynamicRule Object containing new saving rules for each Markov state.
getPermGroFacAggLR(self)

Calculates and returns the long run permanent income growth factor. This is the average growth factor in self.PermGroFacAgg, weighted by the long run distribution of Markov states (as determined by self.MrkvArray).

Parameters: None PermGroFacAggLR : float Long run aggregate permanent income growth factor
makeAggShkDstn(self)

Creates the attributes TranShkAggDstn, PermShkAggDstn, and AggShkDstn. Draws on attributes TranShkAggStd, PermShkAddStd, TranShkAggCount, PermShkAggCount. This version accounts for the Markov macroeconomic state.

Parameters: None None
makeAggShkHist(self)

Make simulated histories of aggregate transitory and permanent shocks. Histories are of length self.act_T, for use in the general equilibrium simulation. Draws on history of aggregate Markov states generated by internal call to makeMrkvHist().

Parameters: None None
makeMrkvHist(self)

Makes a history of macroeconomic Markov states, stored in the attribute MrkvNow_hist. This version ensures that each state is reached a sufficient number of times to have a valid sample for calcDynamics to produce a good dynamic rule. It will sometimes cause act_T to be increased beyond its initially specified level.

Parameters: None None
millRule(self, aLvlNow, pLvlNow)

Function to calculate the capital to labor ratio, interest factor, and wage rate based on each agent’s current state. Just calls calcRandW() and adds the Markov state index.

update(self)

Use primitive parameters (and perfect foresight calibrations) to make interest factor and wage rate functions (of capital to labor ratio), as well as discrete approximations to the aggregate shock distributions.

Parameters: None None
class HARK.ConsumptionSaving.ConsAggShockModel.MargValueFunc2D(cFunc, CRRA)

A class for representing a marginal value function in models where the standard envelope condition of dvdm(m,M) = u’(c(m,M)) holds (with CRRA utility).

Methods

 __call__(self, m, M) Assign an arbitrary number of attributes to this agent, as a convenience. assignParameters(self, \*\*kwds) Assign an arbitrary number of attributes to this agent. distance(self, other) A generic distance method, which requires the existence of an attribute called distance_criteria, giving a list of strings naming the attributes to be considered by the distance metric. getAvg(self, varname, \*\*kwds) Calculates the average of an attribute of this instance.
class HARK.ConsumptionSaving.ConsAggShockModel.SmallOpenEconomy(agents=[], tolerance=0.0001, act_T=1000, **kwds)

A class for representing a small open economy, where the wage rate and interest rate are exogenously determined by some “global” rate. However, the economy is still subject to aggregate productivity shocks.

Methods

 __call__(self, \*\*kwds) Assign an arbitrary number of attributes to this agent, as a convenience. assignParameters(self, \*\*kwds) Assign an arbitrary number of attributes to this agent. calcDynamics(self, KtoLnow) Calculates a new dynamic rule for the economy, which is just an empty object. cultivate(self) Has each AgentType in agents perform their marketAction method, using variables sown from the market (and maybe also “private” variables). distance(self, other) A generic distance method, which requires the existence of an attribute called distance_criteria, giving a list of strings naming the attributes to be considered by the distance metric. getAggShocks(self) Returns aggregate state variables and shocks for this period. getAvg(self, varname, \*\*kwds) Calculates the average of an attribute of this instance. makeAggShkDstn(self) Creates the attributes TranShkAggDstn, PermShkAggDstn, and AggShkDstn. makeAggShkHist(self) Make simulated histories of aggregate transitory and permanent shocks. makeHistory(self) Runs a loop of sow–>cultivate–>reap–>mill act_T times, tracking the evolution of variables X named in track_vars in attributes named X_hist. mill(self) Processes the variables collected from agents using the function millRule, storing the results in attributes named in aggr_sow. millRule(self) No aggregation occurs for a small open economy, because the wage and interest rates are exogenously determined. reap(self) Collects attributes named in reap_vars from each AgentType in the market, storing them in respectively named attributes of self. reset(self) Reset the economy to prepare for a new simulation. solve(self) “Solves” the market by finding a “dynamic rule” that governs the aggregate market state such that when agents believe in these dynamics, their actions collectively generate the same dynamic rule. solveAgents(self) Solves the microeconomic problem for all AgentTypes in this market. sow(self) Distributes attrributes named in sow_vars from self to each AgentType in the market, storing them in respectively named attributes. store(self) Record the current value of each variable X named in track_vars in an attribute named X_hist. update(self) Use primitive parameters to set basic objects. updateDynamics(self) Calculates a new “aggregate dynamic rule” using the history of variables named in track_vars, and distributes this rule to AgentTypes in agents.
calcDynamics(self, KtoLnow)

Calculates a new dynamic rule for the economy, which is just an empty object. There is no “dynamic rule” for a small open economy, because K/L does not generate w and R.

getAggShocks(self)

Returns aggregate state variables and shocks for this period. The capital-to-labor ratio is irrelevant and thus treated as constant, and the wage and interest rates are also constant. However, aggregate shocks are assigned from a prespecified history.

Parameters: None AggVarsNow : CobbDouglasAggVars Aggregate state and shock variables for this period.
makeAggShkDstn(self)

Creates the attributes TranShkAggDstn, PermShkAggDstn, and AggShkDstn. Draws on attributes TranShkAggStd, PermShkAddStd, TranShkAggCount, PermShkAggCount.

Parameters: None None
makeAggShkHist(self)

Make simulated histories of aggregate transitory and permanent shocks. Histories are of length self.act_T, for use in the general equilibrium simulation. This replicates the same method for CobbDouglasEconomy; future version should create parent class.

Parameters: None None
millRule(self)

No aggregation occurs for a small open economy, because the wage and interest rates are exogenously determined. However, aggregate shocks may occur.

reset(self)

Reset the economy to prepare for a new simulation. Sets the time index of aggregate shocks to zero and runs Market.reset(). This replicates the reset method for CobbDouglasEconomy; future version should create parent class of that class and this one.

Parameters: None None
update(self)

Use primitive parameters to set basic objects. This is an extremely stripped-down version of update for CobbDouglasEconomy.

Parameters: none none
class HARK.ConsumptionSaving.ConsAggShockModel.SmallOpenMarkovEconomy(agents=[], tolerance=0.0001, act_T=1000, **kwds)

A class for representing a small open economy, where the wage rate and interest rate are exogenously determined by some “global” rate. However, the economy is still subject to aggregate productivity shocks. This version supports a discrete Markov state. All methods in this class inherit from the two parent classes.

Methods

 __call__(self, \*\*kwds) Assign an arbitrary number of attributes to this agent, as a convenience. assignParameters(self, \*\*kwds) Assign an arbitrary number of attributes to this agent. calcAFunc(self, MaggNow, AaggNow) Calculate a new aggregate savings rule based on the history of the aggregate savings and aggregate market resources from a simulation. calcDynamics(self, KtoLnow) Calculates a new dynamic rule for the economy: end of period savings as a function of aggregate market resources. calcRandW(self, aLvlNow, pLvlNow) Calculates the interest factor and wage rate this period using each agent’s capital stock to get the aggregate capital ratio. cultivate(self) Has each AgentType in agents perform their marketAction method, using variables sown from the market (and maybe also “private” variables). distance(self, other) A generic distance method, which requires the existence of an attribute called distance_criteria, giving a list of strings naming the attributes to be considered by the distance metric. getAggShocks(self) Returns aggregate state variables and shocks for this period. getAvg(self, varname, \*\*kwds) Calculates the average of an attribute of this instance. getPermGroFacAggLR(self) Calculates and returns the long run permanent income growth factor. makeAggShkDstn(self) Creates the attributes TranShkAggDstn, PermShkAggDstn, and AggShkDstn. makeAggShkHist(self) Make simulated histories of aggregate transitory and permanent shocks. makeHistory(self) Runs a loop of sow–>cultivate–>reap–>mill act_T times, tracking the evolution of variables X named in track_vars in attributes named X_hist. makeMrkvHist(self) Makes a history of macroeconomic Markov states, stored in the attribute MrkvNow_hist. mill(self) Processes the variables collected from agents using the function millRule, storing the results in attributes named in aggr_sow. millRule(self) Function to calculate the capital to labor ratio, interest factor, and wage rate based on each agent’s current state. reap(self) Collects attributes named in reap_vars from each AgentType in the market, storing them in respectively named attributes of self. reset(self) Reset the economy to prepare for a new simulation. solve(self) “Solves” the market by finding a “dynamic rule” that governs the aggregate market state such that when agents believe in these dynamics, their actions collectively generate the same dynamic rule. solveAgents(self) Solves the microeconomic problem for all AgentTypes in this market. sow(self) Distributes attrributes named in sow_vars from self to each AgentType in the market, storing them in respectively named attributes. store(self) Record the current value of each variable X named in track_vars in an attribute named X_hist. update(self) Use primitive parameters (and perfect foresight calibrations) to make interest factor and wage rate functions (of capital to labor ratio), as well as discrete approximations to the aggregate shock distributions. updateDynamics(self) Calculates a new “aggregate dynamic rule” using the history of variables named in track_vars, and distributes this rule to AgentTypes in agents.
calcDynamics(self, KtoLnow)

Calculates a new dynamic rule for the economy: end of period savings as a function of aggregate market resources. Just calls calcAFunc().

makeAggShkDstn(self)

Creates the attributes TranShkAggDstn, PermShkAggDstn, and AggShkDstn. Draws on attributes TranShkAggStd, PermShkAddStd, TranShkAggCount, PermShkAggCount. This version accounts for the Markov macroeconomic state.

Parameters: None None
makeAggShkHist(self)

Make simulated histories of aggregate transitory and permanent shocks. Histories are of length self.act_T, for use in the general equilibrium simulation. Draws on history of aggregate Markov states generated by internal call to makeMrkvHist().

Parameters: None None
millRule(self)

Function to calculate the capital to labor ratio, interest factor, and wage rate based on each agent’s current state. Just calls calcRandW() and adds the Markov state index.

update(self)

Use primitive parameters (and perfect foresight calibrations) to make interest factor and wage rate functions (of capital to labor ratio), as well as discrete approximations to the aggregate shock distributions.

Parameters: None None
HARK.ConsumptionSaving.ConsAggShockModel.solveConsAggMarkov(solution_next, IncomeDstn, LivPrb, DiscFac, CRRA, MrkvArray, PermGroFac, PermGroFacAgg, aXtraGrid, BoroCnstArt, Mgrid, AFunc, Rfunc, wFunc, DeprFac)

Solve one period of a consumption-saving problem with idiosyncratic and aggregate shocks (transitory and permanent). Moreover, the macroeconomic state follows a Markov process that determines the income distribution and aggregate permanent growth factor. This is a basic solver that can’t handle cubic splines, nor can it calculate a value function.

Parameters: solution_next : ConsumerSolution The solution to the succeeding one period problem. IncomeDstn : [[np.array]] A list of lists, each containing five arrays of floats, representing a discrete approximation to the income process between the period being solved and the one immediately following (in solution_next). Order: event probabilities, idisyncratic permanent shocks, idiosyncratic transitory shocks, aggregate permanent shocks, aggregate transitory shocks. 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. MrkvArray : np.array Markov transition matrix between discrete macroeconomic states. MrkvArray[i,j] is probability of being in state j next period conditional on being in state i this period. PermGroFac : float Expected permanent income growth factor at the end of this period, for the individual’s productivity. PermGroFacAgg : [float] Expected aggregate productivity growth in each Markov macro state. aXtraGrid : np.array Array of “extra” end-of-period asset values– assets above the absolute minimum acceptable level. BoroCnstArt : float Artificial borrowing constraint; minimum allowable end-of-period asset-to- permanent-income ratio. Unlike other models, this can’t be None. Mgrid : np.array A grid of aggregate market resourses to permanent income in the economy. AFunc : [function] Aggregate savings as a function of aggregate market resources, for each Markov macro state. Rfunc : function The net interest factor on assets as a function of capital ratio k. wFunc : function The wage rate for labor as a function of capital-to-labor ratio k. DeprFac : float Capital Depreciation Rate solution_now : ConsumerSolution The solution to the single period consumption-saving problem. Includes a consumption function cFunc (linear interpolation over linear interpola- tions) and marginal value function vPfunc.
HARK.ConsumptionSaving.ConsAggShockModel.solveConsAggShock(solution_next, IncomeDstn, LivPrb, DiscFac, CRRA, PermGroFac, PermGroFacAgg, aXtraGrid, BoroCnstArt, Mgrid, AFunc, Rfunc, wFunc, DeprFac)

Solve one period of a consumption-saving problem with idiosyncratic and aggregate shocks (transitory and permanent). This is a basic solver that can’t handle cubic splines, nor can it calculate a value function.

Parameters: solution_next : ConsumerSolution The solution to the succeeding one period problem. IncomeDstn : [np.array] A list containing five arrays of floats, representing a discrete approximation to the income process between the period being solved and the one immediately following (in solution_next). Order: event probabilities, idisyncratic permanent shocks, idiosyncratic transitory shocks, aggregate permanent shocks, aggregate transitory shocks. 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. PermGroFac : float Expected permanent income growth factor at the end of this period. PermGroFacAgg : float Expected aggregate productivity growth factor. aXtraGrid : np.array Array of “extra” end-of-period asset values– assets above the absolute minimum acceptable level. BoroCnstArt : float Artificial borrowing constraint; minimum allowable end-of-period asset-to- permanent-income ratio. Unlike other models, this can’t be None. Mgrid : np.array A grid of aggregate market resourses to permanent income in the economy. AFunc : function Aggregate savings as a function of aggregate market resources. Rfunc : function The net interest factor on assets as a function of capital ratio k. wFunc : function The wage rate for labor as a function of capital-to-labor ratio k. DeprFac : float Capital Depreciation Rate solution_now : ConsumerSolution The solution to the single period consumption-saving problem. Includes a consumption function cFunc (linear interpolation over linear interpola- tions) and marginal value function vPfunc.