{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "\n", "
\n", " \n", " \"QuantEcon\"\n", " \n", "
" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# The Aiyagari Model" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Overview\n", "\n", "In this lecture we describe the structure of a class of models that build on work by Truman Bewley [[Bew77]](zreferences.ipynb#bewley1977)\n", "\n", "We begin by discussing an example of a Bewley model due to Rao Aiyagari\n", "\n", "The model features\n", "\n", "- Heterogeneous agents \n", "- A single exogenous vehicle for borrowing and lending \n", "- Limits on amounts individual agents may borrow \n", "\n", "\n", "The Aiyagari model has been used to investigate many topics, including\n", "\n", "- precautionary savings and the effect of liquidity constraints [[Aiy94]](zreferences.ipynb#aiyagari1994) \n", "- risk sharing and asset pricing [[HL96]](zreferences.ipynb#heaton1996) \n", "- the shape of the wealth distribution [[BBZ15]](zreferences.ipynb#benhabib2015) \n", "- etc., etc., etc. " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### References\n", "\n", "The primary reference for this lecture is [[Aiy94]](zreferences.ipynb#aiyagari1994)\n", "\n", "A textbook treatment is available in chapter 18 of [[LS18]](zreferences.ipynb#ljungqvist2012)\n", "\n", "A continuous time version of the model by SeHyoun Ahn and Benjamin Moll can be found [here](http://nbviewer.jupyter.org/github/QuantEcon/QuantEcon.notebooks/blob/master/aiyagari_continuous_time.ipynb)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## The Economy" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Households\n", "\n", "Infinitely lived households / consumers face idiosyncratic income shocks\n", "\n", "A unit interval of *ex ante* identical households face a common borrowing constraint\n", "\n", "The savings problem faced by a typical household is\n", "\n", "$$\n", "\\max \\mathbb E \\sum_{t=0}^{\\infty} \\beta^t u(c_t)\n", "$$\n", "\n", "subject to\n", "\n", "$$\n", "a_{t+1} + c_t \\leq w z_t + (1 + r) a_t\n", "\\quad\n", "c_t \\geq 0,\n", "\\quad \\text{and} \\quad\n", "a_t \\geq -B\n", "$$\n", "\n", "where\n", "\n", "- $ c_t $ is current consumption \n", "- $ a_t $ is assets \n", "- $ z_t $ is an exogenous component of labor income capturing stochastic unemployment risk, etc. \n", "- $ w $ is a wage rate \n", "- $ r $ is a net interest rate \n", "- $ B $ is the maximum amount that the agent is allowed to borrow \n", "\n", "\n", "The exogenous process $ \\{z_t\\} $ follows a finite state Markov chain with given stochastic matrix $ P $\n", "\n", "The wage and interest rate are fixed over time\n", "\n", "In this simple version of the model, households supply labor inelastically because they do not value leisure" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Firms\n", "\n", "Firms produce output by hiring capital and labor\n", "\n", "Firms act competitively and face constant returns to scale\n", "\n", "Since returns to scale are constant the number of firms does not matter\n", "\n", "Hence we can consider a single (but nonetheless competitive) representative firm\n", "\n", "The firm’s output is\n", "\n", "$$\n", "Y_t = A K_t^{\\alpha} N^{1 - \\alpha}\n", "$$\n", "\n", "where\n", "\n", "- $ A $ and $ \\alpha $ are parameters with $ A > 0 $ and $ \\alpha \\in (0, 1) $ \n", "- $ K_t $ is aggregate capital \n", "- $ N $ is total labor supply (which is constant in this simple version of the model) \n", "\n", "\n", "The firm’s problem is\n", "\n", "$$\n", "max_{K, N} \\left\\{ A K_t^{\\alpha} N^{1 - \\alpha} - (r + \\delta) K - w N \\right\\}\n", "$$\n", "\n", "The parameter $ \\delta $ is the depreciation rate\n", "\n", "From the first-order condition with respect to capital, the firm’s inverse demand for capital is\n", "\n", "\n", "\n", "$$\n", "r = A \\alpha \\left( \\frac{N}{K} \\right)^{1 - \\alpha} - \\delta \\tag{1}\n", "$$\n", "\n", "Using this expression and the firm’s first-order condition for labor, we can pin down\n", "the equilibrium wage rate as a function of $ r $ as\n", "\n", "\n", "\n", "$$\n", "w(r) = A (1 - \\alpha) (A \\alpha / (r + \\delta))^{\\alpha / (1 - \\alpha)} \\tag{2}\n", "$$" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Equilibrium\n", "\n", "We construct a *stationary rational expectations equilibrium* (SREE)\n", "\n", "In such an equilibrium\n", "\n", "- prices induce behavior that generates aggregate quantities consistent with the prices \n", "- aggregate quantities and prices are constant over time \n", "\n", "\n", "In more detail, an SREE lists a set of prices, savings and production policies such that\n", "\n", "- households want to choose the specified savings policies taking the prices as given \n", "- firms maximize profits taking the same prices as given \n", "- the resulting aggregate quantities are consistent with the prices; in particular, the demand for capital equals the supply \n", "- aggregate quantities (defined as cross-sectional averages) are constant \n", "\n", "\n", "In practice, once parameter values are set, we can check for an SREE by the following steps\n", "\n", "1. pick a proposed quantity $ K $ for aggregate capital \n", "1. determine corresponding prices, with interest rate $ r $ determined by [(1)](#equation-aiy-rgk) and a wage rate $ w(r) $ as given in [(2)](#equation-aiy-wgr) \n", "1. determine the common optimal savings policy of the households given these prices \n", "1. compute aggregate capital as the mean of steady state capital given this savings policy \n", "\n", "\n", "If this final quantity agrees with $ K $ then we have a SREE" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Code\n", "\n", "Let’s look at how we might compute such an equilibrium in practice\n", "\n", "To solve the household’s dynamic programming problem we’ll use the [DiscreteDP](https://github.com/QuantEcon/QuantEcon.jl/blob/master/src/markov/ddp.jl) type from [QuantEcon.jl](http://quantecon.org/julia_index.html)\n", "\n", "Our first task is the least exciting one: write code that maps parameters for a household problem into the `R` and `Q` matrices needed to generate an instance of `DiscreteDP`\n", "\n", "Below is a piece of boilerplate code that does just this\n", "\n", "In reading the code, the following information will be helpful\n", "\n", "- `R` needs to be a matrix where `R[s, a]` is the reward at state `s` under action `a` \n", "- `Q` needs to be a three dimensional array where `Q[s, a, s']` is the probability of transitioning to state `s'` when the current state is `s` and the current action is `a` \n", "\n", "\n", "(For a detailed discussion of `DiscreteDP` see [this lecture](dynamic_programming/discrete_dp.ipynb))\n", "\n", "Here we take the state to be $ s_t := (a_t, z_t) $, where $ a_t $ is assets and $ z_t $ is the shock\n", "\n", "The action is the choice of next period asset level $ a_{t+1} $\n", "\n", "The object also includes a default set of parameters that we’ll adopt unless otherwise specified" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Setup" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "hide-output": true }, "outputs": [], "source": [ "using InstantiateFromURL\n", "github_project(\"QuantEcon/quantecon-notebooks-julia\", version = \"0.2.0\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "hide-output": false }, "outputs": [], "source": [ "using LinearAlgebra, Statistics, Compat" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "hide-output": false }, "outputs": [], "source": [ "using Parameters, Plots, QuantEcon\n", "gr(fmt = :png);" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "hide-output": false }, "outputs": [], "source": [ "Household = @with_kw (r = 0.01,\n", " w = 1.0,\n", " σ = 1.0,\n", " β = 0.96,\n", " z_chain = MarkovChain([0.9 0.1; 0.1 0.9], [0.1; 1.0]),\n", " a_min = 1e-10,\n", " a_max = 18.0,\n", " a_size = 200,\n", " a_vals = range(a_min, a_max, length = a_size),\n", " z_size = length(z_chain.state_values),\n", " n = a_size * z_size,\n", " s_vals = gridmake(a_vals, z_chain.state_values),\n", " s_i_vals = gridmake(1:a_size, 1:z_size),\n", " u = σ == 1 ? x -> log(x) : x -> (x^(1 - σ) - 1) / (1 - σ),\n", " R = setup_R!(fill(-Inf, n, a_size), a_vals, s_vals, r, w, u),\n", " # -Inf is the utility of dying (0 consumption)\n", " Q = setup_Q!(zeros(n, a_size, n), s_i_vals, z_chain))\n", "\n", "function setup_Q!(Q, s_i_vals, z_chain)\n", " for next_s_i in 1:size(Q, 3)\n", " for a_i in 1:size(Q, 2)\n", " for s_i in 1:size(Q, 1)\n", " z_i = s_i_vals[s_i, 2]\n", " next_z_i = s_i_vals[next_s_i, 2]\n", " next_a_i = s_i_vals[next_s_i, 1]\n", " if next_a_i == a_i\n", " Q[s_i, a_i, next_s_i] = z_chain.p[z_i, next_z_i]\n", " end\n", " end\n", " end\n", " end\n", " return Q\n", "end\n", "\n", "function setup_R!(R, a_vals, s_vals, r, w, u)\n", " for new_a_i in 1:size(R, 2)\n", " a_new = a_vals[new_a_i]\n", " for s_i in 1:size(R, 1)\n", " a = s_vals[s_i, 1]\n", " z = s_vals[s_i, 2]\n", " c = w * z + (1 + r) * a - a_new\n", " if c > 0\n", " R[s_i, new_a_i] = u(c)\n", " end\n", " end\n", " end\n", " return R\n", "end" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "As a first example of what we can do, let’s compute and plot an optimal accumulation policy at fixed prices" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "hide-output": false }, "outputs": [], "source": [ "# Create an instance of Household\n", "am = Household(a_max = 20.0, r = 0.03, w = 0.956)\n", "\n", "# Use the instance to build a discrete dynamic program\n", "am_ddp = DiscreteDP(am.R, am.Q, am.β)\n", "\n", "# Solve using policy function iteration\n", "results = solve(am_ddp, PFI)\n", "\n", "# Simplify names\n", "@unpack z_size, a_size, n, a_vals = am\n", "z_vals = am.z_chain.state_values\n", "\n", "# Get all optimal actions across the set of\n", "# a indices with z fixed in each column\n", "a_star = reshape([a_vals[results.sigma[s_i]] for s_i in 1:n], a_size, z_size)\n", "\n", "labels = [\"z = z_vals[1]\", \"z = z_vals[2]\"]\n", "plot(a_vals, a_star, label = labels, lw = 2, alpha = 0.6)\n", "plot!(a_vals, a_vals, label = \"\", color = :black, linestyle = :dash)\n", "plot!(xlabel = \"current assets\", ylabel = \"next period assets\", grid = false)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The plot shows asset accumulation policies at different values of the exogenous state\n", "\n", "Now we want to calculate the equilibrium\n", "\n", "Let’s do this visually as a first pass\n", "\n", "The following code draws aggregate supply and demand curves\n", "\n", "The intersection gives equilibrium interest rates and capital" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "hide-output": false }, "outputs": [], "source": [ "# Firms' parameters\n", "const A = 1\n", "const N = 1\n", "const α = 0.33\n", "const β = 0.96\n", "const δ = 0.05\n", "\n", "function r_to_w(r)\n", " return A * (1 - α) * (A * α / (r + δ)) ^ (α / (1 - α))\n", "end\n", "\n", "function rd(K)\n", " return A * α * (N / K) ^ (1 - α) - δ\n", "end\n", "\n", "function prices_to_capital_stock(am, r)\n", "\n", " # Set up problem\n", " w = r_to_w(r)\n", " @unpack a_vals, s_vals, u = am\n", " setup_R!(am.R, a_vals, s_vals, r, w, u)\n", "\n", " aiyagari_ddp = DiscreteDP(am.R, am.Q, am.β)\n", "\n", " # Compute the optimal policy\n", " results = solve(aiyagari_ddp, PFI)\n", "\n", " # Compute the stationary distribution\n", " stationary_probs = stationary_distributions(results.mc)[:, 1][1]\n", "\n", " # Return K\n", " return dot(am.s_vals[:, 1], stationary_probs)\n", "end\n", "\n", "# Create an instance of Household\n", "am = Household(β = β, a_max = 20.0)\n", "\n", "# Create a grid of r values at which to compute demand and supply of capital\n", "r_vals = range(0.005, 0.04, length = 20)\n", "\n", "# Compute supply of capital\n", "k_vals = prices_to_capital_stock.(Ref(am), r_vals)\n", "\n", "# Plot against demand for capital by firms\n", "demand = rd.(k_vals)\n", "labels = [\"demand for capital\" \"supply of capital\"]\n", "plot(k_vals, [demand r_vals], label = labels, lw = 2, alpha = 0.6)\n", "plot!(xlabel = \"capital\", ylabel = \"interest rate\", xlim = (2, 14), ylim = (0.0, 0.1))" ] } ], "metadata": { "filename": "aiyagari.rst", "kernelspec": { "display_name": "Julia 1.2", "language": "julia", "name": "julia-1.2" }, "title": "The Aiyagari Model" }, "nbformat": 4, "nbformat_minor": 2 }