def compute_asset_series(cp, T=500000): """ Simulates a time series of length T for assets, given optimal savings behavior. Parameter cp is an instance of consumerProblem """ Pi, z_vals, R = cp.Pi, cp.z_vals, cp.R # Simplify names v_init, c_init = initialize(cp) c = compute_fixed_point(coleman_operator, cp, c_init) cf = lambda a, i_z: interp(a, cp.asset_grid, c[:, i_z]) a = np.zeros(T+1) z_seq = mc_tools.sample_path(Pi, sample_size=T) for t in range(T): i_z = z_seq[t] a[t+1] = R * a[t] + z_vals[i_z] - cf(a[t], i_z) return a
from compute_fp import compute_fixed_point from matplotlib import pyplot as plt import numpy as np from ifp import coleman_operator, consumerProblem, initialize r_vals = np.linspace(0, 0.04, 4) fig, ax = plt.subplots() for r_val in r_vals: cp = consumerProblem(r=r_val) v_init, c_init = initialize(cp) c = compute_fixed_point(coleman_operator, cp, c_init) ax.plot(cp.asset_grid, c[:, 0], label=r'$r = %.3f$' % r_val) ax.set_xlabel('asset level') ax.set_ylabel('consumption (low income)') ax.legend(loc='upper left') plt.show()
from compute_fp import compute_fixed_point from matplotlib import pyplot as plt import numpy as np from ifp import coleman_operator, consumerProblem, initialize r_vals = np.linspace(0, 0.04, 4) fig, ax = plt.subplots() for r_val in r_vals: cp = consumerProblem(r=r_val) v_init, c_init = initialize(cp) c = compute_fixed_point(coleman_operator, cp, c_init) ax.plot(cp.asset_grid, c[:, 0], label=r'$r = %.3f$' % r_val) ax.set_xlabel('asset level') ax.set_ylabel('consumption (low income)') ax.legend(loc='upper left') plt.show()