class testKrusellSmith(unittest.TestCase): def setUp(self): # Make one agent type and an economy for it to live in self.agent = KrusellSmithType() self.agent.cycles = 0 self.agent.AgentCount = 1000 # Low number of simulated agents self.economy = KrusellSmithEconomy(agents=[self.agent]) self.economy.max_loops = 2 # Quit early self.economy.act_T = 1100 # Shorter simulated period self.economy.discard_periods = 100 self.economy.verbose = False # Turn off printed messages def test_agent(self): self.agent.getEconomyData(self.economy) self.agent.solve() self.assertAlmostEqual( self.agent.solution[0].cFunc[0](10., self.economy.MSS), 1.23867751) def test_economy(self): self.agent.getEconomyData(self.economy) self.economy.makeMrkvHist( ) # Make a simulated history of aggregate shocks self.economy.solve( ) # Solve for the general equilibrium of the economy self.economy.AFunc = self.economy.dynamics.AFunc self.assertAlmostEqual(self.economy.AFunc[0].slope, 1.0014463644834282) self.assertAlmostEqual(self.economy.history['Aprev'][4], 11.009107526443584) self.assertAlmostEqual(self.economy.history['MrkvNow'][40], 1) self.assertAlmostEqual(self.economy.history['Urate'][12], 0.040000000000000036)
# %% # Import Krusell-Smith model from HARK.ConsumptionSaving.ConsAggShockModel import KrusellSmithType, KrusellSmithEconomy from time import time from scipy.stats import linregress # %% # Make default KS agent type and economy KSeconomy = KrusellSmithEconomy() KSeconomy.verbose = False KStype = KrusellSmithType() KStype.cycles = 0 KStype.getEconomyData(KSeconomy) KSeconomy.agents = [KStype] KSeconomy.makeMrkvHist() # %% # Solve the Krusell-Smith economy t0 = time() print("Now solving for the equilibrium of the Krusell-Smith (1998) model. This might take a few minutes...") KSeconomy.solve() t1 = time() print('Solving the Krusell-Smith model took ' + str(t1-t0) + ' seconds.') # %% # Plot the consumption function for each discrete state state_names = ['bad economy, unemployed', 'bad economy, employed', 'good economy, unemployed', 'good economy, employed'] for j in range(4):