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
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)
def plot1(Epsilon, DiscFac, PopGrowth, YearsPerGeneration, Initialk): '''Inputs: Epsilon: Elasticity of output with respect to capital/labour ratio DiscFac: One period discount factor YearPerGeneration: No. of years per generation PopGrowth: Gross growth rate of population in one period''' # kMax = 0.1 # Define some parameters Beta = DiscFac**YearsPerGeneration xi = PopGrowth**YearsPerGeneration Q = (1-Epsilon)*(Beta/(1+Beta))/xi kBar = Q**(1/(1-Epsilon)) # Create an agent that will solve the consumption problem PFagent = PerfForesightConsumerType(**init_perfect_foresight) PFagent.cycles = 1 # let the agent live the cycle of periods just once PFagent.T_cycle = 2 # Number of periods in the cycle PFagent.assign_parameters(PermGroFac = [0.000001]) # Income only in the first period PFagent.LivPrb = [1.] PFagent.DiscFac = Beta # Hark seems to have trouble with log-utility # so pass rho = 1 + something small. PFagent.CRRA = 1.001 PFagent.solve() # Plot the OLG capital accumulation curve and 45 deg line plt.figure(figsize=(9,6)) kt_range = np.linspace(0, kMax, 300) # Analitical solution plot ktp1 = Q*kt_range**Epsilon plt.plot(kt_range, ktp1, 'b-', label='Capital accumulation curve') plt.plot(kt_range, kt_range, 'k-', label='45 Degree line') # Plot the path kt_ar = Initialk ktp1_ar = 0. for i in range(3): # Compute Next Period's capital using HARK wage = (1-Epsilon)*kt_ar**Epsilon c = PFagent.solution[0].cFunc(wage) a = wage - c k1 = a/xi plt.arrow(kt_ar, ktp1_ar, 0., k1-ktp1_ar, length_includes_head=True, lw=0.01, width=0.0005, color='black', edgecolor=None) plt.arrow(kt_ar, k1, k1-kt_ar , 0., length_includes_head=True, lw=0.01, width=0.0005, color='black', edgecolor=None) # Update arrow kt_ar = k1 ktp1_ar = kt_ar # Plot kbar and initial k plt.plot(kBar, kBar, 'ro', label=r'$\bar{k}$') plt.plot(Initialk, 0.0005, 'co', label = '$k_0$') plt.legend() plt.xlim(0 ,kMax) plt.ylim(0, kMax) plt.xlabel('$k_t$') plt.ylabel('$k_{t+1}$') plt.show() return None
def FisherPlot3(M1, R, Beta, CRRA, 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 = 1 # One single non-terminal period PFexample.PermGroFac = [0] # No income in the second period PFexample.LivPrb = [1.] # No chance of dying before the second period # Set interest rate and bank balances from input. PFexample.Rfree = R PFexample.CRRA = CRRA PFexample.DiscFac = Beta # 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!' ) return # 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, M1, 10, endpoint=True) C2_bc = (M1 - C1_bc) * R plt.plot(C1_bc, C2_bc, 'k-', label='Budget Constraint') # Plot the optimal consumption bundle C1 = PFexample.solution[0].cFunc(M1) C2 = PFexample.solution[1].cFunc((M1 - C1) * R) 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.1, 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
# %% # The code below is an example to show you how to plot a set of consumption functions # for a sequence of values of the discount factor. You should be # to adapt this code to solve the rest of the sproblem posed above howClose=0.01 # How close to come to the limit where the impatience condition fails DiscFac_min = 0.8 DiscFac_max = DiscFac_lim-howClose # numPoints = 10 DiscFac_list = np.linspace(DiscFac_min, DiscFac_max, numPoints) # Create a list of beta values plt.figure(figsize=((9,6))) # set the plot size plt.plot(m_range, cSustainable , 'k', label='Sustainable c') # Add sustainable c line for i in range(len(DiscFac_list)): PFagent.DiscFac = DiscFac_list[i] PFagent.solve() cHARK = PFagent.solution[0].cFunc(m_range) plt.plot(m_range, cHARK, label='Consumption Function, $\\beta$= '+str(PFagent.DiscFac)) PFagent.DiscFac = Params.DiscFac # return discount factor to default value PFagent.solve() # It's polite to leave the PFagent back with its default solution plt.xlabel('Market resources m') # x axis label plt.ylabel('Consumption c') # y axis label plt.legend() # show legend plt.show() # plot chart # %% # Now plot the consumption functions for alternate values of G as described above # Note the tricky fact that PermGroFac is a list of values because it could