Ejemplo n.º 1
0
"""
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':
Ejemplo n.º 2
0
"""
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'
Ejemplo n.º 3
0
"""
Filename: odu_plot_densities.py
Authors: John Stachurski, Thomas J. Sargent

"""
import numpy as np
import matplotlib.pyplot as plt
from quantecon import odu_vfi

sp = odu_vfi.searchProblem(F_a=1, F_b=1, G_a=3, G_b=1.2)
grid = np.linspace(0, 2, 150)
fig, ax = plt.subplots()
ax.plot(grid, sp.f(grid), label=r'$f$', lw=2)
ax.plot(grid, sp.g(grid), label=r'$g$', lw=2)
ax.legend(loc=0)
plt.show()