def makeConvergencePlot(DiscFac, CRRA, Rfree, PermShkStd): # Construct finite horizon agent with baseline parameters baseAgent_Fin = IndShockConsumerType(verbose=0, **base_params) baseAgent_Fin.DiscFac = DiscFac baseAgent_Fin.CRRA = CRRA baseAgent_Fin.Rfree = Rfree baseAgent_Fin.PermShkStd = [PermShkStd] baseAgent_Fin.cycles = 100 baseAgent_Fin.updateIncomeProcess() baseAgent_Fin.solve() baseAgent_Fin.unpack('cFunc') # figure limits mMax = 6 # 11 mMin = 0 cMin = 0 cMax = 4 # 7 mPlotMin = 0 mLocCLabels = 5.6 # 9.6 # Defines horizontal limit of figure mPlotTop = 3.5 # 6.5 # Defines maximum m value where functions are plotted mPts = 1000 # Number of points at which functions are evaluated plt.figure(figsize=(12, 8)) plt.ylim([cMin, cMax]) plt.xlim([mMin, mMax]) mBelwLabels = np.linspace(mPlotMin, mLocCLabels - 0.1, mPts) # Range of m below loc of labels m_FullRange = np.linspace(mPlotMin, mPlotTop, mPts) # Full plot range c_Tm0 = m_FullRange # c_Tm0 defines the last period consumption rule (c=m) c_Tm1 = baseAgent_Fin.cFunc[-2]( mBelwLabels ) # c_Tm1 defines the second-to-last period consumption rule c_Tm5 = baseAgent_Fin.cFunc[-6]( mBelwLabels) # c_Tm5 defines the T-5 period consumption rule c_Tm10 = baseAgent_Fin.cFunc[-11]( mBelwLabels) # c_Tm10 defines the T-10 period consumption rule c_Limt = baseAgent_Fin.cFunc[0]( mBelwLabels ) # c_Limt defines limiting infinite-horizon consumption rule plt.plot(mBelwLabels, c_Limt, label="$c(m)$") plt.plot(mBelwLabels, c_Tm1, label="$c_{T-1}(m)$") plt.plot(mBelwLabels, c_Tm5, label="$c_{T-5}(m)$") plt.plot(mBelwLabels, c_Tm10, label="$c_{T-10}(m)$") plt.plot(m_FullRange, c_Tm0, label="$c_{T}(m) = 45$ degree line") plt.legend(fontsize='x-large') plt.tick_params( labelbottom=False, labelleft=False, left="off", right="off", bottom="off", top="off", ) plt.show() return None
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 makeTargetMfig(Rfree, DiscFac, CRRA, PermShkStd, TranShkStd): baseAgent_Inf = IndShockConsumerType(verbose=0, cycles=0, **base_params) baseAgent_Inf.Rfree = Rfree baseAgent_Inf.DiscFac = DiscFac baseAgent_Inf.CRRA = CRRA baseAgent_Inf.PermShkStd = [PermShkStd] baseAgent_Inf.TranShkStd = [TranShkStd] baseAgent_Inf.updateIncomeProcess() baseAgent_Inf.checkConditions() mPlotMin = 0 mPlotMax = 250 baseAgent_Inf.aXtraMax = mPlotMax baseAgent_Inf.solve() baseAgent_Inf.unpack('cFunc') cPlotMin = 0 cPlotMax = baseAgent_Inf.cFunc[0](mPlotMax) if (baseAgent_Inf.GPFInd >= 1): baseAgent_Inf.checkGICInd(verbose=3) mBelwTrg = np.linspace(mPlotMin, mPlotMax, 1000) EPermGroFac = baseAgent_Inf.PermGroFac[0] EmDelEq0 = lambda m: (EPermGroFac / Rfree) + (1.0 - EPermGroFac / Rfree ) * m cBelwTrg_Best = baseAgent_Inf.cFunc[0](mBelwTrg) # "best" = optimal c cBelwTrg_Sstn = EmDelEq0(mBelwTrg) # "sustainable" c mNrmTrg = baseAgent_Inf.solution[0].mNrmSS plt.figure(figsize=(12, 8)) plt.plot(mBelwTrg, cBelwTrg_Best, label="$c(m_{t})$") plt.plot(mBelwTrg, cBelwTrg_Sstn, label="$\mathsf{E}_{t}[\Delta m_{t+1}] = 0$") plt.xlim(mPlotMin, mPlotMax) plt.ylim(cPlotMin, cPlotMax) plt.plot( [mNrmTrg, mNrmTrg], [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(mNrmTrg - 0.05, -0.1, "m̌", fontsize=26) plt.legend(fontsize='x-large') plt.show() return None
## and instantiate an instance of that ConsumerType instead. As a homework assignment, we leave it ## to you to uncomment the two lines of code below, and see how the results change! #from ConsIndShockModel import KinkedRconsumerType #BaselineExample = KinkedRconsumerType(**Params.init_kinked_R) # + {"cell_marker": "\"\"\"", "cell_type": "markdown"} # The next step is to change the values of parameters as we want. # # To see all the parameters used in the model, along with their default values, see $\texttt{ConsumerParameters.py}$ # # Parameter values are stored as attributes of the $\texttt{ConsumerType}$ the values are used for. For example, the risk-free interest rate $\texttt{Rfree}$ is stored as $\texttt{BaselineExample.Rfree}$. Because we created $\texttt{BaselineExample}$ using the default parameters values at the moment $\texttt{BaselineExample.Rfree}$ is set to the default value of $\texttt{Rfree}$ (which, at the time this demo was written, was 1.03). Therefore, to change the risk-free interest rate used in $\texttt{BaselineExample}$ to (say) 1.02, all we need to do is: # # - # Change the Default Riskfree Interest Rate BaselineExample.Rfree = 1.02 # + ## Change some parameter values BaselineExample.Rfree = 1.02 #change the risk-free interest rate BaselineExample.CRRA = 2. # change the coefficient of relative risk aversion BaselineExample.BoroCnstArt = -.3 # change the artificial borrowing constraint BaselineExample.DiscFac = .5 #chosen so that target debt-to-permanent-income_ratio is about .1 # i.e. BaselineExample.solution[0].cFunc(.9) ROUGHLY = 1. ## There is one more parameter value we need to change. This one is more complicated than the rest. ## We could solve the problem for a consumer with an infinite horizon of periods that (ex-ante) ## are all identical. We could also solve the problem for a consumer with a fininite lifecycle, ## or for a consumer who faces an infinite horizon of periods that cycle (e.g., a ski instructor ## facing an infinite series of winters, with lots of income, and summers, with very little income.) ## The way to differentiate is through the "cycles" attribute, which indicates how often the
"T_sim": 2000, # Number of periods to simulate "aNrmInitMean": np.log(1.25) - (.5**2) / 2, # Mean of log initial assets "aNrmInitStd": .5, # Standard deviation of log initial assets "pLvlInitMean": 0, # Mean of log initial permanent income "pLvlInitStd": 0, # Standard deviation of log initial permanent income "PermGroFacAgg": 1.0, # Aggregate permanent income growth factor "T_age": None, # Age after which simulated agents are automatically killed } # %% [markdown] # # Solve # %% collapsed=true jupyter={"outputs_hidden": true, "source_hidden": true} fast = IndShockConsumerType(**Harmenberg_Dict, verbose=1) fast.cycles = 0 fast.Rfree = 1.2**.25 fast.PermGroFac = [1.02] fast.tolerance = fast.tolerance / 100 fast.track_vars = ['cNrm', 'pLvl'] fast.solve(verbose=False) # %% [markdown] # # Calculate Patience Conditions # %% collapsed=true jupyter={"outputs_hidden": true} fast.check_conditions(verbose=True) # %% jupyter={"source_hidden": true} # Simulate a population fast.initialize_sim()