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 test_Harmenberg_mtd(self): example = IndShockConsumerType(**dict_harmenberg, verbose=0) example.cycles = 0 example.track_vars = ['aNrm', 'mNrm', 'cNrm', 'pLvl', 'aLvl'] example.T_sim = 20000 example.solve() example.neutral_measure = True example.update_income_process() example.initialize_sim() example.simulate() Asset_list = [] Consumption_list = [] M_list = [] for i in range(example.T_sim): Assetagg = np.mean(example.history['aNrm'][i]) Asset_list.append(Assetagg) ConsAgg = np.mean(example.history['cNrm'][i]) Consumption_list.append(ConsAgg) Magg = np.mean(example.history['mNrm'][i]) M_list.append(Magg) ######################################################### example2 = IndShockConsumerType(**dict_harmenberg, verbose=0) example2.cycles = 0 example2.track_vars = ['aNrm', 'mNrm', 'cNrm', 'pLvl', 'aLvl'] example2.T_sim = 20000 example2.solve() example2.initialize_sim() example2.simulate() Asset_list2 = [] Consumption_list2 = [] M_list2 = [] for i in range(example2.T_sim): Assetagg = np.mean(example2.history['aLvl'][i]) Asset_list2.append(Assetagg) ConsAgg = np.mean(example2.history['cNrm'][i] * example2.history['pLvl'][i]) Consumption_list2.append(ConsAgg) Magg = np.mean(example2.history['mNrm'][i] * example2.history['pLvl'][i]) M_list2.append(Magg) c_std2 = np.std(Consumption_list2) c_std1 = np.std(Consumption_list) c_std_ratio = c_std2 / c_std1 self.assertAlmostEqual(c_std2, 0.03768819564871894) self.assertAlmostEqual(c_std1, 0.004411745897568616) self.assertAlmostEqual(c_std_ratio, 8.542694099741672)
def makeTargetMfig(Rfree, DiscFac, CRRA, permShkStd, TranShkStd): inf_hor = IndShockConsumerType(quietly=True, **base_params) inf_hor.Rfree = Rfree inf_hor.DiscFac = DiscFac inf_hor.CRRA = CRRA inf_hor.permShkStd = [permShkStd] inf_hor.TranShkStd = [TranShkStd] inf_hor.update_income_process() mPlotMin = 0 mPlotMax = 250 inf_hor.aXtraMax = mPlotMax inf_hor.solve(quietly=True, messaging_level=logging.CRITICAL) soln = inf_hor.solution[0] Bilt, cFunc = soln.Bilt, soln.cFunc cPlotMin = 0, cFunc(mPlotMax) if Bilt.GICNrm: # tattle soln.check_GICNrm(soln, quietly=False, messaging_level=logging.WARNING) mBelwStE = np.linspace(mPlotMin, mPlotMax, 1000) EPermGroFac = inf_hor.PermGroFac[0] def EmDelEq0(mVec): return (EPermGroFac / Rfree) + (1.0 - EPermGroFac / Rfree) * mVec cBelwStE_Best = cFunc(mBelwStE) # "best" = optimal c cBelwStE_Sstn = EmDelEq0(mBelwStE) # "sustainable" c mNrmStE = Bilt.mNrmStE plt.figure(figsize=(12, 8)) plt.plot(mBelwStE, cBelwStE_Best, label="$c(m_{t})$") plt.plot(mBelwStE, cBelwStE_Sstn, label="$\mathsf{E}_{t}[\Delta m_{t+1}] = 0$") plt.xlim(mPlotMin, mPlotMax) plt.ylim(cPlotMin, cFunc(mPlotMax)) plt.plot( [mNrmStE, mNrmStE], [0, 2.5], color="black", linestyle="--", ) plt.tick_params( # labelbottom=False, # labelleft=False, # left="off", right="off", # bottom="off", top="off", ) plt.text(0, 1.47, r"$c$", fontsize=26) plt.text(3.02, 0, r"$m$", fontsize=26) plt.text(mNrmStE - 0.05, -0.1, "m̌", fontsize=26) plt.legend(fontsize='x-large') plt.show() return None
def makeBoundsFigure(UnempPrb, permShkStd, TranShkStd, DiscFac, CRRA): inf_hor = IndShockConsumerType(quietly=True, messaging_level=logging.CRITICAL, **base_params) inf_hor.UnempPrb = UnempPrb inf_hor.permShkStd = [permShkStd] inf_hor.TranShkStd = [TranShkStd] inf_hor.DiscFac = DiscFac inf_hor.CRRA = CRRA inf_hor.update_income_process() inf_hor.solve(quietly=True, messaging_level=logging.CRITICAL) soln = inf_hor.solution[0] Bilt, Pars = soln.Bilt, soln.Pars cFunc = soln.cFunc mPlotMin, mPlotMax = 0, 25 inf_hor.aXtraMax = mPlotMax # Retrieve parameters (makes code more readable) Rfree, EPermGroFac = Pars.Rfree, Pars.PermGroFac κ_Min = 1.0 - (Rfree**(-1.0)) * (Rfree * DiscFac)**(1.0 / CRRA) h_inf = (1.0 / (1.0 - EPermGroFac / Rfree)) def cFunc_Uncnst(mVec): return (h_inf - 1) * κ_Min + κ_Min * mVec def cFunc_TopBnd(mVec): return (1 - UnempPrb**(1.0 / CRRA) * (Rfree * DiscFac)**(1.0 / CRRA) / Rfree) * mVec def cFunc_BotBnd(mVec): return (1 - (Rfree * DiscFac)**(1.0 / CRRA) / Rfree) * mVec # Plot the consumption function and its bounds cPlotMaxLabel = r"c̅$(m) = (m-1+h)κ̲$" # Use unicode kludge cPlotMinLabel = r"c̲$(m)= (1-\Phi_{R})m = κ̲ m$" # mKnk is point where the two upper bounds meet mKnk = ((h_inf - 1) * κ_Min) / ( (1 - UnempPrb**(1.0 / CRRA) * (Rfree * DiscFac)**(1.0 / CRRA) / Rfree) - κ_Min) mBelwKnkPts, mAbveKnkPts = 50, 100 mBelwKnk = np.linspace(mPlotMin, mKnk, mBelwKnkPts) mAbveKnk = np.linspace(mKnk, mPlotMax, mAbveKnkPts) mFullPts = np.linspace(mPlotMin, mPlotMax, mBelwKnkPts + mAbveKnkPts) plt.figure(figsize=(12, 8)) plt.plot(mFullPts, cFunc(mFullPts), label=r'$c(m)$') plt.plot(mBelwKnk, cFunc_Uncnst(mBelwKnk), label=cPlotMaxLabel, linestyle="--") plt.plot( mAbveKnk, cFunc_Uncnst(mAbveKnk), label= r'Upper Bound $ = $ Min $[\overline{\overline{c}}(m),\overline{c}(m)]$', linewidth=2.5, color='black') plt.plot(mBelwKnk, cFunc_TopBnd(mBelwKnk), linewidth=2.5, color='black') plt.plot(mAbveKnk, cFunc_TopBnd(mAbveKnk), linestyle="--", label=r"$\overline{\overline{c}}(m) = κ̅m = (1 - ℘^{1/ρ}Φᵣ)m$") plt.plot(mBelwKnk, cFunc_BotBnd(mBelwKnk), color='red', linewidth=2.5) plt.plot(mAbveKnk, cFunc_BotBnd(mAbveKnk), color='red', label=cPlotMinLabel, linewidth=2.5) plt.tick_params(labelbottom=False, labelleft=False, left='off', right='off', bottom='off', top='off') plt.xlim(mPlotMin, mPlotMax) plt.ylim(mPlotMin, 1.12 * cFunc_Uncnst(mPlotMax)) plt.text(mPlotMin, 1.12 * cFunc_Uncnst(mPlotMax) + 0.05, "$c$", fontsize=22) plt.text(mPlotMax + 0.1, mPlotMin, "$m$", fontsize=22) plt.legend(fontsize='x-large') plt.show() return None