def makeIncShkHist(self): ''' Makes histories of simulated income shocks for this consumer type by drawing from the discrete income distributions, storing them as attributes of self for use by simulation methods. Parameters ---------- None Returns ------- None ''' # After running the routine for AggShockConsumerType, just add in updateBeliefHist AggShockConsumerType.makeIncShkHist(self) orig_time = self.time_flow self.timeFwd() self.resetRNG() # Initialize the shock histories updateBeliefHist = np.zeros((self.sim_periods, self.Nagents)) + np.nan updateBeliefHist[0, :] = 1.0 t_idx = 0 # Loop through each simulated period for t in range(1, self.sim_periods): updateBeliefHist[t, :] = drawBernoulli(self.Nagents, self.updateBeliefProb, seed=self.RNG.randint( 0, 2**31 - 1)) # Advance the time index, looping if we've run out of income distributions t_idx += 1 if t_idx >= len(self.IncomeDstn): t_idx = 0 # Store the results as attributes of self and restore time to its original flow self.updateBeliefHist = updateBeliefHist if not orig_time: self.timeRev()
cTranImpulseResponse = AggCons_impulseResponseInd(IndShockExample, PermShk, TranShk, 100, 25) plt.plot(cTranImpulseResponse) print( 'Impulse response to a one time permanent and transitive shock to income of 10%:' ) plt.show() ########################################## # Now do aggregate shocks of a market # Make an aggregate shocks consumer AggShockExample = AggShockConsumerType(**Params.init_agg_shocks) AggShockExample.cycles = 0 AggShockExample.sim_periods = 3000 AggShockExample.makeIncShkHist( ) # Simulate a history of idiosyncratic shocks # Make a Cobb-Douglas economy for the agents EconomyExample = CobbDouglasEconomy(agents=[AggShockExample], act_T=AggShockExample.sim_periods, **Params.init_cobb_douglas) EconomyExample.makeAggShkHist() # Simulate a history of aggregate shocks # Have the consumers inherit relevant objects from the economy AggShockExample.getEconomyData(EconomyExample) # Solve the microeconomic model for the aggregate shocks example type (and display results) t_start = clock() AggShockExample.solve() t_end = clock() print('Solving an aggregate shocks consumer took ' + mystr(t_end - t_start) + ' seconds.')
import ConsumerParameters as Params from time import clock from HARKutilities import plotFuncs mystr = lambda number: "{:.4f}".format(number) # Make an aggregate shocks sticky expectations consumer StickyExample = AggShockStickyExpectationsConsumerType( **Params.init_sticky_shocks) NotStickyExample = AggShockConsumerType(**Params.init_sticky_shocks) StickyExample.cycles = 0 NotStickyExample.cycles = 0 StickyExample.sim_periods = 3000 NotStickyExample.sim_periods = 3000 StickyExample.makeIncShkHist( ) # Simulate a history of idiosyncratic shocks NotStickyExample.makeIncShkHist( ) # Simulate a history of idiosyncratic shocks # Make a Cobb-Douglas economy for the agents StickyEconomyExample = CobbDouglasEconomy(agents=[StickyExample], act_T=StickyExample.sim_periods, **Params.init_cobb_douglas) NotStickyEconomyExample = CobbDouglasEconomy( agents=[NotStickyExample], act_T=NotStickyExample.sim_periods, **Params.init_cobb_douglas) StickyEconomyExample.makeAggShkHist( ) # Simulate a history of aggregate shocks NotStickyEconomyExample.makeAggShkHist( ) # Simulate a history of aggregate shocks # Have the consumers inherit relevant objects from the economy