Ejemplo n.º 1
0
    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.]
        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.unpackcFunc()

        # Make and solve a perfect foresight consumer type with the same parameters
        PerfectForesightType = PerfForesightConsumerType(**test_dictionary)
        PerfectForesightType.cycles = 0

        PerfectForesightType.solve()
        PerfectForesightType.unpackcFunc()

        self.InfiniteType = InfiniteType
        self.PerfectForesightType = PerfectForesightType
Ejemplo n.º 2
0
    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.unpackcFunc()  # unpack the consumption function

        self.cFunc = PFexample.solution[0].cFunc
        self.a0 = self.cFunc(0)
        self.a1 = self.cFunc(1) - self.cFunc(0)
Ejemplo n.º 3
0
    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.unpackcFunc()  # unpack the consumption function

        self.cFunc = PFaux.solution[0].cFunc
# %%
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()