diff --git a/HARK/ConsumptionSaving/ConsAggShockModel.py b/HARK/ConsumptionSaving/ConsAggShockModel.py index 026304dff..cf9c8c72a 100644 --- a/HARK/ConsumptionSaving/ConsAggShockModel.py +++ b/HARK/ConsumptionSaving/ConsAggShockModel.py @@ -16,7 +16,7 @@ CRRAutility_invP, CRRAutility_inv, combineIndepDstns,\ approxMeanOneLognormal from HARK.simulation import drawDiscrete, drawUniform -from .ConsIndShockModel import ConsumerSolution, IndShockConsumerType +from HARK.ConsumptionSaving.ConsIndShockModel import ConsumerSolution, IndShockConsumerType from HARK import HARKobject, Market, AgentType from copy import deepcopy import matplotlib.pyplot as plt @@ -1753,7 +1753,7 @@ def __init__(self,AFunc): ############################################################################### def main(): - from . import ConsumerParameters as Params + import HARK.ConsumptionSaving.ConsumerParameters as Params from time import clock from HARK.utilities import plotFuncs mystr = lambda number : "{:.4f}".format(number) @@ -1793,6 +1793,7 @@ def main(): mMin = AggShockExample.solution[0].mNrmMin(M) c_at_this_M = AggShockExample.cFunc[0](m_grid+mMin,M*np.ones_like(m_grid)) plt.plot(m_grid+mMin,c_at_this_M) + plt.ylim(0.,None) plt.show() if solve_agg_shocks_market: @@ -1813,6 +1814,7 @@ def main(): mMin = AggShockExample.solution[0].mNrmMin(M) c_at_this_M = AggShockExample.cFunc[0](m_grid+mMin,M*np.ones_like(m_grid)) plt.plot(m_grid+mMin,c_at_this_M) + plt.ylim(0.,None) plt.show() ######### EXAMPLE IMPLEMENTATIONS OF AggShockMarkovConsumerType ########### @@ -1843,6 +1845,7 @@ def main(): mMin = AggShockMrkvExample.solution[0].mNrmMin[i](M) c_at_this_M = AggShockMrkvExample.cFunc[0][i](m_grid+mMin,M*np.ones_like(m_grid)) plt.plot(m_grid+mMin,c_at_this_M) + plt.ylim(0.,None) plt.show() if solve_markov_market: @@ -1861,6 +1864,7 @@ def main(): mMin = AggShockMrkvExample.solution[0].mNrmMin[i](M) c_at_this_M = AggShockMrkvExample.cFunc[0][i](m_grid+mMin,M*np.ones_like(m_grid)) plt.plot(m_grid+mMin,c_at_this_M) + plt.ylim(0.,None) plt.show() if solve_krusell_smith: diff --git a/HARK/ConsumptionSaving/ConsGenIncProcessModel.py b/HARK/ConsumptionSaving/ConsGenIncProcessModel.py index b81bedff7..b81cf6042 100644 --- a/HARK/ConsumptionSaving/ConsGenIncProcessModel.py +++ b/HARK/ConsumptionSaving/ConsGenIncProcessModel.py @@ -17,7 +17,7 @@ CRRAutility_invP, CRRAutility_inv, CRRAutilityP_invP,\ getPercentiles from HARK.simulation import drawLognormal, drawDiscrete, drawUniform -from .ConsIndShockModel import ConsIndShockSetup, ConsumerSolution, IndShockConsumerType +from HARK.ConsumptionSaving.ConsIndShockModel import ConsIndShockSetup, ConsumerSolution, IndShockConsumerType utility = CRRAutility utilityP = CRRAutilityP @@ -1276,7 +1276,7 @@ def updatepLvlNextFunc(self): ############################################################################### def main(): - from . import ConsumerParameters as Params + import HARK.ConsumptionSaving.ConsumerParameters as Params from HARK.utilities import plotFuncs from time import clock import matplotlib.pyplot as plt @@ -1306,6 +1306,7 @@ def main(): C = ExplicitExample.solution[0].cFunc(M_temp,p*np.ones_like(M_temp)) plt.plot(M_temp,C) plt.xlim(0.,20.) + plt.ylim(0.,None) plt.xlabel('Market resource level mLvl') plt.ylabel('Consumption level cLvl') plt.show() @@ -1328,6 +1329,7 @@ def main(): C = ExplicitExample.solution[0].cFunc(M_temp,p*np.ones_like(M_temp)) plt.plot(M_temp/p,C/p) plt.xlim(0.,20.) + plt.ylim(0.,None) plt.xlabel('Normalized market resources mNrm') plt.ylabel('Normalized consumption cNrm') plt.show() @@ -1382,6 +1384,7 @@ def main(): C = PersistentExample.solution[0].cFunc(M_temp,p*np.ones_like(M_temp)) plt.plot(M_temp,C) plt.xlim(0.,20.) + plt.ylim(0.,None) plt.xlabel('Market resource level mLvl') plt.ylabel('Consumption level cLvl') plt.show() diff --git a/HARK/ConsumptionSaving/ConsIndShockModel.py b/HARK/ConsumptionSaving/ConsIndShockModel.py index 782321fed..40ec41345 100644 --- a/HARK/ConsumptionSaving/ConsIndShockModel.py +++ b/HARK/ConsumptionSaving/ConsIndShockModel.py @@ -2426,7 +2426,7 @@ def constructAssetsGrid(parameters): #################################################################################################### def main(): - from . import ConsumerParameters as Params + import HARK.ConsumptionSaving.ConsumerParameters as Params from HARK.utilities import plotFuncsDer, plotFuncs from time import clock mystr = lambda number : "{:.4f}".format(number) diff --git a/HARK/ConsumptionSaving/ConsMarkovModel.py b/HARK/ConsumptionSaving/ConsMarkovModel.py index 73affbaff..74f196cfe 100644 --- a/HARK/ConsumptionSaving/ConsMarkovModel.py +++ b/HARK/ConsumptionSaving/ConsMarkovModel.py @@ -9,10 +9,8 @@ from builtins import range from copy import deepcopy import numpy as np -from .ConsIndShockModel import ConsIndShockSolver, ValueFunc, MargValueFunc, ConsumerSolution, IndShockConsumerType -from .ConsAggShockModel import AggShockConsumerType -from HARK.utilities import combineIndepDstns, warnings # Because of "patch" to warnings modules -from HARK import Market, HARKobject +from HARK.ConsumptionSaving.ConsIndShockModel import ConsIndShockSolver, ValueFunc, \ + MargValueFunc, ConsumerSolution, IndShockConsumerType from HARK.simulation import drawDiscrete, drawUniform from HARK.interpolation import CubicInterp, LowerEnvelope, LinearInterp from HARK.utilities import CRRAutility, CRRAutilityP, CRRAutilityPP, CRRAutilityP_inv, \ @@ -974,7 +972,7 @@ def makeEulerErrorFunc(self,mMax=100,approx_inc_dstn=True): ############################################################################### def main(): - from . import ConsumerParameters as Params + import HARK.ConsumptionSaving.ConsumerParameters as Params from HARK.utilities import plotFuncs from time import clock from copy import copy @@ -1026,7 +1024,7 @@ def main(): start_time = clock() SerialUnemploymentExample.solve() end_time = clock() - print('Solving a Markov consumer took ' + mystr(end_time-start_time) + ' seconds.') + print('Solving a Markov consumer with serially correlated unemployment took ' + mystr(end_time-start_time) + ' seconds.') print('Consumption functions for each discrete state:') plotFuncs(SerialUnemploymentExample.solution[0].cFunc,0,50) if SerialUnemploymentExample.vFuncBool: diff --git a/HARK/ConsumptionSaving/ConsMedModel.py b/HARK/ConsumptionSaving/ConsMedModel.py index 13719c77c..8744a898b 100644 --- a/HARK/ConsumptionSaving/ConsMedModel.py +++ b/HARK/ConsumptionSaving/ConsMedModel.py @@ -11,14 +11,13 @@ from HARK.utilities import approxLognormal, addDiscreteOutcomeConstantMean, CRRAutilityP_inv,\ CRRAutility, CRRAutility_inv, CRRAutility_invP, CRRAutilityPP,\ makeGridExpMult, NullFunc -from HARK.simulation import drawLognormal -from .ConsIndShockModel import ConsumerSolution +from HARK.ConsumptionSaving.ConsIndShockModel import ConsumerSolution from HARK.interpolation import BilinearInterpOnInterp1D, TrilinearInterp, BilinearInterp, CubicInterp,\ LinearInterp, LowerEnvelope3D, UpperEnvelope, LinearInterpOnInterp1D,\ VariableLowerBoundFunc3D -from .ConsGenIncProcessModel import ConsGenIncProcessSolver, PersistentShockConsumerType,\ - ValueFunc2D, MargValueFunc2D, MargMargValueFunc2D, \ - VariableLowerBoundFunc2D +from HARK.ConsumptionSaving.ConsGenIncProcessModel import ConsGenIncProcessSolver,\ + PersistentShockConsumerType, ValueFunc2D, MargValueFunc2D,\ + MargMargValueFunc2D, VariableLowerBoundFunc2D from copy import deepcopy utility_inv = CRRAutility_inv @@ -1359,7 +1358,7 @@ def solveConsMedShock(solution_next,IncomeDstn,MedShkDstn,LivPrb,DiscFac,CRRA,CR ############################################################################### def main(): - from . import ConsumerParameters as Params + import HARK.ConsumptionSaving.ConsumerParameters as Params from HARK.utilities import CRRAutility_inv from time import clock import matplotlib.pyplot as plt diff --git a/HARK/ConsumptionSaving/ConsPrefShockModel.py b/HARK/ConsumptionSaving/ConsPrefShockModel.py index f83032c68..18f27c626 100644 --- a/HARK/ConsumptionSaving/ConsPrefShockModel.py +++ b/HARK/ConsumptionSaving/ConsPrefShockModel.py @@ -12,7 +12,7 @@ from builtins import range import numpy as np from HARK.utilities import approxMeanOneLognormal -from .ConsIndShockModel import IndShockConsumerType, ConsumerSolution, ConsIndShockSolver, \ +from HARK.ConsumptionSaving.ConsIndShockModel import IndShockConsumerType, ConsumerSolution, ConsIndShockSolver, \ ValueFunc, MargValueFunc, KinkedRconsumerType, ConsKinkedRsolver from HARK.interpolation import LinearInterpOnInterp1D, LinearInterp, CubicInterp, LowerEnvelope @@ -594,7 +594,7 @@ def solveConsKinkyPref(solution_next,IncomeDstn,PrefShkDstn, ############################################################################### def main(): - from . import ConsumerParameters as Params + import HARK.ConsumptionSaving.ConsumerParameters as Params import matplotlib.pyplot as plt from HARK.utilities import plotFuncs from time import clock @@ -618,6 +618,8 @@ def main(): PrefShk = PrefShockExample.PrefShkDstn[0][1][j] c = PrefShockExample.solution[0].cFunc(m,PrefShk*np.ones_like(m)) plt.plot(m,c) + plt.xlim([0.,None]) + plt.ylim([0.,None]) plt.show() print('Consumption function (and MPC) when shock=1:') @@ -625,6 +627,8 @@ def main(): k = PrefShockExample.solution[0].cFunc.derivativeX(m,np.ones_like(m)) plt.plot(m,c) plt.plot(m,k) + plt.xlim([0.,None]) + plt.ylim([0.,None]) plt.show() if PrefShockExample.vFuncBool: @@ -657,6 +661,7 @@ def main(): PrefShk = KinkyPrefExample.PrefShkDstn[0][1][j] c = KinkyPrefExample.solution[0].cFunc(m,PrefShk*np.ones_like(m)) plt.plot(m,c) + plt.ylim([0.,None]) plt.show() print('Consumption function (and MPC) when shock=1:') @@ -664,6 +669,7 @@ def main(): k = KinkyPrefExample.solution[0].cFunc.derivativeX(m,np.ones_like(m)) plt.plot(m,c) plt.plot(m,k) + plt.ylim([0.,None]) plt.show() if KinkyPrefExample.vFuncBool: diff --git a/HARK/ConsumptionSaving/ConsRepAgentModel.py b/HARK/ConsumptionSaving/ConsRepAgentModel.py index 82d0179ae..2b9b935e4 100644 --- a/HARK/ConsumptionSaving/ConsRepAgentModel.py +++ b/HARK/ConsumptionSaving/ConsRepAgentModel.py @@ -11,7 +11,7 @@ import numpy as np from HARK.interpolation import LinearInterp from HARK.simulation import drawUniform, drawDiscrete -from .ConsIndShockModel import IndShockConsumerType, ConsumerSolution, MargValueFunc +from HARK.ConsumptionSaving.ConsIndShockModel import IndShockConsumerType, ConsumerSolution, MargValueFunc def solveConsRepAgent(solution_next,DiscFac,CRRA,IncomeDstn,CapShare,DeprFac,PermGroFac,aXtraGrid): ''' @@ -331,7 +331,7 @@ def main(): from copy import deepcopy from time import clock from HARK.utilities import plotFuncs - from . import ConsumerParameters as Params + import HARK.ConsumptionSaving.ConsumerParameters as Params # Make a quick example dictionary RA_params = deepcopy(Params.init_idiosyncratic_shocks) diff --git a/HARK/ConsumptionSaving/RepAgentModel.py b/HARK/ConsumptionSaving/RepAgentModel.py index dbeea42af..6dbae740a 100644 --- a/HARK/ConsumptionSaving/RepAgentModel.py +++ b/HARK/ConsumptionSaving/RepAgentModel.py @@ -1,384 +1,11 @@ ''' -This module contains models for solving representative agent macroeconomic models. -This stands in contrast to all other model modules in HARK, which (unsurprisingly) -take a heterogeneous agents approach. In these models, all attributes are either -time invariant or exist on a short cycle. +This file appears to be an old version of what is now ConsRepAgentModel.py. +Its previous contents have been entirely removed and replaced with a universal +import from ConsRepAgentModel. Whenever a user imports from this file, they +will get a warning that they should import from ConsRepAgentModel instead. ''' -from __future__ import division, print_function -from __future__ import absolute_import -from builtins import str -from builtins import range -import numpy as np -from HARK.interpolation import LinearInterp -from HARK.simulation import drawUniform, drawDiscrete -from .ConsIndShockModel import IndShockConsumerType, ConsumerSolution, MargValueFunc -def solveConsRepAgent(solution_next,DiscFac,CRRA,IncomeDstn,CapShare,DeprFac,PermGroFac,aXtraGrid): - ''' - Solve one period of the simple representative agent consumption-saving model. - - Parameters - ---------- - solution_next : ConsumerSolution - Solution to the next period's problem (i.e. previous iteration). - DiscFac : float - Intertemporal discount factor for future utility. - CRRA : float - Coefficient of relative risk aversion. - IncomeDstn : [np.array] - A list containing three 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, permanent shocks, transitory shocks. - CapShare : float - Capital's share of income in Cobb-Douglas production function. - DeprFac : float - Depreciation rate of capital. - PermGroFac : float - Expected permanent income growth factor at the end of this period. - aXtraGrid : np.array - Array of "extra" end-of-period asset values-- assets above the - absolute minimum acceptable level. In this model, the minimum acceptable - level is always zero. - - Returns - ------- - solution_now : ConsumerSolution - Solution to this period's problem (new iteration). - ''' - # Unpack next period's solution and the income distribution - vPfuncNext = solution_next.vPfunc - ShkPrbsNext = IncomeDstn[0] - PermShkValsNext = IncomeDstn[1] - TranShKValsNext = IncomeDstn[2] - - # Make tiled versions of end-of-period assets, shocks, and probabilities - aNrmNow = aXtraGrid - aNrmCount = aNrmNow.size - ShkCount = ShkPrbsNext.size - aNrm_tiled = np.tile(np.reshape(aNrmNow,(aNrmCount,1)),(1,ShkCount)) - - # Tile arrays of the income shocks and put them into useful shapes - PermShkVals_tiled = np.tile(np.reshape(PermShkValsNext,(1,ShkCount)),(aNrmCount,1)) - TranShkVals_tiled = np.tile(np.reshape(TranShKValsNext,(1,ShkCount)),(aNrmCount,1)) - ShkPrbs_tiled = np.tile(np.reshape(ShkPrbsNext,(1,ShkCount)),(aNrmCount,1)) - - # Calculate next period's capital-to-permanent-labor ratio under each combination - # of end-of-period assets and shock realization - kNrmNext = aNrm_tiled/(PermGroFac*PermShkVals_tiled) - - # Calculate next period's market resources - KtoLnext = kNrmNext/TranShkVals_tiled - RfreeNext = 1. - DeprFac + CapShare*KtoLnext**(CapShare-1.) - wRteNext = (1.-CapShare)*KtoLnext**CapShare - mNrmNext = RfreeNext*kNrmNext + wRteNext*TranShkVals_tiled - - # Calculate end-of-period marginal value of assets for the RA - vPnext = vPfuncNext(mNrmNext) - EndOfPrdvP = DiscFac*np.sum(RfreeNext*(PermGroFac*PermShkVals_tiled)**(-CRRA)*vPnext*ShkPrbs_tiled,axis=1) - - # Invert the first order condition to get consumption, then find endogenous gridpoints - cNrmNow = EndOfPrdvP**(-1./CRRA) - mNrmNow = aNrmNow + cNrmNow - - # Construct the consumption function and the marginal value function - cFuncNow = LinearInterp(np.insert(mNrmNow,0,0.0),np.insert(cNrmNow,0,0.0)) - vPfuncNow = MargValueFunc(cFuncNow,CRRA) - - # Construct and return the solution for this period - solution_now = ConsumerSolution(cFunc=cFuncNow,vPfunc=vPfuncNow) - return solution_now - - - -def solveConsRepAgentMarkov(solution_next,MrkvArray,DiscFac,CRRA,IncomeDstn,CapShare,DeprFac,PermGroFac,aXtraGrid): - ''' - Solve one period of the simple representative agent consumption-saving model. - This version supports a discrete Markov process. - - Parameters - ---------- - solution_next : ConsumerSolution - Solution to the next period's problem (i.e. previous iteration). - MrkvArray : np.array - Markov transition array between this period and next period. - DiscFac : float - Intertemporal discount factor for future utility. - CRRA : float - Coefficient of relative risk aversion. - IncomeDstn : [[np.array]] - A list of lists containing three 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, permanent shocks, transitory shocks. - CapShare : float - Capital's share of income in Cobb-Douglas production function. - DeprFac : float - Depreciation rate of capital. - PermGroFac : [float] - Expected permanent income growth factor for each state we could be in - next period. - aXtraGrid : np.array - Array of "extra" end-of-period asset values-- assets above the - absolute minimum acceptable level. In this model, the minimum acceptable - level is always zero. - - Returns - ------- - solution_now : ConsumerSolution - Solution to this period's problem (new iteration). - ''' - # Define basic objects - StateCount = MrkvArray.shape[0] - aNrmNow = aXtraGrid - aNrmCount = aNrmNow.size - EndOfPrdvP_cond = np.zeros((StateCount,aNrmCount)) + np.nan - - # Loop over *next period* states, calculating conditional EndOfPrdvP - for j in range(StateCount): - # Define next-period-state conditional objects - vPfuncNext = solution_next.vPfunc[j] - ShkPrbsNext = IncomeDstn[j][0] - PermShkValsNext = IncomeDstn[j][1] - TranShKValsNext = IncomeDstn[j][2] - - # Make tiled versions of end-of-period assets, shocks, and probabilities - ShkCount = ShkPrbsNext.size - aNrm_tiled = np.tile(np.reshape(aNrmNow,(aNrmCount,1)),(1,ShkCount)) - - # Tile arrays of the income shocks and put them into useful shapes - PermShkVals_tiled = np.tile(np.reshape(PermShkValsNext,(1,ShkCount)),(aNrmCount,1)) - TranShkVals_tiled = np.tile(np.reshape(TranShKValsNext,(1,ShkCount)),(aNrmCount,1)) - ShkPrbs_tiled = np.tile(np.reshape(ShkPrbsNext,(1,ShkCount)),(aNrmCount,1)) - - # Calculate next period's capital-to-permanent-labor ratio under each combination - # of end-of-period assets and shock realization - kNrmNext = aNrm_tiled/(PermGroFac[j]*PermShkVals_tiled) - - # Calculate next period's market resources - KtoLnext = kNrmNext/TranShkVals_tiled - RfreeNext = 1. - DeprFac + CapShare*KtoLnext**(CapShare-1.) - wRteNext = (1.-CapShare)*KtoLnext**CapShare - mNrmNext = RfreeNext*kNrmNext + wRteNext*TranShkVals_tiled - - # Calculate end-of-period marginal value of assets for the RA - vPnext = vPfuncNext(mNrmNext) - EndOfPrdvP_cond[j,:] = DiscFac*np.sum(RfreeNext*(PermGroFac[j]*PermShkVals_tiled)**(-CRRA)*vPnext*ShkPrbs_tiled,axis=1) - - # Apply the Markov transition matrix to get unconditional end-of-period marginal value - EndOfPrdvP = np.dot(MrkvArray,EndOfPrdvP_cond) - - # Construct the consumption function and marginal value function for each discrete state - cFuncNow_list = [] - vPfuncNow_list = [] - for i in range(StateCount): - # Invert the first order condition to get consumption, then find endogenous gridpoints - cNrmNow = EndOfPrdvP[i,:]**(-1./CRRA) - mNrmNow = aNrmNow + cNrmNow - - # Construct the consumption function and the marginal value function - cFuncNow_list.append(LinearInterp(np.insert(mNrmNow,0,0.0),np.insert(cNrmNow,0,0.0))) - vPfuncNow_list.append(MargValueFunc(cFuncNow_list[-1],CRRA)) - - # Construct and return the solution for this period - solution_now = ConsumerSolution(cFunc=cFuncNow_list,vPfunc=vPfuncNow_list) - return solution_now - - - -class RepAgentConsumerType(IndShockConsumerType): - ''' - A class for representing representative agents with inelastic labor supply. - ''' - time_inv_ = IndShockConsumerType.time_inv_ + ['CapShare','DeprFac'] - - def __init__(self,time_flow=True,**kwds): - ''' - Make a new instance of a representative agent. - - Parameters - ---------- - time_flow : boolean - Whether time is currently "flowing" forward for this instance. - - Returns - ------- - None - ''' - IndShockConsumerType.__init__(self,cycles=0,time_flow=time_flow,**kwds) - self.AgentCount = 1 # Hardcoded, because this is rep agent - self.solveOnePeriod = solveConsRepAgent - self.delFromTimeInv('Rfree','BoroCnstArt','vFuncBool','CubicBool') - - def getStates(self): - ''' - Calculates updated values of normalized market resources and permanent income level. - Uses pLvlNow, aNrmNow, PermShkNow, TranShkNow. - - Parameters - ---------- - None - - Returns - ------- - None - ''' - pLvlPrev = self.pLvlNow - aNrmPrev = self.aNrmNow - - # Calculate new states: normalized market resources and permanent income level - self.pLvlNow = pLvlPrev*self.PermShkNow # Updated permanent income level - self.kNrmNow = aNrmPrev/self.PermShkNow - self.yNrmNow = self.kNrmNow**self.CapShare*self.TranShkNow**(1.-self.CapShare) - self.Rfree = 1. + self.CapShare*self.kNrmNow**(self.CapShare-1.)*self.TranShkNow**(1.-self.CapShare) - self.DeprFac - self.wRte = (1.-self.CapShare)*self.kNrmNow**self.CapShare*self.TranShkNow**(-self.CapShare) - self.mNrmNow = self.Rfree*self.kNrmNow + self.wRte*self.TranShkNow - - -class RepAgentMarkovConsumerType(RepAgentConsumerType): - ''' - A class for representing representative agents with inelastic labor supply - and a discrete MarkovState - ''' - time_inv_ = RepAgentConsumerType.time_inv_ + ['MrkvArray'] - - def __init__(self,time_flow=True,**kwds): - ''' - Make a new instance of a representative agent with Markov state. - - Parameters - ---------- - time_flow : boolean - Whether time is currently "flowing" forward for this instance. - - Returns - ------- - None - ''' - RepAgentConsumerType.__init__(self,time_flow=time_flow,**kwds) - self.solveOnePeriod = solveConsRepAgentMarkov - - 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 - ''' - RepAgentConsumerType.updateSolutionTerminal(self) - - # Make replicated terminal period solution - StateCount = self.MrkvArray.shape[0] - self.solution_terminal.cFunc = StateCount*[self.cFunc_terminal_] - self.solution_terminal.vPfunc = StateCount*[self.solution_terminal.vPfunc] - self.solution_terminal.mNrmMin = StateCount*[self.solution_terminal.mNrmMin] - - - def getShocks(self): - ''' - 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(0,2**31-1)) - self.MrkvNow = np.searchsorted(cutoffs,MrkvDraw) - - t = self.t_cycle[0] - i = self.MrkvNow[0] - IncomeDstnNow = self.IncomeDstn[t-1][i] # set current income distribution - PermGroFacNow = self.PermGroFac[t-1][i] # and permanent growth factor - Indices = np.arange(IncomeDstnNow[0].size) # just a list of integers - # Get random draws of income shocks from the discrete distribution - EventDraw = drawDiscrete(N=1,X=Indices,P=IncomeDstnNow[0],exact_match=False,seed=self.RNG.randint(0,2**31-1)) - PermShkNow = IncomeDstnNow[1][EventDraw]*PermGroFacNow # permanent "shock" includes expected growth - TranShkNow = IncomeDstnNow[2][EventDraw] - self.PermShkNow = np.array(PermShkNow) - self.TranShkNow = np.array(TranShkNow) - - - def getControls(self): - ''' - 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](self.mNrmNow) - - -############################################################################### -def main(): - from copy import deepcopy - from time import clock - from HARK.utilities import plotFuncs - from . import ConsumerParameters as Params - - # Make a quick example dictionary - RA_params = deepcopy(Params.init_idiosyncratic_shocks) - RA_params['DeprFac'] = 0.05 - RA_params['CapShare'] = 0.36 - RA_params['UnempPrb'] = 0.0 - RA_params['LivPrb'] = [1.0] - - # Make and solve a rep agent model - RAexample = RepAgentConsumerType(**RA_params) - t_start = clock() - RAexample.solve() - t_end = clock() - print('Solving a representative agent problem took ' + str(t_end-t_start) + ' seconds.') - plotFuncs(RAexample.solution[0].cFunc,0,20) - - # Simulate the representative agent model - RAexample.T_sim = 2000 - RAexample.track_vars = ['cNrmNow','mNrmNow','Rfree','wRte'] - RAexample.initializeSim() - t_start = clock() - RAexample.simulate() - t_end = clock() - print('Simulating a representative agent for ' + str(RAexample.T_sim) + ' periods took ' + str(t_end-t_start) + ' seconds.') - - # Make and solve a Markov representative agent - RA_markov_params = deepcopy(RA_params) - RA_markov_params['PermGroFac'] = [[0.97,1.03]] - RA_markov_params['MrkvArray'] = np.array([[0.99,0.01],[0.01,0.99]]) - RA_markov_params['MrkvNow'] = 0 - RAmarkovExample = RepAgentMarkovConsumerType(**RA_markov_params) - RAmarkovExample.IncomeDstn[0] = 2*[RAmarkovExample.IncomeDstn[0]] - t_start = clock() - RAmarkovExample.solve() - t_end = clock() - print('Solving a two state representative agent problem took ' + str(t_end-t_start) + ' seconds.') - plotFuncs(RAmarkovExample.solution[0].cFunc,0,10) - - # Simulate the two state representative agent model - RAmarkovExample.T_sim = 2000 - RAmarkovExample.track_vars = ['cNrmNow','mNrmNow','Rfree','wRte','MrkvNow'] - RAmarkovExample.initializeSim() - t_start = clock() - RAmarkovExample.simulate() - t_end = clock() - print('Simulating a two state representative agent for ' + str(RAexample.T_sim) + ' periods took ' + str(t_end-t_start) + ' seconds.') - -if __name__ == '__main__': - main() +import warnings +from HARK.ConsumptionSaving.ConsRepAgentModel import * +warnings.warn('Please import from ConsRepAgentModel rather than RepAgentModel. This module will be removed in a future version of HARK.') \ No newline at end of file diff --git a/HARK/ConsumptionSaving/TractableBufferStockModel.py b/HARK/ConsumptionSaving/TractableBufferStockModel.py index 88f78d578..057b4c3d5 100644 --- a/HARK/ConsumptionSaving/TractableBufferStockModel.py +++ b/HARK/ConsumptionSaving/TractableBufferStockModel.py @@ -474,7 +474,7 @@ def main(): # contained in the HARK folder. Also import the ConsumptionSavingModel import numpy as np # numeric Python from HARK.utilities import plotFuncs # basic plotting tools - from .ConsMarkovModel import MarkovConsumerType # An alternative, much longer way to solve the TBS model + from HARK.ConsumptionSaving.ConsMarkovModel import MarkovConsumerType # An alternative, much longer way to solve the TBS model from time import clock # timing utility do_simulation = True