def setUp(self): """ Prepare to compare the models by initializing and solving them """ # Set up and solve infinite type import HARK.ConsumptionSaving.ConsumerParameters as Params # Define a test dictionary that should have the same solution in the # perfect foresight and idiosyncratic shocks models. test_dictionary = deepcopy(Params.init_idiosyncratic_shocks) test_dictionary['LivPrb'] = [1.] test_dictionary['DiscFac'] = 0.955 test_dictionary['PermGroFac'] = [1.] test_dictionary['PermShkStd'] = [0.] test_dictionary['TranShkStd'] = [0.] test_dictionary['UnempPrb'] = 0. test_dictionary['T_cycle'] = 1 test_dictionary['T_retire'] = 0 test_dictionary['BoroCnstArt'] = None InfiniteType = IndShockConsumerType(**test_dictionary) InfiniteType.cycles = 0 InfiniteType.updateIncomeProcess() InfiniteType.solve() InfiniteType.timeFwd() InfiniteType.unpackcFunc() # Make and solve a perfect foresight consumer type with the same parameters PerfectForesightType = PerfForesightConsumerType(**test_dictionary) PerfectForesightType.cycles = 0 PerfectForesightType.solve() PerfectForesightType.unpackcFunc() PerfectForesightType.timeFwd() self.InfiniteType = InfiniteType self.PerfectForesightType = PerfectForesightType
do_simulation = True # %% # Make and solve an example perfect foresight consumer PFexample = PerfForesightConsumerType() # Make this type have an infinite horizon PFexample.cycles = 0 # %% start_time = time() PFexample.solve() end_time = time() print("Solving a perfect foresight consumer took " + mystr(end_time - start_time) + " seconds.") PFexample.unpackcFunc() PFexample.timeFwd() # %% # Plot the perfect foresight consumption function print("Perfect foresight consumption function:") mMin = PFexample.solution[0].mNrmMin plotFuncs(PFexample.cFunc[0], mMin, mMin + 10) # %% if do_simulation: PFexample.T_sim = 120 # Set number of simulation periods PFexample.track_vars = ["mNrmNow"] PFexample.initializeSim() PFexample.simulate() # %%