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 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