def compute_lt_price(self, error_tol=1e-7, max_iter=600, verbose=0): """ Compute the equilibrium price function associated with Lucas tree lt Parameters ---------- error_tol, max_iter, verbose Arguments to be passed directly to `quantecon.compute_fixed_point`. See that docstring for more information Returns ------- price : array_like(float) The prices at the grid points in the attribute `grid` of the object """ # == simplify notation == # grid, grid_size = self.grid, self.grid_size lucas_operator, gamma = self.lucas_operator, self.gamma # == Create storage array for compute_fixed_point. Reduces memory # allocation and speeds code up == # Tf = np.empty(grid_size) # == Initial guess, just a vector of ones == # f_init = np.ones(grid_size) f = compute_fixed_point(lucas_operator, f_init, error_tol, max_iter, verbose, Tf=Tf) price = f * grid**gamma return price
Authors: John Stachurski and Thomas Sargent LastModified: 11/08/2013 """ import matplotlib.pyplot as plt from mpl_toolkits.mplot3d.axes3d import Axes3D import numpy as np from matplotlib import cm from quantecon.compute_fp import compute_fixed_point import quantecon as qe # === solve for the value function === # wp = qe.career.workerProblem() v_init = np.ones((wp.N, wp.N))*100 v = compute_fixed_point(qe.career.bellman, wp, v_init) # === plot value function === # fig = plt.figure(figsize=(8,6)) ax = fig.add_subplot(111, projection='3d') tg, eg = np.meshgrid(wp.theta, wp.epsilon) ax.plot_surface(tg, eg, v.T, rstride=2, cstride=2, cmap=cm.jet, alpha=0.5, linewidth=0.25) ax.set_zlim(150, 200) ax.set_xlabel('theta', fontsize=14) ax.set_ylabel('epsilon', fontsize=14)
Authors: John Stachurski and Thomas Sargent """ import matplotlib.pyplot as plt from mpl_toolkits.mplot3d.axes3d import Axes3D from matplotlib import cm from scipy.interpolate import LinearNDInterpolator import numpy as np from quantecon import odu_vfi from quantecon.compute_fp import compute_fixed_point sp = odu_vfi.searchProblem(w_grid_size=100, pi_grid_size=100) v_init = np.zeros(len(sp.grid_points)) + sp.c / (1 - sp.beta) v = compute_fixed_point(odu_vfi.bellman, sp, v_init) policy = odu_vfi.get_greedy(sp, v) # Make functions from these arrays by interpolation vf = LinearNDInterpolator(sp.grid_points, v) pf = LinearNDInterpolator(sp.grid_points, policy) pi_plot_grid_size, w_plot_grid_size = 100, 100 pi_plot_grid = np.linspace(0.001, 0.99, pi_plot_grid_size) w_plot_grid = np.linspace(0, sp.w_max, w_plot_grid_size) #plot_choice = 'value_function' plot_choice = 'policy_function' if plot_choice == 'value_function': Z = np.empty((w_plot_grid_size, pi_plot_grid_size))
Filename: odu_vfi_plots.py Authors: John Stachurski and Thomas Sargent """ import matplotlib.pyplot as plt from mpl_toolkits.mplot3d.axes3d import Axes3D from matplotlib import cm from scipy.interpolate import LinearNDInterpolator import numpy as np from quantecon import odu_vfi from quantecon.compute_fp import compute_fixed_point sp = odu_vfi.searchProblem(w_grid_size=100, pi_grid_size=100) v_init = np.zeros(len(sp.grid_points)) + sp.c / (1 - sp.beta) v = compute_fixed_point(odu_vfi.bellman, sp, v_init) policy = odu_vfi.get_greedy(sp, v) # Make functions from these arrays by interpolation vf = LinearNDInterpolator(sp.grid_points, v) pf = LinearNDInterpolator(sp.grid_points, policy) pi_plot_grid_size, w_plot_grid_size = 100, 100 pi_plot_grid = np.linspace(0.001, 0.99, pi_plot_grid_size) w_plot_grid = np.linspace(0, sp.w_max, w_plot_grid_size) #plot_choice = 'value_function' plot_choice = 'policy_function' if plot_choice == 'value_function': Z = np.empty((w_plot_grid_size, pi_plot_grid_size))
""" Origin: QE by John Stachurski and Thomas J. Sargent Filename: jv_test.py Authors: John Stachurski and Thomas Sargent LastModified: 11/08/2013 Tests jv.py with a particular parameterization. """ import matplotlib.pyplot as plt from jv import workerProblem, bellman_operator from quantecon.compute_fp import compute_fixed_point import quantecon.jv as jv # === solve for optimal policy === # wp = jv.workerProblem(grid_size=25) v_init = wp.x_grid * 0.5 V = compute_fixed_point(jv.bellman_operator, wp, v_init, max_iter=40) s_policy, phi_policy = jv.bellman_operator(wp, V, return_policies=True) # === plot policies === # fig, ax = plt.subplots() ax.set_xlim(0, max(wp.x_grid)) ax.set_ylim(-0.1, 1.1) ax.plot(wp.x_grid, phi_policy, 'b-', label='phi') ax.plot(wp.x_grid, s_policy, 'g-', label='s') ax.legend() plt.show()
Authors: John Stachurski and Thomas Sargent LastModified: 11/08/2013 """ import matplotlib.pyplot as plt from mpl_toolkits.mplot3d.axes3d import Axes3D import numpy as np from matplotlib import cm from quantecon.compute_fp import compute_fixed_point import quantecon as qe # === solve for the value function === # wp = qe.career.workerProblem() v_init = np.ones((wp.N, wp.N)) * 100 v = compute_fixed_point(qe.career.bellman, wp, v_init) # === plot value function === # fig = plt.figure(figsize=(8, 6)) ax = fig.add_subplot(111, projection='3d') tg, eg = np.meshgrid(wp.theta, wp.epsilon) ax.plot_surface(tg, eg, v.T, rstride=2, cstride=2, cmap=cm.jet, alpha=0.5, linewidth=0.25) ax.set_zlim(150, 200) ax.set_xlabel('theta', fontsize=14)