def setUp(self): """ Prepare to compare the models by initializing and solving them """ # Set up and solve infinite type # Define a test dictionary that should have the same solution in the # perfect foresight and idiosyncratic shocks models. test_dictionary = deepcopy(init_idiosyncratic_shocks) test_dictionary["LivPrb"] = [1.0] test_dictionary["DiscFac"] = 0.955 test_dictionary["PermGroFac"] = [1.0] test_dictionary["PermShkStd"] = [0.0] test_dictionary["TranShkStd"] = [0.0] test_dictionary["UnempPrb"] = 0.0 test_dictionary["T_cycle"] = 1 test_dictionary["T_retire"] = 0 test_dictionary["BoroCnstArt"] = None InfiniteType = IndShockConsumerType(**test_dictionary) InfiniteType.cycles = 0 InfiniteType.update_income_process() InfiniteType.solve() InfiniteType.unpack("cFunc") # Make and solve a perfect foresight consumer type with the same parameters PerfectForesightType = PerfForesightConsumerType(**test_dictionary) PerfectForesightType.cycles = 0 PerfectForesightType.solve() PerfectForesightType.unpack("cFunc") self.InfiniteType = InfiniteType self.PerfectForesightType = PerfectForesightType
def __init__(self, Rfree=1.001, CRRA=2): PFaux = PerfForesightConsumerType( ) # set up a consumer type and use default parameteres PFaux.cycles = 0 # Make this type have an infinite horizon PFaux.DiscFac = 1 / Rfree PFaux.Rfree = Rfree PFaux.LivPrb = [1.0] PFaux.PermGroFac = [1.0] PFaux.CRRA = CRRA PFaux.solve() # solve the consumer's problem PFaux.unpack('cFunc') # unpack the consumption function self.cFunc = PFaux.solution[0].cFunc
def __init__(self): PFexample = PerfForesightConsumerType( ) # set up a consumer type and use default parameteres PFexample.cycles = 0 # Make this type have an infinite horizon PFexample.DiscFac = 0.05 PFexample.PermGroFac = [0.7] PFexample.solve() # solve the consumer's problem PFexample.unpack('cFunc') # unpack the consumption function self.cFunc = PFexample.solution[0].cFunc self.a0 = self.cFunc(0) self.a1 = self.cFunc(1) - self.cFunc(0)
mystr = lambda number: "{:.4f}".format(number) 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.unpack('cFunc') # 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() # Make and solve an example consumer with idiosyncratic income shocks IndShockExample = IndShockConsumerType() IndShockExample.cycles = 0 # Make this type have an infinite horizon