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
PatR_array = Pat_array/Rfree_array # + # Set the time preference factor to match the interest factor so that $(R \beta) = 1$ Paramod['DiscFac'] = 1/Rfree # + # Plot average deviation from true consumption function PFagent = PerfForesightConsumerType(**Paramod) # construct a consumer with our previous parameters plt.figure(figsize=(9,6)) #set the figure size mean_dev = np.zeros(30) for i in range(len(Rfree_array)): PFagent.Rfree = Rfree_array[i] # Now we just copy the lines of code from above that we want PFagent.solve() cHARK = PFagent.solution[0].cFunc(m_range) wealthHmn = PFagent.solution[0].hNrm wealthTot = wealthHmn+m_range rfree=Rfree-1 discRte=(1/DiscFac)-1 cApprox = wealthTot*(rfree - (1/CRRA)*(rfree-discRte)) deviation = np.mean(np.abs(cApprox/cHARK)) mean_dev[i] = deviation plt.plot(Rfree_array,mean_dev) plt.xlabel('Return Factor') # x axis label plt.ylabel(' Average deviation along consumption function') # y axis label
def FisherPlot(Y1, Y2, B1, R, c1Max, c2Max): # Basic setup of perfect foresight consumer # We first create an instance of the class # PerfForesightConsumerType, with its standard parameters. PFexample = PerfForesightConsumerType() PFexample.cycles = 1 # let the agent live the cycle of periods just once PFexample.T_cycle = 2 # Number of periods in the cycle PFexample.PermGroFac = [1.] # No automatic growth in income across periods PFexample.LivPrb = [1.] # No chance of dying before the second period PFexample.aNrmInitStd = 0. PFexample.AgentCount = 1 CRRA = PFexample.CRRA Beta = PFexample.DiscFac # Set interest rate and bank balances from input. PFexample.Rfree = R PFexample.aNrmInitMean = B1 # Solve the model: this generates the optimal consumption function. # Try-except blocks "try" to execute the code in the try block. If an # error occurs, the except block is executed and the application does # not halt try: PFexample.solve() except: print( 'Those parameter values violate a condition required for solution!' ) # Create the figure c1Min = 0. c2Min = 0. plt.figure(figsize=(8, 8)) plt.xlabel('Period 1 Consumption $C_1$') plt.ylabel('Period 2 Consumption $C_2$') plt.ylim([c2Min, c2Max]) plt.xlim([c1Min, c1Max]) # Plot the budget constraint C1_bc = np.linspace(c1Min, B1 + Y1 + Y2 / R, 10, endpoint=True) C2_bc = (Y1 + B1 - C1_bc) * R + Y2 plt.plot(C1_bc, C2_bc, 'k-', label='Budget Constraint') # Plot the optimal consumption bundle C1 = PFexample.solution[0].cFunc(B1 + Y1 + Y2 / R) C2 = PFexample.solution[1].cFunc((Y1 + B1 - C1) * R + Y2) plt.plot(C1, C2, 'ro', label='Optimal Consumption') # Plot the indifference curve V = C1**(1 - CRRA) / (1 - CRRA) + Beta * C2**(1 - CRRA) / ( 1 - CRRA) # Get max utility C1_V = np.linspace(((1 - CRRA) * V)**(1 / (1 - CRRA)) + 0.5, c1Max, 1000) C2_V = (((1 - CRRA) * V - C1_V**(1 - CRRA)) / Beta)**(1 / (1 - CRRA)) plt.plot(C1_V, C2_V, 'b-', label='Indiferrence Curve') # Add a legend and display the plot plt.legend() plt.show() return None