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
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 FisherPlot2(Y1, Y2, B1, RHi, RLo, c1Max, c2Max): # Basic setup of perfect foresight consumer PFexample = PerfForesightConsumerType( ) # set up a consumer type and use default parameteres 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 = 2. Beta = PFexample.DiscFac # Set the parameters we enter PFexample.aNrmInitMean = B1 # Create two models, one for RfreeHigh and one for RfreeLow PFexampleRHi = deepcopy(PFexample) PFexampleRHi.Rfree = RHi PFexampleRLo = deepcopy(PFexample) PFexampleRLo.Rfree = RLo c1Min = 0. c2Min = 0. # Solve the model for RfreeHigh try: PFexampleRHi.solve() PFexampleRLo.solve() except: print( 'Those parameter values violate a condition required for solution!' ) # Plot the chart 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 constraints C1_bc_RLo = np.linspace(c1Min, B1 + Y1 + Y2 / RLo, 10, endpoint=True) C2_bc_RLo = (Y1 + B1 - C1_bc_RLo) * RLo + Y2 plt.plot(C1_bc_RLo, C2_bc_RLo, 'k-', label='Budget Constraint R Low') C1_bc_RHi = np.linspace(c1Min, B1 + Y1 + Y2 / RHi, 10, endpoint=True) C2_bc_RHi = (Y1 + B1 - C1_bc_RHi) * RHi + Y2 plt.plot(C1_bc_RHi, C2_bc_RHi, 'k--', label='Budget Constraint R High') # The optimal consumption bundles C1_opt_RLo = PFexampleRLo.solution[0].cFunc(B1 + Y1 + Y2 / RLo) C2_opt_RLo = PFexampleRLo.solution[1].cFunc((Y1 + B1 - C1_opt_RLo) * RLo + Y2) C1_opt_RHi = PFexampleRHi.solution[0].cFunc(B1 + Y1 + Y2 / RHi) C2_opt_RHi = PFexampleRHi.solution[1].cFunc((Y1 + B1 - C1_opt_RHi) * RHi + Y2) # Plot the indifference curves V_RLo = C1_opt_RLo**(1 - CRRA) / (1 - CRRA) + Beta * C2_opt_RLo**( 1 - CRRA) / (1 - CRRA) # Get max utility C1_V_RLo = np.linspace(((1 - CRRA) * V_RLo)**(1 / (1 - CRRA)) + 0.5, c1Max, 1000) C2_V_RLo = (((1 - CRRA) * V_RLo - C1_V_RLo**(1 - CRRA)) / Beta)**(1 / (1 - CRRA)) plt.plot(C1_V_RLo, C2_V_RLo, 'b-', label='Indiferrence Curve R Low') V_RHi = C1_opt_RHi**(1 - CRRA) / (1 - CRRA) + Beta * C2_opt_RHi**( 1 - CRRA) / (1 - CRRA) # Get max utility C1_V_RHi = np.linspace(((1 - CRRA) * V_RHi)**(1 / (1 - CRRA)) + 0.5, c1Max, 1000) C2_V_RHi = (((1 - CRRA) * V_RHi - C1_V_RHi**(1 - CRRA)) / Beta)**(1 / (1 - CRRA)) plt.plot(C1_V_RHi, C2_V_RHi, 'b--', label='Indiferrence Curve R High') # The substitution effect C1_Subs = (V_RHi * (1 - CRRA) / (1 + Beta * (RLo * Beta)**((1 - CRRA) / CRRA)))**(1 / (1 - CRRA)) C2_Subs = C1_Subs * (RLo * Beta)**(1 / CRRA) # The Human wealth effect Y2HW = Y2 * RLo / RHi C1HW = Y2HW / (RLo + (RLo)**(1 / CRRA)) C2HW = C1HW * (RLo * Beta)**(1 / CRRA) C1_bc_HW = np.linspace(c1Min, B1 + Y1 + Y2HW / RLo, 10, endpoint=True) C2_bc_HW = (Y1 + B1 - C1_bc_HW) * RLo + Y2HW plt.plot(C1_bc_HW, C2_bc_HW, 'k:') VHW = (C1HW**(1 - CRRA)) / (1 - CRRA) + (Beta * C2HW** (1 - CRRA)) / (1 - CRRA) C1_V_HW = np.linspace(((1 - CRRA) * VHW)**(1 / (1 - CRRA)) + 0.5, c1Max, 1000) C2_V_HW = (((1 - CRRA) * VHW - C1_V_HW**(1 - CRRA)) / Beta)**(1 / (1 - CRRA)) plt.plot(C1_V_HW, C2_V_HW, 'b:') # Plot the points of interest plt.plot(C1_opt_RLo, C2_opt_RLo, 'ro', label='A: Optimal Consumption R Low') plt.plot(C1_Subs, C2_Subs, 'go', label='B: Income effect DB \n Substitution effect BC') plt.plot(C1_opt_RHi, C2_opt_RHi, 'mo', label='C: Optimal Consumption R High') plt.plot(C1HW, C2HW, 'co', label='D: HW effect AD') plt.legend() plt.show() return None