{
"cells": [
{
"cell_type": "markdown",
"id": "1464f333",
"metadata": {},
"source": [
"# Consumption Smoothing"
]
},
{
"cell_type": "markdown",
"id": "8516a58b",
"metadata": {},
"source": [
"## Overview\n",
"\n",
"Technically, this lecture is a sequel to this quantecon lecture [present values](https://intro.quantecon.org/pv.html), although it might not seem so at first.\n",
"\n",
"It will take a while for a “present value” or asset price explicilty to appear in this lecture, but when it does it will be a key actor.\n",
"\n",
"In this lecture, we’ll study a famous model of the “consumption function” that Milton Friedman [[Fri56](https://intro.quantecon.org/zreferences.html#id175)] and Robert Hall [[Hal78](https://intro.quantecon.org/zreferences.html#id176)]) proposed to fit some empirical data patterns that the simple Keynesian model described in this quantecon lecture [geometric series](https://intro.quantecon.org/geom_series.html) had missed.\n",
"\n",
"The key insight of Friedman and Hall was that today’s consumption ought not to depend just on today’s non-financial income: it should also depend on a person’s anticipations of her **future** non-financial incomes at various dates.\n",
"\n",
"In this lecture, we’ll study what is sometimes called the “consumption-smoothing model” using only linear algebra, in particular matrix multiplication and matrix inversion.\n",
"\n",
"Formulas presented in [present value formulas](https://intro.quantecon.org/pv.html) are at the core of the consumption smoothing model because they are used to define a consumer’s “human wealth”.\n",
"\n",
"As usual, we’ll start with by importing some Python modules."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "df2e2560",
"metadata": {
"hide-output": false
},
"outputs": [],
"source": [
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"from collections import namedtuple"
]
},
{
"cell_type": "markdown",
"id": "e4bcd991",
"metadata": {},
"source": [
"Our model describes the behavior of a consumer who lives from time $ t=0, 1, \\ldots, T $, receives a stream $ \\{y_t\\}_{t=0}^T $ of non-financial income and chooses a consumption stream $ \\{c_t\\}_{t=0}^T $.\n",
"\n",
"We usually think of the non-financial income stream as coming from the person’s salary from supplying labor.\n",
"\n",
"The model takes that non-financial income stream as an input, regarding it as “exogenous” in the sense of not being determined by the model.\n",
"\n",
"The consumer faces a gross interest rate of $ R >1 $ that is constant over time, at which she is free to borrow or lend, up to some limits that we’ll describe below.\n",
"\n",
"To set up the model, let\n",
"\n",
"- $ T \\geq 2 $ be a positive integer that constitutes a time-horizon \n",
"- $ y = \\{y_t\\}_{t=0}^T $ be an exogenous sequence of non-negative non-financial incomes $ y_t $ \n",
"- $ a = \\{a_t\\}_{t=0}^{T+1} $ be a sequence of financial wealth \n",
"- $ c = \\{c_t\\}_{t=0}^T $ be a sequence of non-negative consumption rates \n",
"- $ R \\geq 1 $ be a fixed gross one period rate of return on financial assets \n",
"- $ \\beta \\in (0,1) $ be a fixed discount factor \n",
"- $ a_0 $ be a given initial level of financial assets \n",
"- $ a_{T+1} \\geq 0 $ be a terminal condition on final assets \n",
"\n",
"\n",
"While the sequence of financial wealth $ a $ is to be determined by the model, it must satisfy two **boundary conditions** that require it to be equal to $ a_0 $ at time $ 0 $ and $ a_{T+1} $ at time $ T+1 $.\n",
"\n",
"The **terminal condition** $ a_{T+1} \\geq 0 $ requires that the consumer not die leaving debts.\n",
"\n",
"(We’ll see that a utility maximizing consumer won’t **want** to die leaving positive assets, so she’ll arrange her affairs to make\n",
"\\$a_{T+1} = 0.)\n",
"\n",
"The consumer faces a sequence of budget constraints that constrains the triple of sequences $ y, c, a $\n",
"\n",
"\n",
"\n",
"$$\n",
"a_{t+1} = R (a_t+ y_t - c_t), \\quad t =0, 1, \\ldots T \\tag{9.1}\n",
"$$\n",
"\n",
"Notice that there are $ T+1 $ such budget constraints, one for each $ t=0, 1, \\ldots, T $.\n",
"\n",
"Given a sequence $ y $ of non-financial income, there is a big set of **pairs** $ (a, c) $ of (financial wealth, consumption) sequences that satisfy the sequence of budget constraints [(9.1)](#equation-eq-a-t).\n",
"\n",
"Our model has the following logical flow.\n",
"\n",
"- start with an exogenous non-financial income sequence $ y $, an initial financial wealth $ a_0 $, and\n",
" a candidate consumption path $ c $. \n",
"- use the system of equations [(9.1)](#equation-eq-a-t) for $ t=0, \\ldots, T $ to compute a path $ a $ of financial wealth \n",
"- verify that $ a_{T+1} $ satisfies the terminal wealth constraint $ a_{T+1} \\geq 0 $. \n",
" - If it does, declare that the candidate path is **budget feasible**. \n",
" - if the candidate consumption path is not budget feasible, propose a path with less consumption sometimes and start over \n",
"\n",
"\n",
"Below, we’ll describe how to execute these steps using linear algebra – matrix inversion and multiplication.\n",
"\n",
"The above procedure seems like a sensible way to find “budget-feasible” consumption paths $ c $, i.e., paths that are consistent\n",
"with the exogenous non-financial income stream $ y $, the initial financial asset level $ a_0 $, and the terminal asset level $ a_{T+1} $.\n",
"\n",
"In general, there will be many budget feasible consumption paths $ c $.\n",
"\n",
"Among all budget-feasible consumption paths, which one **should** the consumer want to choose?\n",
"\n",
"We shall eventually evaluate alternative budget feasible consumption paths $ c $ using the following **welfare criterion**\n",
"\n",
"\n",
"\n",
"$$\n",
"W = \\sum_{t=0}^T \\beta^t (g_1 c_t - \\frac{g_2}{2} c_t^2 ) \\tag{9.2}\n",
"$$\n",
"\n",
"where $ g_1 > 0, g_2 > 0 $.\n",
"\n",
"The fact that the utility function $ g_1 c_t - \\frac{g_2}{2} c_t^2 $ has diminishing marginal utility imparts a preference for consumption that is very smooth when $ \\beta R \\approx 1 $.\n",
"\n",
"Indeed, we shall see that when $ \\beta R = 1 $ (a condition assumed by Milton Friedman [[Fri56](https://intro.quantecon.org/zreferences.html#id175)] and Robert Hall [[Hal78](https://intro.quantecon.org/zreferences.html#id176)]), this criterion assigns higher welfare to **smoother** consumption paths.\n",
"\n",
"By **smoother** we mean as close as possible to being constant over time.\n",
"\n",
"The preference for smooth consumption paths that is built into the model gives it the name “consumption smoothing model”.\n",
"\n",
"Let’s dive in and do some calculations that will help us understand how the model works.\n",
"\n",
"Here we use default parameters $ R = 1.05 $, $ g_1 = 1 $, $ g_2 = 1/2 $, and $ T = 65 $.\n",
"\n",
"We create a namedtuple to store these parameters with default values."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "c7f96887",
"metadata": {
"hide-output": false
},
"outputs": [],
"source": [
"ConsumptionSmoothing = namedtuple(\"ConsumptionSmoothing\", \n",
" [\"R\", \"g1\", \"g2\", \"β_seq\", \"T\"])\n",
"\n",
"def creat_cs_model(R=1.05, g1=1, g2=1/2, T=65):\n",
" β = 1/R\n",
" β_seq = np.array([β**i for i in range(T+1)])\n",
" return ConsumptionSmoothing(R=1.05, g1=1, g2=1/2, \n",
" β_seq=β_seq, T=65)"
]
},
{
"cell_type": "markdown",
"id": "065f8e56",
"metadata": {},
"source": [
"## Friedman-Hall consumption-smoothing model\n",
"\n",
"A key object in the model is what Milton Friedman called “human” or “non-financial” wealth at time $ 0 $:\n",
"\n",
"$$\n",
"h_0 \\equiv \\sum_{t=0}^T R^{-t} y_t = \\begin{bmatrix} 1 & R^{-1} & \\cdots & R^{-T} \\end{bmatrix}\n",
"\\begin{bmatrix} y_0 \\cr y_1 \\cr \\vdots \\cr y_T \\end{bmatrix}\n",
"$$\n",
"\n",
"Human or non-financial wealth is evidently just the present value at time $ 0 $ of the consumer’s non-financial income stream $ y $.\n",
"\n",
"Notice that formally it very much resembles the asset price that we computed in this quantecon lecture [present values](https://intro.quantecon.org/pv.html).\n",
"\n",
"Indeed, this is why Milton Friedman called it “human capital”.\n",
"\n",
"By iterating on equation [(9.1)](#equation-eq-a-t) and imposing the terminal condition\n",
"\n",
"$$\n",
"a_{T+1} = 0,\n",
"$$\n",
"\n",
"it is possible to convert a sequence of budget constraints into the single intertemporal constraint\n",
"\n",
"$$\n",
"\\sum_{t=0}^T R^{-t} c_t = a_0 + h_0,\n",
"$$\n",
"\n",
"which says that the present value of the consumption stream equals the sum of finanical and non-financial (or human) wealth.\n",
"\n",
"Robert Hall [[Hal78](https://intro.quantecon.org/zreferences.html#id176)] showed that when $ \\beta R = 1 $, a condition Milton Friedman had also assumed,\n",
"it is “optimal” for a consumer to **smooth consumption** by setting\n",
"\n",
"$$\n",
"c_t = c_0 \\quad t =0, 1, \\ldots, T\n",
"$$\n",
"\n",
"(Later we’ll present a “variational argument” that shows that this constant path is indeed optimal when $ \\beta R =1 $.)\n",
"\n",
"In this case, we can use the intertemporal budget constraint to write\n",
"\n",
"\n",
"\n",
"$$\n",
"c_t = c_0 = \\left(\\sum_{t=0}^T R^{-t}\\right)^{-1} (a_0 + h_0), \\quad t= 0, 1, \\ldots, T. \\tag{9.3}\n",
"$$\n",
"\n",
"Equation [(9.3)](#equation-eq-conssmoothing) is the consumption-smoothing model in a nutshell."
]
},
{
"cell_type": "markdown",
"id": "95ee9948",
"metadata": {},
"source": [
"## Mechanics of Consumption smoothing model\n",
"\n",
"As promised, we’ll provide step by step instructions on how to use linear algebra, readily implemented\n",
"in Python, to compute all the objects in play in the consumption-smoothing model.\n",
"\n",
"In the calculations below, we’ll set default values of $ R > 1 $, e.g., $ R = 1.05 $, and $ \\beta = R^{-1} $."
]
},
{
"cell_type": "markdown",
"id": "f80bc710",
"metadata": {},
"source": [
"### Step 1\n",
"\n",
"For some $ (T+1) \\times 1 $ $ y $ vector, use matrix algebra to compute $ h_0 $\n",
"\n",
"$$\n",
"\\sum_{t=0}^T R^{-t} y_t = \\begin{bmatrix} 1 & R^{-1} & \\cdots & R^{-T} \\end{bmatrix}\n",
"\\begin{bmatrix} y_0 \\cr y_1 \\cr \\vdots \\cr y_T \\end{bmatrix}\n",
"$$"
]
},
{
"cell_type": "markdown",
"id": "5d294df3",
"metadata": {},
"source": [
"### Step 2\n",
"\n",
"Compute the optimal level of consumption $ c_0 $\n",
"\n",
"$$\n",
"c_t = c_0 = \\left( \\frac{1 - R^{-1}}{1 - R^{-(T+1)}} \\right) (a_0 + \\sum_{t=0}^T R^t y_t ) , \\quad t = 0, 1, \\ldots, T\n",
"$$"
]
},
{
"cell_type": "markdown",
"id": "2b190e5e",
"metadata": {},
"source": [
"### Step 3\n",
"\n",
"In this step, we use the system of equations [(9.1)](#equation-eq-a-t) for $ t=0, \\ldots, T $ to compute a path $ a $ of financial wealth.\n",
"\n",
"To do this, we translated that system of difference equations into a single matrix equation as follows (we’ll say more about the mechanics of using linear algebra to solve such difference equations later in the last part of this lecture):\n",
"\n",
"$$\n",
"\\begin{bmatrix} \n",
"1 & 0 & 0 & \\cdots & 0 & 0 & 0 \\cr\n",
"-R & 1 & 0 & \\cdots & 0 & 0 & 0 \\cr\n",
"0 & -R & 1 & \\cdots & 0 & 0 & 0 \\cr\n",
"\\vdots &\\vdots & \\vdots & \\cdots & \\vdots & \\vdots & \\vdots \\cr\n",
"0 & 0 & 0 & \\cdots & -R & 1 & 0 \\cr\n",
"0 & 0 & 0 & \\cdots & 0 & -R & 1\n",
"\\end{bmatrix} \n",
"\\begin{bmatrix} a_1 \\cr a_2 \\cr a_3 \\cr \\vdots \\cr a_T \\cr a_{T+1} \n",
"\\end{bmatrix}\n",
"= R \n",
"\\begin{bmatrix} y_0 + a_0 - c_0 \\cr y_1 - c_0 \\cr y_2 - c_0 \\cr \\vdots\\cr y_{T-1} - c_0 \\cr y_T - c_0\n",
"\\end{bmatrix}\n",
"$$\n",
"\n",
"Multiply both sides by the inverse of the matrix on the left side to compute\n",
"\n",
"$$\n",
"\\begin{bmatrix} a_1 \\cr a_2 \\cr a_3 \\cr \\vdots \\cr a_T \\cr a_{T+1} \\end{bmatrix}\n",
"$$\n",
"\n",
"It should turn out automatically that\n",
"\n",
"$$\n",
"a_{T+1} = 0.\n",
"$$\n",
"\n",
"We have built into the our calculations that the consumer leaves life with exactly zero assets, just barely satisfying the\n",
"terminal condition that $ a_{T+1} \\geq 0 $.\n",
"\n",
"Let’s verify this with our Python code.\n",
"\n",
"First we implement this model in `compute_optimal`"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "c27e3156",
"metadata": {
"hide-output": false
},
"outputs": [],
"source": [
"def compute_optimal(model, a0, y_seq):\n",
" R, T = model.R, model.T\n",
"\n",
" # non-financial wealth\n",
" h0 = model.β_seq @ y_seq # since β = 1/R\n",
"\n",
" # c0\n",
" c0 = (1 - 1/R) / (1 - (1/R)**(T+1)) * (a0 + h0)\n",
" c_seq = c0*np.ones(T+1)\n",
"\n",
" # verify\n",
" A = np.diag(-R*np.ones(T), k=-1) + np.eye(T+1)\n",
" b = y_seq - c_seq\n",
" b[0] = b[0] + a0\n",
"\n",
" a_seq = np.linalg.inv(A) @ b\n",
" a_seq = np.concatenate([[a0], a_seq])\n",
"\n",
" return c_seq, a_seq"
]
},
{
"cell_type": "markdown",
"id": "ae79c760",
"metadata": {},
"source": [
"We use an example where the consumer inherits $ a_0<0 $ (which can be interpreted as a student debt).\n",
"\n",
"The non-financial process $ \\{y_t\\}_{t=0}^{T} $ is constant and positive up to $ t=45 $ and then becomes zero afterward."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "42c57395",
"metadata": {
"hide-output": false
},
"outputs": [],
"source": [
"# Financial wealth\n",
"a0 = -2 # such as \"student debt\"\n",
"\n",
"# non-financial Income process\n",
"y_seq = np.concatenate([np.ones(46), np.zeros(20)])\n",
"\n",
"cs_model = creat_cs_model()\n",
"c_seq, a_seq = compute_optimal(cs_model, a0, y_seq)\n",
"\n",
"print('check a_T+1=0:', \n",
" np.abs(a_seq[-1] - 0) <= 1e-8)"
]
},
{
"cell_type": "markdown",
"id": "4103e837",
"metadata": {},
"source": [
"The visualization shows the path of non-financial income, consumption, and financial assets."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "93d93399",
"metadata": {
"hide-output": false
},
"outputs": [],
"source": [
"# Sequence Length\n",
"T = cs_model.T\n",
"\n",
"plt.plot(range(T+1), y_seq, label='non-financial income')\n",
"plt.plot(range(T+1), c_seq, label='consumption')\n",
"plt.plot(range(T+2), a_seq, label='financial wealth')\n",
"plt.plot(range(T+2), np.zeros(T+2), '--')\n",
"\n",
"plt.legend()\n",
"plt.xlabel(r'$t$')\n",
"plt.ylabel(r'$c_t,y_t,a_t$')\n",
"plt.show()"
]
},
{
"cell_type": "markdown",
"id": "59d07067",
"metadata": {},
"source": [
"Note that $ a_{T+1} = 0 $ is satisfied.\n",
"\n",
"We can further evaluate the welfare using the formula [(9.2)](#equation-welfare)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b2b80469",
"metadata": {
"hide-output": false
},
"outputs": [],
"source": [
"def welfare(model, c_seq):\n",
" β_seq, g1, g2 = model.β_seq, model.g1, model.g2\n",
"\n",
" u_seq = g1 * c_seq - g2/2 * c_seq**2\n",
" return β_seq @ u_seq\n",
"\n",
"print('Welfare:', welfare(cs_model, c_seq))"
]
},
{
"cell_type": "markdown",
"id": "013a2be6",
"metadata": {},
"source": [
"### Feasible consumption variations\n",
"\n",
"Earlier, we had promised to present an argument that supports our claim that a constant consumption play $ c_t = c_0 $ for all\n",
"$ t $ is optimal.\n",
"\n",
"Let’s do that now.\n",
"\n",
"Although simple and direct, the approach we’ll take is actually an example of what is called the “calculus of variations”.\n",
"\n",
"Let’s dive in and see what the key idea is.\n",
"\n",
"To explore what types of consumption paths are welfare-improving, we shall create an **admissible consumption path variation sequence** $ \\{v_t\\}_{t=0}^T $\n",
"that satisfies\n",
"\n",
"$$\n",
"\\sum_{t=0}^T R^{-t} v_t = 0\n",
"$$\n",
"\n",
"This equation says that the **present value** of admissible variations must be zero.\n",
"\n",
"(So once again, we encounter our formula for the present value of an “asset”.)\n",
"\n",
"Here we’ll compute a two-parameter class of admissible variations\n",
"of the form\n",
"\n",
"$$\n",
"v_t = \\xi_1 \\phi^t - \\xi_0\n",
"$$\n",
"\n",
"We say two and not three-parameter class because $ \\xi_0 $ will be a function of $ (\\phi, \\xi_1; R) $ that guarantees that the variation is feasible.\n",
"\n",
"Let’s compute that function.\n",
"\n",
"We require\n",
"\n",
"$$\n",
"\\sum_{t=0}^T \\left[ \\xi_1 \\phi^t - \\xi_0 \\right] = 0\n",
"$$\n",
"\n",
"which implies that\n",
"\n",
"$$\n",
"\\xi_1 \\sum_{t=0}^T \\phi_t R^{-t} - \\xi_0 \\sum_{t=0}^T R^{-t} = 0\n",
"$$\n",
"\n",
"which implies that\n",
"\n",
"$$\n",
"\\xi_1 \\frac{1 - (\\phi R^{-1})^{T+1}}{1 - \\phi R^{-1}} - \\xi_0 \\frac{1 - R^{-(T+1)}}{1-R^{-1} } =0\n",
"$$\n",
"\n",
"which implies that\n",
"\n",
"$$\n",
"\\xi_0 = \\xi_0(\\phi, \\xi_1; R) = \\xi_1 \\left(\\frac{1 - R^{-1}}{1 - R^{-(T+1)}}\\right) \\left(\\frac{1 - (\\phi R^{-1})^{T+1}}{1 - \\phi R^{-1}}\\right)\n",
"$$\n",
"\n",
"This is our formula for $ \\xi_0 $.\n",
"\n",
"Evidently, if $ c^o $ is a budget-feasible consumption path, then so is $ c^o + v $,\n",
"where $ v $ is a budget-feasible variation.\n",
"\n",
"Given $ R $, we thus have a two parameter class of budget feasible variations $ v $ that we can use\n",
"to compute alternative consumption paths, then evaluate their welfare.\n",
"\n",
"Now let’s compute and visualize the variations"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "5100a181",
"metadata": {
"hide-output": false
},
"outputs": [],
"source": [
"def compute_variation(model, ξ1, ϕ, a0, y_seq, verbose=1):\n",
" R, T, β_seq = model.R, model.T, model.β_seq\n",
"\n",
" ξ0 = ξ1*((1 - 1/R) / (1 - (1/R)**(T+1))) * ((1 - (ϕ/R)**(T+1)) / (1 - ϕ/R))\n",
" v_seq = np.array([(ξ1*ϕ**t - ξ0) for t in range(T+1)])\n",
" \n",
" if verbose == 1:\n",
" print('check feasible:', np.isclose(β_seq @ v_seq, 0)) # since β = 1/R\n",
"\n",
" c_opt, _ = compute_optimal(model, a0, y_seq)\n",
" cvar_seq = c_opt + v_seq\n",
"\n",
" return cvar_seq"
]
},
{
"cell_type": "markdown",
"id": "8853da90",
"metadata": {},
"source": [
"We visualize variations with $ \\xi_1 \\in \\{.01, .05\\} $ and $ \\phi \\in \\{.95, 1.02\\} $"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "48530aa0",
"metadata": {
"hide-output": false
},
"outputs": [],
"source": [
"fig, ax = plt.subplots()\n",
"\n",
"ξ1s = [.01, .05]\n",
"ϕs= [.95, 1.02]\n",
"colors = {.01: 'tab:blue', .05: 'tab:green'}\n",
"\n",
"params = np.array(np.meshgrid(ξ1s, ϕs)).T.reshape(-1, 2)\n",
"\n",
"for i, param in enumerate(params):\n",
" ξ1, ϕ = param\n",
" print(f'variation {i}: ξ1={ξ1}, ϕ={ϕ}')\n",
" cvar_seq = compute_variation(model=cs_model, \n",
" ξ1=ξ1, ϕ=ϕ, a0=a0, \n",
" y_seq=y_seq)\n",
" print(f'welfare={welfare(cs_model, cvar_seq)}')\n",
" print('-'*64)\n",
" if i % 2 == 0:\n",
" ls = '-.'\n",
" else: \n",
" ls = '-' \n",
" ax.plot(range(T+1), cvar_seq, ls=ls, \n",
" color=colors[ξ1], \n",
" label=fr'$\\xi_1 = {ξ1}, \\phi = {ϕ}$')\n",
"\n",
"plt.plot(range(T+1), c_seq, \n",
" color='orange', label=r'Optimal $\\vec{c}$ ')\n",
"\n",
"plt.legend()\n",
"plt.xlabel(r'$t$')\n",
"plt.ylabel(r'$c_t$')\n",
"plt.show()"
]
},
{
"cell_type": "markdown",
"id": "56527715",
"metadata": {},
"source": [
"We can even use the Python `np.gradient` command to compute derivatives of welfare with respect to our two parameters.\n",
"\n",
"We are teaching the key idea beneath the **calculus of variations**.\n",
"\n",
"First, we define the welfare with respect to $ \\xi_1 $ and $ \\phi $"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "0213f00a",
"metadata": {
"hide-output": false
},
"outputs": [],
"source": [
"def welfare_rel(ξ1, ϕ):\n",
" \"\"\"\n",
" Compute welfare of variation sequence \n",
" for given ϕ, ξ1 with a consumption smoothing model\n",
" \"\"\"\n",
" \n",
" cvar_seq = compute_variation(cs_model, ξ1=ξ1, \n",
" ϕ=ϕ, a0=a0, \n",
" y_seq=y_seq, \n",
" verbose=0)\n",
" return welfare(cs_model, cvar_seq)\n",
"\n",
"# Vectorize the function to allow array input\n",
"welfare_vec = np.vectorize(welfare_rel)"
]
},
{
"cell_type": "markdown",
"id": "515ae5a2",
"metadata": {},
"source": [
"Then we can visualize the relationship between welfare and $ \\xi_1 $ and compute its derivatives"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "2436c6cf",
"metadata": {
"hide-output": false
},
"outputs": [],
"source": [
"ξ1_arr = np.linspace(-0.5, 0.5, 20)\n",
"\n",
"plt.plot(ξ1_arr, welfare_vec(ξ1_arr, 1.02))\n",
"plt.ylabel('welfare')\n",
"plt.xlabel(r'$\\xi_1$')\n",
"plt.show()\n",
"\n",
"welfare_grad = welfare_vec(ξ1_arr, 1.02)\n",
"welfare_grad = np.gradient(welfare_grad)\n",
"plt.plot(ξ1_arr, welfare_grad)\n",
"plt.ylabel('derivative of welfare')\n",
"plt.xlabel(r'$\\xi_1$')\n",
"plt.show()"
]
},
{
"cell_type": "markdown",
"id": "73ec2455",
"metadata": {},
"source": [
"The same can be done on $ \\phi $"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "62e79459",
"metadata": {
"hide-output": false
},
"outputs": [],
"source": [
"ϕ_arr = np.linspace(-0.5, 0.5, 20)\n",
"\n",
"plt.plot(ξ1_arr, welfare_vec(0.05, ϕ_arr))\n",
"plt.ylabel('welfare')\n",
"plt.xlabel(r'$\\phi$')\n",
"plt.show()\n",
"\n",
"welfare_grad = welfare_vec(0.05, ϕ_arr)\n",
"welfare_grad = np.gradient(welfare_grad)\n",
"plt.plot(ξ1_arr, welfare_grad)\n",
"plt.ylabel('derivative of welfare')\n",
"plt.xlabel(r'$\\phi$')\n",
"plt.show()"
]
},
{
"cell_type": "markdown",
"id": "6238044c",
"metadata": {},
"source": [
"## Wrapping up the consumption-smoothing model\n",
"\n",
"The consumption-smoothing model of Milton Friedman [[Fri56](https://intro.quantecon.org/zreferences.html#id175)] and Robert Hall [[Hal78](https://intro.quantecon.org/zreferences.html#id176)]) is a cornerstone of modern macro\n",
"that has important ramifications about the size of the Keynesian “fiscal policy multiplier” described briefly in\n",
"quantecon lecture [geometric series](https://intro.quantecon.org/geom_series.html).\n",
"\n",
"In particular, Milton Friedman and others showed that it **lowered** the fiscal policy multiplier relative to the one implied by\n",
"the simple Keynesian consumption function presented in [geometric series](https://intro.quantecon.org/geom_series.html).\n",
"\n",
"Friedman and Hall’s work opened the door to a lively literature on the aggregate consumption function and implied fiscal multipliers that\n",
"remains very active today."
]
},
{
"cell_type": "markdown",
"id": "8b3e0def",
"metadata": {},
"source": [
"## Difference equations with linear algebra\n",
"\n",
"In the preceding sections we have used linear algebra to solve a consumption smoothing model.\n",
"\n",
"The same tools from linear algebra – matrix multiplication and matrix inversion – can be used to study many other dynamic models too.\n",
"\n",
"We’ll concluse this lecture by giving a couple of examples.\n",
"\n",
"In particular, we’ll describe a useful way of representing and “solving” linear difference equations.\n",
"\n",
"To generate some $ y $ vectors, we’ll just write down a linear difference equation\n",
"with appropriate initial conditions and then use linear algebra to solve it."
]
},
{
"cell_type": "markdown",
"id": "f17aa0ef",
"metadata": {},
"source": [
"### First-order difference equation\n",
"\n",
"We’ll start with a first-order linear difference equation for $ \\{y_t\\}_{t=0}^T $:\n",
"\n",
"$$\n",
"y_{t} = \\lambda y_{t-1}, \\quad t = 1, 2, \\ldots, T\n",
"$$\n",
"\n",
"where $ y_0 $ is a given initial condition.\n",
"\n",
"We can cast this set of $ T $ equations as a single matrix equation\n",
"\n",
"$$\n",
"\\begin{bmatrix} \n",
"1 & 0 & 0 & \\cdots & 0 & 0 \\cr\n",
"-\\lambda & 1 & 0 & \\cdots & 0 & 0 \\cr\n",
"0 & -\\lambda & 1 & \\cdots & 0 & 0 \\cr\n",
" \\vdots & \\vdots & \\vdots & \\cdots & \\vdots & \\vdots \\cr\n",
"0 & 0 & 0 & \\cdots & -\\lambda & 1 \n",
"\\end{bmatrix} \n",
"\\begin{bmatrix}\n",
"y_1 \\cr y_2 \\cr y_3 \\cr \\vdots \\cr y_T \n",
"\\end{bmatrix}\n",
"= \n",
"\\begin{bmatrix} \n",
"\\lambda y_0 \\cr 0 \\cr 0 \\cr \\vdots \\cr 0 \n",
"\\end{bmatrix}\n",
"$$\n",
"\n",
"Multiplying both sides by inverse of the matrix on the left provides the solution\n",
"\n",
"\n",
"\n",
"$$\n",
"\\begin{bmatrix} \n",
"y_1 \\cr y_2 \\cr y_3 \\cr \\vdots \\cr y_T \n",
"\\end{bmatrix} \n",
"= \n",
"\\begin{bmatrix} \n",
"1 & 0 & 0 & \\cdots & 0 & 0 \\cr\n",
"\\lambda & 1 & 0 & \\cdots & 0 & 0 \\cr\n",
"\\lambda^2 & \\lambda & 1 & \\cdots & 0 & 0 \\cr\n",
" \\vdots & \\vdots & \\vdots & \\cdots & \\vdots & \\vdots \\cr\n",
"\\lambda^{T-1} & \\lambda^{T-2} & \\lambda^{T-3} & \\cdots & \\lambda & 1 \n",
"\\end{bmatrix}\n",
"\\begin{bmatrix} \n",
"\\lambda y_0 \\cr 0 \\cr 0 \\cr \\vdots \\cr 0 \n",
"\\end{bmatrix} \\tag{9.4}\n",
"$$"
]
},
{
"cell_type": "markdown",
"id": "1211c70b",
"metadata": {},
"source": [
"### Exercise 9.1\n",
"\n",
"In the [(9.4)](#equation-fst-ord-inverse), we multiply the inverse of the matrix $ A $. In this exercise, please confirm that\n",
"\n",
"$$\n",
"\\begin{bmatrix} \n",
"1 & 0 & 0 & \\cdots & 0 & 0 \\cr\n",
"\\lambda & 1 & 0 & \\cdots & 0 & 0 \\cr\n",
"\\lambda^2 & \\lambda & 1 & \\cdots & 0 & 0 \\cr\n",
" \\vdots & \\vdots & \\vdots & \\cdots & \\vdots & \\vdots \\cr\n",
"\\lambda^{T-1} & \\lambda^{T-2} & \\lambda^{T-3} & \\cdots & \\lambda & 1 \n",
"\\end{bmatrix}\n",
"$$\n",
"\n",
"is the inverse of $ A $ and check that $ A A^{-1} = I $"
]
},
{
"cell_type": "markdown",
"id": "f2436444",
"metadata": {},
"source": [
"### Second order difference equation\n",
"\n",
"A second-order linear difference equation for $ \\{y_t\\}_{t=0}^T $ is\n",
"\n",
"$$\n",
"y_{t} = \\lambda_1 y_{t-1} + \\lambda_2 y_{t-2}, \\quad t = 1, 2, \\ldots, T\n",
"$$\n",
"\n",
"where now $ y_0 $ and $ y_{-1} $ are two given initial equations determined outside the model.\n",
"\n",
"As we did with the first-order difference equation, we can cast this set of $ T $ equations as a single matrix equation\n",
"\n",
"$$\n",
"\\begin{bmatrix} \n",
"1 & 0 & 0 & \\cdots & 0 & 0 & 0 \\cr\n",
"-\\lambda_1 & 1 & 0 & \\cdots & 0 & 0 & 0 \\cr\n",
"-\\lambda_2 & -\\lambda_1 & 1 & \\cdots & 0 & 0 & 0 \\cr\n",
" \\vdots & \\vdots & \\vdots & \\cdots & \\vdots & \\vdots \\cr\n",
"0 & 0 & 0 & \\cdots & -\\lambda_2 & -\\lambda_1 & 1 \n",
"\\end{bmatrix} \n",
"\\begin{bmatrix} \n",
"y_1 \\cr y_2 \\cr y_3 \\cr \\vdots \\cr y_T \n",
"\\end{bmatrix}\n",
"= \n",
"\\begin{bmatrix} \n",
"\\lambda_1 y_0 + \\lambda_2 y_{-1} \\cr \\lambda_2 y_0 \\cr 0 \\cr \\vdots \\cr 0 \n",
"\\end{bmatrix}\n",
"$$\n",
"\n",
"Multiplying both sides by inverse of the matrix on the left again provides the solution."
]
},
{
"cell_type": "markdown",
"id": "e62a4975",
"metadata": {},
"source": [
"### Exercise 9.2\n",
"\n",
"As an exercise, we ask you to represent and solve a **third order linear difference equation**.\n",
"How many initial conditions must you specify?"
]
}
],
"metadata": {
"date": 1696997364.8950112,
"filename": "cons_smooth.md",
"kernelspec": {
"display_name": "Python",
"language": "python3",
"name": "python3"
},
"title": "Consumption Smoothing"
},
"nbformat": 4,
"nbformat_minor": 5
}