""" w = r_to_w(r) am.set_prices(r, w) aiyagari_ddp = DiscreteDP(am.R, am.Q, beta) # Compute the optimal policy results = aiyagari_ddp.solve(method='policy_iteration') # Compute the stationary distribution stationary_probs = results.mc.stationary_distributions[0] # Extract the marginal distribution for assets asset_probs = asset_marginal(stationary_probs, am.a_size, am.z_size) # Return K return np.sum(asset_probs * am.a_vals) # Create an instance of Household am = Household(a_max=20) # Use the instance to build a discrete dynamic program am_ddp = DiscreteDP(am.R, am.Q, am.beta) # Create a grid of r values at which to compute demand and supply of capital num_points = 20 r_vals = np.linspace(0.005, 0.04, num_points) # Compute supply of capital k_vals = np.empty(num_points) for i, r in enumerate(r_vals): k_vals[i] = prices_to_capital_stock(am, r) # Plot against demand for capital by firms fig, ax = plt.subplots(figsize=(11, 8))
import numpy as np import quantecon as qe import matplotlib.pyplot as plt from aiyagari_household import Household from quantecon.markov import DiscreteDP # Example prices r = 0.03 w = 0.956 # Create an instance of Household am = Household(a_max=20, r=r, w=w) # Use the instance to build a discrete dynamic program am_ddp = DiscreteDP(am.R, am.Q, am.beta) # Solve using policy function iteration results = am_ddp.solve(method='policy_iteration') # Simplify names z_size, a_size = am.z_size, am.a_size z_vals, a_vals = am.z_vals, am.a_vals n = a_size * z_size # Get all optimal actions across the set of a indices with z fixed in each row a_star = np.empty((z_size, a_size)) for s_i in range(n): a_i = s_i // z_size z_i = s_i % z_size a_star[z_i, a_i] = a_vals[results.sigma[s_i]]