def update(self): ''' Update the income process, the assets grid, and the terminal solution. Parameters ---------- none Returns ------- none ''' orig_flow = self.time_flow if self.cycles == 0: # hacky fix for labor supply l_bar self.updateIncomeProcessAlt() else: self.updateIncomeProcess() self.updateAssetsGrid() self.updateSolutionTerminal() self.timeFwd() self.resetRNG() if self.cycles > 0: self.IncomeDstn = Model.applyFlatIncomeTax( self.IncomeDstn, tax_rate=self.tax_rate, T_retire=self.T_retire, unemployed_indices=range(0, (self.TranShkCount + 1) * self.PermShkCount, self.TranShkCount + 1)) self.makeIncShkHist() if not orig_flow: self.timeRev()
Params.init_consumer_objects[ "PermGroFacAgg"] = 1.0 # Aggregate permanent income growth factor Params.init_consumer_objects[ "aNrmInitMean"] = -10.0 # Mean of log initial assets Params.init_consumer_objects[ "aNrmInitStd"] = 1.0 # Standard deviation of log initial assets Params.init_consumer_objects[ "pLvlInitMean"] = 0.0 # Mean of log initial permanent income Params.init_consumer_objects[ "pLvlInitStd"] = 0.0 # Standard deviation of log initial permanent income Params.init_consumer_objects[ "CubicBool"] = False # Not available in the bequest model # %% # Make an instance of a lifecycle consumer to be used for estimation LifeCyclePop = cShksModl.IndShockConsumerType(**Params.init_consumer_objects) # %% {"code_folding": [0]} # Solve and simulate the model (ignore the "warning" message) LifeCyclePop.solve() # Obtain consumption rules by age LifeCyclePop.unpackcFunc() # Expose the consumption rules # Which variables do we want to track LifeCyclePop.track_vars = [ 'aNrmNow', 'pLvlNow', 'mNrmNow', 'cNrmNow', 'TranShkNow', 't_cycle' ] LifeCyclePop.T_sim = 120 # Nobody lives to be older than 145 years (=25+120) LifeCyclePop.initializeSim( ) # Construct the age-25 distribution of income and assets LifeCyclePop.simulate(
params["UnempPrb"] = 0.05 params["IncUnemp"] = 0.3 params["UnempPrbRet"] = 0.0 params["IncUnempRet"] = 0.0 params.update({ "BoroCnstArt": 0.0, "vFuncBool": False, "CubicBool": False, "aXtraMin": 0.001, "aXtraMax": 50.0, "aXtraNestFac": 3, "aXtraCount": 48, "aXtraExtra": [None], }) example = ConsIndShockModel.IndShockConsumerType(**params) else: params = copy.deepcopy(params) params.pop("PermShkStd", None) params.pop("TranShkStd", None) example = ConsIndShockModel.PerfForesightConsumerType(**params) examples.append(example) results.append(st.empty()) for i, example in enumerate(examples): example.solve() results[i].markdown( f"**Model {1+i}** agent's human wealth is {example.solution[0].hNrm:.02f} times " f"his current income level, with its consumption function is defined (consumption is " f"positive) down to m_t = {example.solution[0].mNrmMin:.02f}.")
import HARK.ConsumptionSaving.ConsIndShockModel as Model # Consumption-saving model with idiosyncratic shocks from HARK.utilities import plotFuncs, plotFuncsDer # Basic plotting tools from time import clock # Timing utility from copy import deepcopy # "Deep" copying for complex objects from HARK.parallel import multiThreadCommandsFake, multiThreadCommands # Parallel processing mystr = lambda number: "{:.4f}".format(number) # Format numbers as strings import numpy as np # Numeric Python if __name__ == '__main__': # Parallel calls *must* be inside a call to __main__ type_count = 32 # Number of values of CRRA to solve # Make the basic type that we'll use as a template. # The basic type has an artificially dense assets grid, as the problem to be # solved must be sufficiently large for multithreading to be faster than # single-threading (looping), due to overhead. BasicType = Model.IndShockConsumerType(**Params.init_idiosyncratic_shocks) BasicType.cycles = 0 BasicType(aXtraMax=100, aXtraCount=64) BasicType(vFuncBool=False, CubicBool=True) BasicType.updateAssetsGrid() BasicType.timeFwd() # Solve the basic type and plot the results, to make sure things are working start_time = clock() BasicType.solve() end_time = clock() print('Solving the basic consumer took ' + mystr(end_time - start_time) + ' seconds.') BasicType.unpackcFunc() print('Consumption function:') plotFuncs(BasicType.cFunc[0], 0, 5) # plot consumption
# Make agent live for sure until the terminal period pf_dict['T_retire'] = t_cycle pf_dict['LivPrb'] = [1] * t_cycle # Shut down income growth pf_dict['PermGroFac'] = [1] * t_cycle # Decrease grid for speed pf_dict['aXtraCount'] = 100 # %% Create both agents port_agent = cpm.PortfolioConsumerType(**pf_dict) port_agent.solve() pf_agent = cis.PerfForesightConsumerType(**pf_dict) pf_agent.solve() # %% Construct the analytical solution rho = pf_dict['CRRA'] R = pf_dict['Rfree'] Beta = pf_dict['DiscFac'] T = pf_dict['T_cycle'] + 1 thorn_r = (R * Beta)**(1 / rho) / R ht = lambda t: (1 - (1 / R)**(T - t + 1)) / (1 - 1 / R) - 1 kappa = lambda t: (1 - thorn_r) / (1 - thorn_r**(T - t + 1)) true_cFunc = lambda t, m: np.minimum(m, kappa(t) * (m + ht(t)))