code
string
signature
string
docstring
string
loss_without_docstring
float64
loss_with_docstring
float64
factor
float64
''' Slightly extends the base version of this method by recalculating aLvlNow to account for the consumer's (potential) misperception about their productivity level. Parameters ---------- None Returns ------- None ''' RepAgentCons...
def getPostStates(self)
Slightly extends the base version of this method by recalculating aLvlNow to account for the consumer's (potential) misperception about their productivity level. Parameters ---------- None Returns ------- None
14.187102
3.42709
4.139694
''' Finds the representative agent's (average) perceived productivity level. Average perception of productivity gets UpdatePrb weight on the true level, for those that update, and (1-UpdatePrb) weight on the previous average perception times expected aggregate growth, for those t...
def getpLvlPcvd(self)
Finds the representative agent's (average) perceived productivity level. Average perception of productivity gets UpdatePrb weight on the true level, for those that update, and (1-UpdatePrb) weight on the previous average perception times expected aggregate growth, for those that don't update. ...
9.208049
1.852534
4.970516
''' Makes new consumers for the given indices. Slightly extends base method by also setting pLvlTrue = 1.0 in the very first simulated period, as well as initializing the perception of aggregate productivity for each Markov state. The representative agent begins with the correc...
def simBirth(self,which_agents)
Makes new consumers for the given indices. Slightly extends base method by also setting pLvlTrue = 1.0 in the very first simulated period, as well as initializing the perception of aggregate productivity for each Markov state. The representative agent begins with the correct perception of the ...
7.464926
2.664964
2.801136
''' Finds the representative agent's (average) perceived productivity level for each Markov state, as well as the distribution of the representative agent's perception of the Markov state. Parameters ---------- None Returns ------- pLvlPc...
def getpLvlPcvd(self)
Finds the representative agent's (average) perceived productivity level for each Markov state, as well as the distribution of the representative agent's perception of the Markov state. Parameters ---------- None Returns ------- pLvlPcvd : np.array ...
5.079797
3.573633
1.421466
''' Calculates consumption for the representative agent using the consumption functions. Takes the weighted average of cLvl across perceived Markov states. Parameters ---------- None Returns ------- None ''' StateCount = self.Mrkv...
def getControls(self)
Calculates consumption for the representative agent using the consumption functions. Takes the weighted average of cLvl across perceived Markov states. Parameters ---------- None Returns ------- None
7.878986
3.57502
2.2039
''' 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. See documentation for calcRandW for more information. ''' MrkvNow = self.MrkvNow_his...
def millRule(self,aLvlNow,pLvlTrue)
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. See documentation for calcRandW for more information.
7.643661
3.343161
2.286357
''' Executes the list of commands in command_list for each AgentType in agent_list in an ordinary, single-threaded loop. Each command should be a method of that AgentType subclass. This function exists so as to easily disable multithreading, as it uses the same syntax as multithreadCommands. ...
def multiThreadCommandsFake(agent_list,command_list,num_jobs=None)
Executes the list of commands in command_list for each AgentType in agent_list in an ordinary, single-threaded loop. Each command should be a method of that AgentType subclass. This function exists so as to easily disable multithreading, as it uses the same syntax as multithreadCommands. Parameters ...
5.354573
1.313635
4.07615
''' Executes the list of commands in command_list for each AgentType in agent_list using a multithreaded system. Each command should be a method of that AgentType subclass. Parameters ---------- agent_list : [AgentType] A list of instances of AgentType on which the commands will be run....
def multiThreadCommands(agent_list,command_list,num_jobs=None)
Executes the list of commands in command_list for each AgentType in agent_list using a multithreaded system. Each command should be a method of that AgentType subclass. Parameters ---------- agent_list : [AgentType] A list of instances of AgentType on which the commands will be run. command...
3.463756
2.392358
1.447842
''' Stores the progress of a parallel Nelder-Mead search in a text file so that it can be resumed later (after manual termination or a crash). Parameters ---------- name : string Name of the txt file in which to store search progress. simplex : np.array The current state of ...
def saveNelderMeadData(name, simplex, fvals, iters, evals)
Stores the progress of a parallel Nelder-Mead search in a text file so that it can be resumed later (after manual termination or a crash). Parameters ---------- name : string Name of the txt file in which to store search progress. simplex : np.array The current state of the simplex ...
3.2934
1.521959
2.163922
''' Reads the progress of a parallel Nelder-Mead search from a text file, as created by saveNelderMeadData(). Parameters ---------- name : string Name of the txt file from which to read search progress. Returns ------- simplex : np.array The current state of the sim...
def loadNelderMeadData(name)
Reads the progress of a parallel Nelder-Mead search from a text file, as created by saveNelderMeadData(). Parameters ---------- name : string Name of the txt file from which to read search progress. Returns ------- simplex : np.array The current state of the simplex of para...
2.816689
1.600793
1.759559
''' Minimizes the objective function using the Nelder-Mead simplex algorithm, starting from an initial parameter guess. Parameters ---------- objectiveFunction : function The function to be minimized. It should take only a single argument, which should be a list representing th...
def minimizeNelderMead(objectiveFunction, parameter_guess, verbose=False, **kwargs)
Minimizes the objective function using the Nelder-Mead simplex algorithm, starting from an initial parameter guess. Parameters ---------- objectiveFunction : function The function to be minimized. It should take only a single argument, which should be a list representing the parameters...
3.125792
2.291865
1.363864
''' Minimizes the objective function using a derivative-free Powell algorithm, starting from an initial parameter guess. Parameters ---------- objectiveFunction : function The function to be minimized. It should take only a single argument, which should be a list representing t...
def minimizePowell(objectiveFunction, parameter_guess, verbose=False)
Minimizes the objective function using a derivative-free Powell algorithm, starting from an initial parameter guess. Parameters ---------- objectiveFunction : function The function to be minimized. It should take only a single argument, which should be a list representing the parameter...
3.225044
2.335406
1.380935
''' Samples rows from the input array of data, generating a new data array with an equal number of rows (records). Rows are drawn with equal probability by default, but probabilities can be specified with weights (must sum to 1). Parameters ---------- data : np.array An array of da...
def bootstrapSampleFromData(data,weights=None,seed=0)
Samples rows from the input array of data, generating a new data array with an equal number of rows (records). Rows are drawn with equal probability by default, but probabilities can be specified with weights (must sum to 1). Parameters ---------- data : np.array An array of data, with eac...
3.293011
1.813921
1.81541
''' Calculates what consumption, market resources, and the marginal propensity to consume must have been in the previous period given model parameters and values of market resources, consumption, and MPC today. Parameters ---------- DiscFac : float Intertemporal discount factor on f...
def findNextPoint(DiscFac,Rfree,CRRA,PermGroFacCmp,UnempPrb,Rnrm,Beth,cNext,mNext,MPCnext,PFMPC)
Calculates what consumption, market resources, and the marginal propensity to consume must have been in the previous period given model parameters and values of market resources, consumption, and MPC today. Parameters ---------- DiscFac : float Intertemporal discount factor on future utilit...
5.282934
2.193279
2.408692
''' This method adds consumption at m=0 to the list of stable arm points, then constructs the consumption function as a cubic interpolation over those points. Should be run after the backshooting routine is complete. Parameters ---------- none Returns ...
def postSolve(self)
This method adds consumption at m=0 to the list of stable arm points, then constructs the consumption function as a cubic interpolation over those points. Should be run after the backshooting routine is complete. Parameters ---------- none Returns ------- ...
5.806431
2.77635
2.09139
''' Makes new consumers for the given indices. Initialized variables include aNrm, as well as time variables t_age and t_cycle. Normalized assets are drawn from a lognormal distributions given by aLvlInitMean and aLvlInitStd. Parameters ---------- which_agents ...
def simBirth(self,which_agents)
Makes new consumers for the given indices. Initialized variables include aNrm, as well as time variables t_age and t_cycle. Normalized assets are drawn from a lognormal distributions given by aLvlInitMean and aLvlInitStd. Parameters ---------- which_agents : np.array(Bool) ...
5.694027
2.422893
2.350094
''' Trivial function that returns boolean array of all False, as there is no death. Parameters ---------- None Returns ------- which_agents : np.array(bool) Boolean array of size AgentCount indicating which agents die. ''' # N...
def simDeath(self)
Trivial function that returns boolean array of all False, as there is no death. Parameters ---------- None Returns ------- which_agents : np.array(bool) Boolean array of size AgentCount indicating which agents die.
7.303961
2.084615
3.503747
''' Determine which agents switch from employment to unemployment. All unemployed agents remain unemployed until death. Parameters ---------- None Returns ------- None ''' employed = self.eStateNow == 1.0 N = int(np.sum(e...
def getShocks(self)
Determine which agents switch from employment to unemployment. All unemployed agents remain unemployed until death. Parameters ---------- None Returns ------- None
6.201181
3.4244
1.810881
''' Calculate market resources for all agents this period. Parameters ---------- None Returns ------- None ''' self.bLvlNow = self.Rfree*self.aLvlNow self.mLvlNow = self.bLvlNow + self.eStateNow
def getStates(self)
Calculate market resources for all agents this period. Parameters ---------- None Returns ------- None
10.117438
4.911678
2.059874
''' Calculate consumption for each agent this period. Parameters ---------- None Returns ------- None ''' employed = self.eStateNow == 1.0 unemployed = np.logical_not(employed) cLvlNow = np.zeros(self.AgentCount) c...
def getControls(self)
Calculate consumption for each agent this period. Parameters ---------- None Returns ------- None
4.036493
2.827651
1.427508
''' Evaluate the derivative of consumption and medical care with respect to market resources at given levels of market resources, permanent income, and medical need shocks. Parameters ---------- mLvl : np.array Market resource levels. pLvl : n...
def derivativeX(self,mLvl,pLvl,MedShk)
Evaluate the derivative of consumption and medical care with respect to market resources at given levels of market resources, permanent income, and medical need shocks. Parameters ---------- mLvl : np.array Market resource levels. pLvl : np.array ...
2.4914
1.460056
1.706373
''' Evaluate the derivative of consumption and medical care with respect to permanent income at given levels of market resources, permanent income, and medical need shocks. Parameters ---------- mLvl : np.array Market resource levels. pLvl : n...
def derivativeY(self,mLvl,pLvl,MedShk)
Evaluate the derivative of consumption and medical care with respect to permanent income at given levels of market resources, permanent income, and medical need shocks. Parameters ---------- mLvl : np.array Market resource levels. pLvl : np.array ...
2.525996
1.474414
1.71322
''' Evaluate the derivative of consumption and medical care with respect to medical need shock at given levels of market resources, permanent income, and medical need shocks. Parameters ---------- mLvl : np.array Market resource levels. pLvl :...
def derivativeZ(self,mLvl,pLvl,MedShk)
Evaluate the derivative of consumption and medical care with respect to medical need shock at given levels of market resources, permanent income, and medical need shocks. Parameters ---------- mLvl : np.array Market resource levels. pLvl : np.array ...
2.535303
1.489784
1.701792
''' Update the income process, the assets grid, the permanent income grid, the medical shock distribution, and the terminal solution. Parameters ---------- none Returns ------- none ''' self.updateIncomeProcess() self.upda...
def update(self)
Update the income process, the assets grid, the permanent income grid, the medical shock distribution, and the terminal solution. Parameters ---------- none Returns ------- none
9.686079
2.655675
3.647314
''' Constructs discrete distributions of medical preference shocks for each period in the cycle. Distributions are saved as attribute MedShkDstn, which is added to time_vary. Parameters ---------- None Returns ------- None ''' ...
def updateMedShockProcess(self)
Constructs discrete distributions of medical preference shocks for each period in the cycle. Distributions are saved as attribute MedShkDstn, which is added to time_vary. Parameters ---------- None Returns ------- None
4.770729
3.138014
1.520302
''' Update the grid of permanent income levels. Currently only works for infinite horizon models (cycles=0) and lifecycle models (cycles=1). Not clear what to do about cycles>1. Identical to version in persistent shocks model, but pLvl=0 is manually added to the grid (because ...
def updatepLvlGrid(self)
Update the grid of permanent income levels. Currently only works for infinite horizon models (cycles=0) and lifecycle models (cycles=1). Not clear what to do about cycles>1. Identical to version in persistent shocks model, but pLvl=0 is manually added to the grid (because there is no ...
7.202684
2.037005
3.535918
''' Gets permanent and transitory income shocks for this period as well as medical need shocks and the price of medical care. Parameters ---------- None Returns ------- None ''' PersistentShockConsumerType.getShocks(self) # Get pe...
def getShocks(self)
Gets permanent and transitory income shocks for this period as well as medical need shocks and the price of medical care. Parameters ---------- None Returns ------- None
3.475124
2.722493
1.276449
''' Calculates consumption and medical care for each consumer of this type using the consumption and medical care functions. Parameters ---------- None Returns ------- None ''' cLvlNow = np.zeros(self.AgentCount) + np.nan ...
def getControls(self)
Calculates consumption and medical care for each consumer of this type using the consumption and medical care functions. Parameters ---------- None Returns ------- None
4.914814
3.021294
1.626725
''' Calculates end-of-period assets for each consumer of this type. Parameters ---------- None Returns ------- None ''' self.aLvlNow = self.mLvlNow - self.cLvlNow - self.MedPriceNow*self.MedNow return None
def getPostStates(self)
Calculates end-of-period assets for each consumer of this type. Parameters ---------- None Returns ------- None
13.459542
5.370462
2.506217
''' Unpacks some of the inputs (and calculates simple objects based on them), storing the results in self for use by other methods. These include: income shocks and probabilities, medical shocks and probabilities, next period's marginal value function (etc), the probability of g...
def setAndUpdateValues(self,solution_next,IncomeDstn,LivPrb,DiscFac)
Unpacks some of the inputs (and calculates simple objects based on them), storing the results in self for use by other methods. These include: income shocks and probabilities, medical shocks and probabilities, next period's marginal value function (etc), the probability of getting the w...
3.627634
1.590467
2.280861
''' Defines CRRA utility function for this period (and its derivatives, and their inverses), saving them as attributes of self for other methods to use. Extends version from ConsIndShock models by also defining inverse marginal utility function over medical care. Parame...
def defUtilityFuncs(self)
Defines CRRA utility function for this period (and its derivatives, and their inverses), saving them as attributes of self for other methods to use. Extends version from ConsIndShock models by also defining inverse marginal utility function over medical care. Parameters -------...
10.063264
3.138224
3.206674
''' Defines the constrained portion of the consumption function as cFuncNowCnst, an attribute of self. Uses the artificial and natural borrowing constraints. Parameters ---------- BoroCnstArt : float or None Borrowing constraint for the minimum allowable (no...
def defBoroCnst(self,BoroCnstArt)
Defines the constrained portion of the consumption function as cFuncNowCnst, an attribute of self. Uses the artificial and natural borrowing constraints. Parameters ---------- BoroCnstArt : float or None Borrowing constraint for the minimum allowable (normalized) assets ...
4.355576
2.953595
1.474669
''' Finds endogenous interpolation points (x,m) for the expenditure function. Parameters ---------- EndOfPrdvP : np.array Array of end-of-period marginal values. aLvlNow : np.array Array of end-of-period asset values that yield the marginal values...
def getPointsForInterpolation(self,EndOfPrdvP,aLvlNow)
Finds endogenous interpolation points (x,m) for the expenditure function. Parameters ---------- EndOfPrdvP : np.array Array of end-of-period marginal values. aLvlNow : np.array Array of end-of-period asset values that yield the marginal values in EndO...
2.998577
2.330377
1.286735
''' Constructs a basic solution for this period, including the consumption function and marginal value function. Parameters ---------- xLvl : np.array Total expenditure points for interpolation. mLvl : np.array Corresponding market resourc...
def usePointsForInterpolation(self,xLvl,mLvl,pLvl,MedShk,interpolator)
Constructs a basic solution for this period, including the consumption function and marginal value function. Parameters ---------- xLvl : np.array Total expenditure points for interpolation. mLvl : np.array Corresponding market resource points for interpo...
4.13458
2.834554
1.458635
''' Constructs the (unconstrained) expenditure function for this period using bilinear interpolation (over permanent income and the medical shock) among an array of linear interpolations over market resources. Parameters ---------- mLvl : np.array Cor...
def makeLinearxFunc(self,mLvl,pLvl,MedShk,xLvl)
Constructs the (unconstrained) expenditure function for this period using bilinear interpolation (over permanent income and the medical shock) among an array of linear interpolations over market resources. Parameters ---------- mLvl : np.array Corresponding market re...
3.366503
2.122409
1.586171
''' Given end of period assets and end of period marginal value, construct the basic solution for this period. Parameters ---------- EndOfPrdvP : np.array Array of end-of-period marginal values. aLvl : np.array Array of end-of-period asset...
def makeBasicSolution(self,EndOfPrdvP,aLvl,interpolator)
Given end of period assets and end of period marginal value, construct the basic solution for this period. Parameters ---------- EndOfPrdvP : np.array Array of end-of-period marginal values. aLvl : np.array Array of end-of-period asset values that yield t...
3.907602
1.923744
2.031248
''' Solves a one period consumption saving problem with risky income and shocks to medical need. Parameters ---------- None Returns ------- solution : ConsumerSolution The solution to the one period problem, including a consumption ...
def solve(self)
Solves a one period consumption saving problem with risky income and shocks to medical need. Parameters ---------- None Returns ------- solution : ConsumerSolution The solution to the one period problem, including a consumption function, ...
7.730379
2.743941
2.817254
''' Find the borrowing constraint for each current state and save it as an attribute of self for use by other methods. Parameters ---------- none Returns ------- none ''' self.BoroCnstNatAll = np.zeros(self.StateCount) + ...
def defBoundary(self)
Find the borrowing constraint for each current state and save it as an attribute of self for use by other methods. Parameters ---------- none Returns ------- none
3.3894
2.877092
1.178064
''' Temporarily assume that a particular Markov state will occur in the succeeding period, and condition solver attributes on this assumption. Allows the solver to construct the future-state-conditional marginal value function (etc) for that future state. Parameters ...
def conditionOnState(self,state_index)
Temporarily assume that a particular Markov state will occur in the succeeding period, and condition solver attributes on this assumption. Allows the solver to construct the future-state-conditional marginal value function (etc) for that future state. Parameters ---------- ...
5.388177
3.163668
1.703142
''' Calculates end-of-period marginal marginal value using a pre-defined array of next period market resources in self.mNrmNext. Parameters ---------- none Returns ------- EndOfPrdvPP : np.array End-of-period marginal marginal value o...
def calcEndOfPrdvPP(self)
Calculates end-of-period marginal marginal value using a pre-defined array of next period market resources in self.mNrmNext. Parameters ---------- none Returns ------- EndOfPrdvPP : np.array End-of-period marginal marginal value of assets at each val...
4.913976
2.201867
2.231732
''' Construct the end-of-period value function conditional on next period's state. NOTE: It might be possible to eliminate this method and replace it with ConsIndShockSolver.makeEndOfPrdvFunc, but the self.X_cond variables must be renamed. Parameters ---------- ...
def makeEndOfPrdvFuncCond(self)
Construct the end-of-period value function conditional on next period's state. NOTE: It might be possible to eliminate this method and replace it with ConsIndShockSolver.makeEndOfPrdvFunc, but the self.X_cond variables must be renamed. Parameters ---------- none ...
3.725549
2.283157
1.631753
''' Construct the end-of-period marginal value function conditional on next period's state. Parameters ---------- None Returns ------- EndofPrdvPfunc_cond : MargValueFunc The end-of-period marginal value function conditional on a part...
def makeEndOfPrdvPfuncCond(self)
Construct the end-of-period marginal value function conditional on next period's state. Parameters ---------- None Returns ------- EndofPrdvPfunc_cond : MargValueFunc The end-of-period marginal value function conditional on a particular s...
3.647224
2.785828
1.309207
''' Calculates end of period marginal value (and marginal marginal) value at each aXtra gridpoint for each current state, unconditional on the future Markov state (i.e. weighting conditional end-of-period marginal value by transition probabilities). Parameters --...
def calcEndOfPrdvP(self)
Calculates end of period marginal value (and marginal marginal) value at each aXtra gridpoint for each current state, unconditional on the future Markov state (i.e. weighting conditional end-of-period marginal value by transition probabilities). Parameters ---------- non...
3.620886
2.859316
1.266347
''' Calculates human wealth and the maximum and minimum MPC for each current period state, then stores them as attributes of self for use by other methods. Parameters ---------- none Returns ------- none ''' # Upper bound on MPC a...
def calcHumWealthAndBoundingMPCs(self)
Calculates human wealth and the maximum and minimum MPC for each current period state, then stores them as attributes of self for use by other methods. Parameters ---------- none Returns ------- none
5.039477
4.329066
1.164103
''' Make a linear interpolation to represent the (unconstrained) consumption function conditional on the current period state. Parameters ---------- mNrm : np.array Array of normalized market resource values for interpolation. cNrm : np.array ...
def makeLinearcFunc(self,mNrm,cNrm)
Make a linear interpolation to represent the (unconstrained) consumption function conditional on the current period state. Parameters ---------- mNrm : np.array Array of normalized market resource values for interpolation. cNrm : np.array Array of normali...
5.411397
2.088042
2.591613
''' Make a cubic interpolation to represent the (unconstrained) consumption function conditional on the current period state. Parameters ---------- mNrm : np.array Array of normalized market resource values for interpolation. cNrm : np.array ...
def makeCubiccFunc(self,mNrm,cNrm)
Make a cubic interpolation to represent the (unconstrained) consumption function conditional on the current period state. Parameters ---------- mNrm : np.array Array of normalized market resource values for interpolation. cNrm : np.array Array of normaliz...
5.724911
2.300719
2.488314
''' Construct the value function for each current state. Parameters ---------- solution : ConsumerSolution The solution to the single period consumption-saving problem. Must have a consumption function cFunc (using cubic or linear splines) as ...
def makevFunc(self,solution)
Construct the value function for each current state. Parameters ---------- solution : ConsumerSolution The solution to the single period consumption-saving problem. Must have a consumption function cFunc (using cubic or linear splines) as a list with elements...
4.15047
2.795597
1.484645
''' Many parameters used by MarkovConsumerType are arrays. Make sure those arrays are the right shape. Parameters ---------- None Returns ------- None ''' StateCount = self.MrkvArray[0].shape[0] # Check that arrays are t...
def checkMarkovInputs(self)
Many parameters used by MarkovConsumerType are arrays. Make sure those arrays are the right shape. Parameters ---------- None Returns ------- None
4.374978
3.464204
1.26291
''' Update the terminal period solution. This method should be run when a new AgentType is created or when CRRA changes. Parameters ---------- none Returns ------- none ''' IndShockConsumerType.updateSolutionTerminal(self) ...
def updateSolutionTerminal(self)
Update the terminal period solution. This method should be run when a new AgentType is created or when CRRA changes. Parameters ---------- none Returns ------- none
3.840433
2.815885
1.363846
''' Makes new Markov consumer by drawing initial normalized assets, permanent income levels, and discrete states. Calls IndShockConsumerType.simBirth, then draws from initial Markov distribution. Parameters ---------- which_agents : np.array(Bool) Boolean arr...
def simBirth(self,which_agents)
Makes new Markov consumer by drawing initial normalized assets, permanent income levels, and discrete states. Calls IndShockConsumerType.simBirth, then draws from initial Markov distribution. Parameters ---------- which_agents : np.array(Bool) Boolean array of size self.Agen...
8.139178
3.474928
2.342258
''' Gets new Markov states and permanent and transitory income shocks for this period. Samples from IncomeDstn for each period-state in the cycle. Parameters ---------- None Returns ------- None ''' # Get new Markov states for ea...
def getShocks(self)
Gets new Markov states and permanent and transitory income shocks for this period. Samples from IncomeDstn for each period-state in the cycle. Parameters ---------- None Returns ------- None
3.726504
3.228394
1.15429
''' A slight modification of AgentType.readShocks that makes sure that MrkvNow is int, not float. Parameters ---------- None Returns ------- None ''' IndShockConsumerType.readShocks(self) self.MrkvNow = self.MrkvNow.astype(int)
def readShocks(self)
A slight modification of AgentType.readShocks that makes sure that MrkvNow is int, not float. Parameters ---------- None Returns ------- None
7.239028
2.367135
3.058139
''' Calculates consumption for each consumer of this type using the consumption functions. Parameters ---------- None Returns ------- None ''' cNrmNow = np.zeros(self.AgentCount) + np.nan for t in range(self.T_cycle): ...
def getControls(self)
Calculates consumption for each consumer of this type using the consumption functions. Parameters ---------- None Returns ------- None
4.923546
3.162806
1.556702
''' Calculates updated values of normalized market resources and permanent income level. Uses pLvlNow, aNrmNow, PermShkNow, TranShkNow. Parameters ---------- None Returns ------- None ''' pLvlPrev = self.pLvlNow aNrmPrev =...
def getStates(self)
Calculates updated values of normalized market resources and permanent income level. Uses pLvlNow, aNrmNow, PermShkNow, TranShkNow. Parameters ---------- None Returns ------- None
3.826439
2.538304
1.507479
''' Update the terminal period solution. This method should be run when a new AgentType is created or when CRRA changes. Parameters ---------- None Returns ------- None ''' RepAgentConsumerType.updateSolutionTerminal(self) ...
def updateSolutionTerminal(self)
Update the terminal period solution. This method should be run when a new AgentType is created or when CRRA changes. Parameters ---------- None Returns ------- None
5.27479
3.1709
1.663499
''' Draws a new Markov state and income shocks for the representative agent. Parameters ---------- None Returns ------- None ''' cutoffs = np.cumsum(self.MrkvArray[self.MrkvNow,:]) MrkvDraw = drawUniform(N=1,seed=self.RNG.randint(...
def getShocks(self)
Draws a new Markov state and income shocks for the representative agent. Parameters ---------- None Returns ------- None
4.337319
3.708063
1.169699
''' Calculates consumption for the representative agent using the consumption functions. Parameters ---------- None Returns ------- None ''' t = self.t_cycle[0] i = self.MrkvNow[0] self.cNrmNow = self.solution[t].cFunc[i](...
def getControls(self)
Calculates consumption for the representative agent using the consumption functions. Parameters ---------- None Returns ------- None
10.886662
4.849223
2.245033
''' Initialize this type for a new simulated history of K/L ratio. Parameters ---------- None Returns ------- None ''' self.initializeSim() self.aLvlNow = self.kInit*np.ones(self.AgentCount) # Start simulation near SS self...
def reset(self)
Initialize this type for a new simulated history of K/L ratio. Parameters ---------- None Returns ------- None
14.814819
6.030406
2.456687
''' Updates the terminal period solution for an aggregate shock consumer. Only fills in the consumption function and marginal value function. Parameters ---------- None Returns ------- None ''' cFunc_terminal = BilinearInterp(np....
def updateSolutionTerminal(self)
Updates the terminal period solution for an aggregate shock consumer. Only fills in the consumption function and marginal value function. Parameters ---------- None Returns ------- None
4.266834
2.483345
1.71818
''' 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 ...
def 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 impor...
7.625759
3.371546
2.261799
''' 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, t...
def 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 ...
4.057273
1.907816
2.126658
''' 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...
def 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 ---------- ...
5.017372
1.462048
3.431742
''' 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 Returns ------- who_dies : np.array(bool) Boolean...
def 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 Returns ------- who_dies : np.array(bool) Boolean array of size Agent...
3.160424
2.378298
1.328859
''' Returns an array of size self.AgentCount with self.RfreeNow in every entry. Parameters ---------- None Returns ------- RfreeNow : np.array Array of size self.AgentCount with risk free interest rate for each agent. ''' Rfr...
def getRfree(self)
Returns an array of size self.AgentCount with self.RfreeNow in every entry. Parameters ---------- None Returns ------- RfreeNow : np.array Array of size self.AgentCount with risk free interest rate for each agent.
6.283127
1.655485
3.795339
''' Finds the effective permanent and transitory shocks this period by combining the aggregate and idiosyncratic shocks of each type. Parameters ---------- None Returns ------- None ''' IndShockConsumerType.getShocks(self) # Updat...
def getShocks(self)
Finds the effective permanent and transitory shocks this period by combining the aggregate and idiosyncratic shocks of each type. Parameters ---------- None Returns ------- None
5.065439
2.415624
2.096948
''' Variation on AggShockConsumerType.addAggShkDstn that handles the Markov state. AggShkDstn is a list of aggregate productivity shock distributions for each Markov state. ''' if len(self.IncomeDstn[0][0]) > 3: self.IncomeDstn = self.IncomeDstnWithoutAggShock...
def 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.
4.415258
2.520653
1.751632
''' Update the terminal period solution. This method should be run when a new AgentType is created or when CRRA changes. Parameters ---------- None Returns ------- None ''' AggShockConsumerType.updateSolutionTerminal(self) ...
def updateSolutionTerminal(self)
Update the terminal period solution. This method should be run when a new AgentType is created or when CRRA changes. Parameters ---------- None Returns ------- None
4.431566
2.722193
1.62794
''' 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 MarkovConsumerTyp...
def 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...
3.329032
2.423755
1.373502
''' 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 ar...
def 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 state...
4.494213
2.197349
2.045288
''' 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 Returns ...
def 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 Returns ------- ...
4.534728
3.132879
1.447464
''' Creates the attributes TranShkAggDstn, PermShkAggDstn, and AggShkDstn. Draws on attributes TranShkAggStd, PermShkAddStd, TranShkAggCount, PermShkAggCount. Parameters ---------- None Returns ------- None ''' self.TranShkAggDstn...
def makeAggShkDstn(self)
Creates the attributes TranShkAggDstn, PermShkAggDstn, and AggShkDstn. Draws on attributes TranShkAggStd, PermShkAddStd, TranShkAggCount, PermShkAggCount. Parameters ---------- None Returns ------- None
2.881031
1.655221
1.740572
''' 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 ...
def 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...
5.597821
3.233683
1.731098
''' 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. ...
def 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 : [f...
5.005973
3.535789
1.415801
''' Use primitive parameters to set basic objects. This is an extremely stripped-down version of update for CobbDouglasEconomy. Parameters ---------- none Returns ------- none ''' self.kSS = 1.0 self.MSS = 1.0 sel...
def update(self)
Use primitive parameters to set basic objects. This is an extremely stripped-down version of update for CobbDouglasEconomy. Parameters ---------- none Returns ------- none
5.145731
2.958326
1.739407
''' 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 --...
def 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 ---------- Non...
5.07751
2.378675
2.134596
''' 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 --...
def 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 ---------- Non...
4.544246
2.394601
1.897705
''' 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 Returns ...
def 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 Returns ------- ...
11.497344
3.401436
3.380144
''' 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 Returns...
def 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 Returns ------- ...
4.04113
2.257476
1.79011
''' Creates the attributes TranShkAggDstn, PermShkAggDstn, and AggShkDstn. Draws on attributes TranShkAggStd, PermShkAddStd, TranShkAggCount, PermShkAggCount. This version accounts for the Markov macroeconomic state. Parameters ---------- None Returns ...
def 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 Returns ------- ...
2.658353
1.610274
1.650869
''' 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 ---...
def 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...
3.521977
2.528301
1.393021
''' 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. See documentation for calcRandW for more information. ''' MrkvNow = self.MrkvNow_his...
def 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. See documentation for calcRandW for more information.
13.501414
2.992998
4.511001
''' 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] ...
def 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...
4.730549
3.315587
1.426761
''' Finds the difference between simulated and target capital to income ratio in an economy when a given parameter has heterogeneity according to some distribution. Parameters ---------- Economy : cstwMPCmarket An object representing the entire economy, containing the various AgentTypes...
def getKYratioDifference(Economy,param_name,param_count,center,spread,dist_type)
Finds the difference between simulated and target capital to income ratio in an economy when a given parameter has heterogeneity according to some distribution. Parameters ---------- Economy : cstwMPCmarket An object representing the entire economy, containing the various AgentTypes as an attri...
6.048744
2.131835
2.837341
''' Finds the sum of squared distances between simulated and target Lorenz points in an economy when a given parameter has heterogeneity according to some distribution. The class of distribution and a measure of spread are given as inputs, but the measure of centrality such that the capital to inco...
def findLorenzDistanceAtTargetKY(Economy,param_name,param_count,center_range,spread,dist_type)
Finds the sum of squared distances between simulated and target Lorenz points in an economy when a given parameter has heterogeneity according to some distribution. The class of distribution and a measure of spread are given as inputs, but the measure of centrality such that the capital to income ratio mat...
5.6942
2.317508
2.457036
''' Calculates the steady state proportions of each age given survival probability sequence LivPrb. Assumes that agents who die are replaced by a newborn agent with t_age=0. Parameters ---------- LivPrb : [float] Sequence of survival probabilities in ordinary chronological order. Has l...
def calcStationaryAgeDstn(LivPrb,terminal_period)
Calculates the steady state proportions of each age given survival probability sequence LivPrb. Assumes that agents who die are replaced by a newborn agent with t_age=0. Parameters ---------- LivPrb : [float] Sequence of survival probabilities in ordinary chronological order. Has length T_cycl...
4.136896
1.730014
2.39125
''' An alternative method for constructing the income process in the infinite horizon model. Parameters ---------- none Returns ------- none ''' if self.cycles == 0: tax_rate = (self.IncUnemp*self.UnempPrb)/((1.0-self.UnempPrb...
def updateIncomeProcess(self)
An alternative method for constructing the income process in the infinite horizon model. Parameters ---------- none Returns ------- none
4.045452
3.489318
1.159382
''' Solves the cstwMPCmarket. ''' if self.AggShockBool: for agent in self.agents: agent.getEconomyData(self) Market.solve(self) else: self.solveAgents() self.makeHistory()
def solve(self)
Solves the cstwMPCmarket.
15.055676
6.797852
2.21477
''' The millRule for this class simply calls the method calcStats. ''' self.calcStats(aLvlNow,pLvlNow,MPCnow,TranShkNow,EmpNow,t_age,LorenzBool,ManyStatsBool) if self.AggShockBool: return self.calcRandW(aLvlNow,pLvlNow) else: # These variables are tracked but ...
def millRule(self,aLvlNow,pLvlNow,MPCnow,TranShkNow,EmpNow,t_age,LorenzBool,ManyStatsBool)
The millRule for this class simply calls the method calcStats.
5.633596
4.029594
1.398055
''' Distributes heterogeneous values of one parameter to the AgentTypes in self.agents. Parameters ---------- param_name : string Name of the parameter to be assigned. param_count : int Number of different values the parameter will take on. ...
def distributeParams(self,param_name,param_count,center,spread,dist_type)
Distributes heterogeneous values of one parameter to the AgentTypes in self.agents. Parameters ---------- param_name : string Name of the parameter to be assigned. param_count : int Number of different values the parameter will take on. center : float ...
5.074802
3.599065
1.410033
''' Returns the difference between the simulated capital to income ratio and the target ratio. Can only be run after solving all AgentTypes and running makeHistory. Parameters ---------- None Returns ------- diff : float Difference be...
def calcKYratioDifference(self)
Returns the difference between the simulated capital to income ratio and the target ratio. Can only be run after solving all AgentTypes and running makeHistory. Parameters ---------- None Returns ------- diff : float Difference between simulated and ...
10.175361
3.71946
2.735709
''' Returns the sum of squared differences between simulated and target Lorenz points. Parameters ---------- None Returns ------- dist : float Sum of squared distances between simulated and target Lorenz points (sqrt) ''' Lore...
def calcLorenzDistance(self)
Returns the sum of squared differences between simulated and target Lorenz points. Parameters ---------- None Returns ------- dist : float Sum of squared distances between simulated and target Lorenz points (sqrt)
4.359365
2.679512
1.626925
''' Evaluate the first derivative with respect to market resources of the marginal value function at given levels of market resources m and per- manent income p. Parameters ---------- m : float or np.array Market resources whose value is to be calcuat...
def derivativeX(self,m,p)
Evaluate the first derivative with respect to market resources of the marginal value function at given levels of market resources m and per- manent income p. Parameters ---------- m : float or np.array Market resources whose value is to be calcuated. p : floa...
7.594263
1.944306
3.905899
''' Unpacks some of the inputs (and calculates simple objects based on them), storing the results in self for use by other methods. These include: income shocks and probabilities, next period's marginal value function (etc), the probability of getting the worst income shock next...
def setAndUpdateValues(self,solution_next,IncomeDstn,LivPrb,DiscFac)
Unpacks some of the inputs (and calculates simple objects based on them), storing the results in self for use by other methods. These include: income shocks and probabilities, next period's marginal value function (etc), the probability of getting the worst income shock next period, the...
3.564502
2.07857
1.714881
''' Defines the constrained portion of the consumption function as cFuncNowCnst, an attribute of self. Parameters ---------- BoroCnstArt : float or None Borrowing constraint for the minimum allowable assets to end the period with. If it is less t...
def defBoroCnst(self,BoroCnstArt)
Defines the constrained portion of the consumption function as cFuncNowCnst, an attribute of self. Parameters ---------- BoroCnstArt : float or None Borrowing constraint for the minimum allowable assets to end the period with. If it is less than the natural borr...
3.135195
2.437148
1.28642
''' Prepare to calculate end-of-period marginal value by creating an array of market resources that the agent could have next period, considering the grid of end-of-period normalized assets, the grid of persistent income levels, and the distribution of shocks he might experience ...
def prepareToCalcEndOfPrdvP(self)
Prepare to calculate end-of-period marginal value by creating an array of market resources that the agent could have next period, considering the grid of end-of-period normalized assets, the grid of persistent income levels, and the distribution of shocks he might experience next period. ...
3.15658
2.159738
1.461557
''' Calculates end-of-period marginal value of assets at each state space point in aLvlNow x pLvlNow. Does so by taking a weighted sum of next period marginal values across income shocks (in preconstructed grids self.mLvlNext x self.pLvlNext). Parameters --------...
def calcEndOfPrdvP(self)
Calculates end-of-period marginal value of assets at each state space point in aLvlNow x pLvlNow. Does so by taking a weighted sum of next period marginal values across income shocks (in preconstructed grids self.mLvlNext x self.pLvlNext). Parameters ---------- None ...
7.055632
1.834329
3.846438
''' Construct the end-of-period value function for this period, storing it as an attribute of self for use by other methods. Parameters ---------- EndOfPrdvP : np.array Array of end-of-period marginal value of assets corresponding to the asset val...
def makeEndOfPrdvFunc(self,EndOfPrdvP)
Construct the end-of-period value function for this period, storing it as an attribute of self for use by other methods. Parameters ---------- EndOfPrdvP : np.array Array of end-of-period marginal value of assets corresponding to the asset values in self.aLvlNow ...
3.74056
3.056656
1.223742
''' Finds endogenous interpolation points (c,m) for the consumption function. Parameters ---------- EndOfPrdvP : np.array Array of end-of-period marginal values. aLvlNow : np.array Array of end-of-period asset values that yield the marginal values...
def getPointsForInterpolation(self,EndOfPrdvP,aLvlNow)
Finds endogenous interpolation points (c,m) for the consumption function. Parameters ---------- EndOfPrdvP : np.array Array of end-of-period marginal values. aLvlNow : np.array Array of end-of-period asset values that yield the marginal values in EndO...
3.43346
2.300444
1.49252
''' Constructs a basic solution for this period, including the consumption function and marginal value function. Parameters ---------- cLvl : np.array Consumption points for interpolation. mLvl : np.array Corresponding market resource poin...
def usePointsForInterpolation(self,cLvl,mLvl,pLvl,interpolator)
Constructs a basic solution for this period, including the consumption function and marginal value function. Parameters ---------- cLvl : np.array Consumption points for interpolation. mLvl : np.array Corresponding market resource points for interpolation...
4.35387
2.034942
2.139555
''' Given end of period assets and end of period marginal value, construct the basic solution for this period. Parameters ---------- EndOfPrdvP : np.array Array of end-of-period marginal values. aLvl : np.array Array of end-of-period asset...
def makeBasicSolution(self,EndOfPrdvP,aLvl,pLvl,interpolator)
Given end of period assets and end of period marginal value, construct the basic solution for this period. Parameters ---------- EndOfPrdvP : np.array Array of end-of-period marginal values. aLvl : np.array Array of end-of-period asset values that yield t...
3.660952
1.729243
2.117084