class testAggShockMarkovConsumerType(unittest.TestCase): def setUp(self): # Make one agent type and an economy for it to live in self.agent = AggShockMarkovConsumerType() self.agent.cycles = 0 self.agent.AgentCount = 1000 # Low number of simulated agents self.agent.IncomeDstn[0] = 2 * [self.agent.IncomeDstn[0]] ## see #557 self.economy = CobbDouglasMarkovEconomy(agents=[self.agent]) def test_agent(self): # Have one consumer type inherit relevant objects from the economy, # then solve their microeconomic problem self.agent.getEconomyData(self.economy) self.agent.solve() self.assertAlmostEqual( self.agent.solution[0].cFunc[0](10.0, self.economy.MSS), 2.5635896520991377) def test_economy(self): # Adjust the economy so that it (fake) solves quickly self.economy.act_T = 500 # Short simulation history self.economy.max_loops = 3 # Just quiet solving early self.economy.verbose = False # Turn off printed messages self.agent.getEconomyData(self.economy) self.economy.makeAggShkHist( ) # 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.0904698841958917) self.assertAlmostEqual(self.economy.history["AaggNow"][5], 9.467758924955897)
AggShockMrkvExample.IncomeDstn[0] = 2 * [AggShockMrkvExample.IncomeDstn[0]] AggShockMrkvExample.cycles = 0 # Make a Cobb-Douglas economy for the agents MrkvEconomyExample = CobbDouglasMarkovEconomy(agents=[AggShockMrkvExample]) MrkvEconomyExample.DampingFac = 0.2 # Turn down damping MrkvEconomyExample.makeAggShkHist( ) # Simulate a history of aggregate shocks AggShockMrkvExample.getEconomyData( MrkvEconomyExample ) # Have the consumers inherit relevant objects from the economy if solve_markov_micro: # Solve the microeconomic model for the Markov aggregate shocks example type (and display results) t_start = process_time() AggShockMrkvExample.solve() t_end = process_time() print("Solving an aggregate shocks Markov consumer took " + mystr(t_end - t_start) + " seconds.") print("Consumption function at each aggregate market \ resources-to-labor ratio gridpoint (for each macro state):") m_grid = np.linspace(0, 10, 200) AggShockMrkvExample.unpack('cFunc') for i in range(2): for M in AggShockMrkvExample.Mgrid.tolist(): 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.0, None)