Skip to content

Commit b2d5885

Browse files
Tom's three new sandpit lectures
1 parent 1a1e771 commit b2d5885

File tree

3 files changed

+1119
-0
lines changed

3 files changed

+1119
-0
lines changed

sandpit/cagan_adaptive_v4.md

Lines changed: 395 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,395 @@
1+
## Adaptive expectations version of Cagan model
2+
3+
```python
4+
import numpy as np
5+
import matplotlib.pyplot as plt
6+
```
7+
8+
<!-- #region -->
9+
We'll use linear algebra to do some experiments with a "fiscal theory of the price level".
10+
11+
According to this model, when the government persistently spends more than it collects in taxes and prints money to finance the shortfall (called the "government deficit"), it puts upward pressure on the price level and generates
12+
persistent inflation.
13+
14+
Our model is an "adaptive expectations" version of a model that Philip Cagan used to study the monetary dynamics of hyperinflations.
15+
16+
It combines these components:
17+
18+
* a demand function for real money balances that says asserts that the logarithm of the quantity of real balances demanded depends inversely on the public's expected rate of inflation
19+
20+
* an **adaptive expectations** model that describes how the public's anticipated rate of inflation responds to past values of actual inflation
21+
22+
* an equilibrium condition that equates the demand for money to the supply
23+
24+
* an exogenous sequence of rates of growth of the money supply
25+
26+
Our model stays quite close to Cagan's original specification.
27+
28+
To facilitate using linear matrix algebra as our principal mathematical tool, we'll use a finite horizon version of
29+
the model.
30+
31+
Let
32+
33+
* $ m_t $ be the log of the supply of nominal money balances;
34+
* $\mu_t = m_{t+1} - m_t $ be the net rate of growth of nominal balances;
35+
* $p_t $ be the log of the price level;
36+
* $\pi_t = p_{t+1} - p_t $ be the net rate of inflation between $t$ and $ t+1$;
37+
* $\pi_t^*$ be the public's expected rate of inflation between $t$ and $t+1$;
38+
* $T$ the horizon -- i.e., the last period for which the model will determine $p_t$
39+
* $\pi_0^*$ public's initial expected rate of inflation between time $0$ and time $1$.
40+
41+
42+
The demand for real balances $\exp\left(\frac{m_t^d}{p_t}\right)$ is governed by the following version of the Cagan demand function
43+
44+
$$
45+
m_t^d - p_t = -\alpha \pi_t^* \: , \: \alpha > 0 ; \quad t = 0, 1, \ldots, T .
46+
$$ (eq:caganmd)
47+
48+
49+
This equation asserts that the demand for real balances
50+
is inversely related to the public's expected rate of inflation.
51+
52+
Equating the logarithm $m_t^d$ of the demand for money to the logarithm $m_t$ of the supply of money in equation {eq}`eq:caganmd` and solving for the logarithm $p_t$
53+
of the price level gives
54+
55+
$$
56+
p_t = m_t + \alpha \pi_t^*
57+
$$ (eq:eqfiscth1)
58+
59+
Taking the difference between equation {eq}`eq:eqfiscth1` at time $t+1$ and at time
60+
$t$ gives
61+
62+
63+
64+
$$
65+
\pi_t = \mu_t + \alpha \pi_{t+1}^* - \alpha \pi_t^*
66+
$$ (eq:eqpipi)
67+
68+
We assume that the expected rate of inflation $\pi_t^*$ is governed
69+
by the Friedman-Cagan adaptive expectations scheme
70+
71+
$$
72+
\pi_{t+1}^* = \lambda \pi_t^* + (1 -\lambda) \pi_t
73+
$$ (eq:adaptexpn)
74+
75+
As exogenous inputs into the model, we take initial conditions $m_0, \pi_0^*$
76+
and a money growth sequence $\vec \mu = \{\mu_t\}_{t=0}^T$.
77+
78+
As endogenous outputs of our model we want to find sequences $\vec \pi = \{\pi_t\}_{t=0}^T, \vec p = \{p_t\}_{t=0}^T$ as functions of the endogenous inputs.
79+
80+
We'll do some mental experiments by studying how the model outputs vary as we vary
81+
the model inputs.
82+
83+
<!-- #endregion -->
84+
85+
<!-- #region -->
86+
### Representing key equations with linear algebra
87+
88+
We begin by writing the equation {eq}`eq:adaptexpn` adaptive expectations model for $\pi_t^*$ for $t=0, \ldots, T$ as
89+
90+
91+
92+
$$
93+
\begin{bmatrix} 1 & 0 & 0 & \cdots & 0 & 0 \cr
94+
-\lambda & 1 & 0 & \cdots & 0 & 0 \cr
95+
0 & - \lambda & 1 & \cdots & 0 & 0 \cr
96+
\vdots & \vdots & \vdots & \cdots & \vdots & \vdots \cr
97+
0 & 0 & 0 & \cdots & -\lambda & 1
98+
\end{bmatrix}
99+
\begin{bmatrix} \pi_0^* \cr
100+
\pi_1^* \cr
101+
\pi_2^* \cr
102+
\vdots \cr
103+
\pi_{T+1}^*
104+
\end{bmatrix} =
105+
(1-\lambda) \begin{bmatrix}
106+
0 & 0 & 0 & \cdots & 0 \cr
107+
1 & 0 & 0 & \cdots & 0 \cr
108+
0 & 1 & 0 & \cdots & 0 \cr
109+
\vdots &\vdots & \vdots & \cdots & \vdots \cr
110+
0 & 0 & 0 & \cdots & 1 \end{bmatrix}
111+
\begin{bmatrix}\pi_0 \cr \pi_1 \cr \pi_2 \cr \vdots \cr \pi_T
112+
\end{bmatrix} +
113+
\begin{bmatrix} \pi_0^* \cr 0 \cr 0 \cr \vdots \cr 0 \end{bmatrix}
114+
$$
115+
116+
Write this equation as
117+
118+
$$
119+
A \vec \pi^* = (1-\lambda) B \vec \pi + \vec \pi_0^*
120+
$$ (eq:eq1)
121+
122+
where the $(T+2) \times (T+2) $matrix $A$, the $(T+2)\times (T+1)$ matrix $B$, and the vectors $\vec \pi^* , \vec \pi_0, \pi_0^*$
123+
are defined implicitly by aligning these two equations.
124+
<!-- #endregion -->
125+
126+
<!-- #region -->
127+
Next we write the key equation {eq}`eq:eqpipi` in matrix notation as
128+
129+
$$ \begin{bmatrix}
130+
\pi_0 \cr \pi_1 \cr \pi_1 \cr \vdots \cr \pi_T \end{bmatrix}
131+
= \begin{bmatrix}
132+
\mu_0 \cr \mu_1 \cr \mu_2 \cr \vdots \cr \mu_T \end{bmatrix}
133+
+ \begin{bmatrix} - \alpha & \alpha & 0 & \cdots & 0 & 0 \cr
134+
0 & -\alpha & \alpha & \cdots & 0 & 0 \cr
135+
0 & 0 & -\alpha & \cdots & 0 & 0 \cr
136+
\vdots & \vdots & \vdots & \cdots & \alpha & 0 \cr
137+
0 & 0 & 0 & \cdots & -\alpha & \alpha
138+
\end{bmatrix}
139+
\begin{bmatrix} \pi_0^* \cr
140+
\pi_1^* \cr
141+
\pi_2^* \cr
142+
\vdots \cr
143+
\pi_{T+1}^*
144+
\end{bmatrix}
145+
$$
146+
147+
Represent the previous equation system in terms of vectors and matrices as
148+
149+
$$
150+
\vec \pi = \vec \mu + C \vec \pi^*
151+
$$ (eq:eq2)
152+
153+
where the $(T+1) \times (T+2)$ matrix $C$ is defined implicitly to align this equation with the preceding
154+
equation system.
155+
156+
157+
158+
### Harvesting payoffs from our matrix formulation
159+
160+
161+
We now have all of the ingredients we need to solve for $\vec \pi$ as
162+
a function of $\vec \mu, \pi_0, \pi_0^*$.
163+
164+
Combine equations {eq}`eq:eq1`and {eq}`eq:eq2` to get
165+
166+
$$
167+
\begin{align*}
168+
A \vec \pi^* & = (1-\lambda) B \vec \pi + \vec \pi_0^* \cr
169+
& = (1-\lambda) B \left[ \vec \mu + C \vec \pi^* \right] + \vec \pi_0^*
170+
\end{align*}
171+
$$
172+
173+
which implies that
174+
175+
$$
176+
\left[ A - (1-\lambda) B C \right] \vec \pi^* = (1-\lambda) B \vec \mu+ \vec \pi_0^*
177+
$$
178+
179+
Multiplying both sides of the above equation by the inverse of the matrix on the left side gives
180+
181+
$$
182+
\vec \pi^* = \left[ A - (1-\lambda) B C \right]^{-1} \left[ (1-\lambda) B \vec \mu+ \vec \pi_0^* \right]
183+
$$ (eq:eq4)
184+
185+
Having solved equation {eq}`eq:eq4` for $\vec \pi^*$, we can use equation {eq}`eq:eq2` to solve for $\vec \pi$:
186+
187+
$$
188+
\vec \pi = \vec \mu + C \vec \pi^*
189+
$$
190+
191+
192+
We have thus solved for two of the key endogenous time series determined by our model, namely, the sequence $\vec \pi^*$
193+
of expected inflation rates and the sequence $\vec \pi$ of actual inflation rates.
194+
195+
Knowing these, we can then quickly calculate the associated sequence $\vec p$ of the logarithm of the price level
196+
from equation {eq}`eq:eqfiscth1`.
197+
198+
Let's fill in the details for this step.
199+
<!-- #endregion -->
200+
201+
Since we now know $\vec \mu$ it is easy to compute $\vec m$.
202+
203+
Thus, notice that we can represent the equations
204+
205+
$$
206+
m_{t+1} = m_t + \mu_t , \quad t = 0, 1, \ldots, T
207+
$$
208+
209+
as the matrix equation
210+
211+
$$
212+
\begin{bmatrix}
213+
1 & 0 & 0 & \cdots & 0 & 0 \cr
214+
-1 & 1 & 0 & \cdots & 0 & 0 \cr
215+
0 & -1 & 1 & \cdots & 0 & 0 \cr
216+
\vdots & \vdots & \vdots & \vdots & 0 & 0 \cr
217+
0 & 0 & 0 & \cdots & 1 & 0 \cr
218+
0 & 0 & 0 & \cdots & -1 & 1
219+
\end{bmatrix}
220+
\begin{bmatrix}
221+
m_1 \cr m_2 \cr m_3 \cr \vdots \cr m_T \cr m_{T+1}
222+
\end{bmatrix}
223+
= \begin{bmatrix}
224+
\mu_0 \cr \mu_1 \cr \mu_2 \cr \vdots \cr \mu_{T-1} \cr \mu_T
225+
\end{bmatrix}
226+
+ \begin{bmatrix}
227+
m_0 \cr 0 \cr 0 \cr \vdots \cr 0 \cr 0
228+
\end{bmatrix}
229+
$$ (eq:eq101)
230+
231+
Multiplying both sides of equation {eq}`eq:eq101` with the inverse of the matrix on the left will give
232+
233+
$$
234+
m_t = m_0 + \sum_{s=0}^{t-1} \mu_s, \quad t =1, \ldots, T+1
235+
$$ (eq:mcum)
236+
237+
Equation {eq}`eq:mcum` shows that the log of the money supply at $t$ equals the log $m_0$ of the initial money supply
238+
plus accumulation of rates of money growth between times $0$ and $t$.
239+
240+
We can then compute $p_t$ for each $t$ from equation {eq}`eq:eqfiscth1`.
241+
242+
We can write a compact formula for $\vec p $ as
243+
244+
$$
245+
\vec p = \vec m + \alpha \hat \pi^*
246+
$$
247+
248+
where
249+
250+
$$
251+
\hat \pi^* = \begin{bmatrix} \pi_0^* \cr
252+
\pi_1^* \cr
253+
\pi_2^* \cr
254+
\vdots \cr
255+
\pi_{T}^*
256+
\end{bmatrix},
257+
$$
258+
259+
which is just $\vec \pi^*$ with the last element dropped.
260+
261+
262+
263+
### Expectational Error Gap
264+
265+
Our computations will verify that
266+
267+
$$
268+
\hat \pi^* \neq \vec \pi,
269+
$$
270+
271+
so that in general
272+
273+
$$
274+
\pi_t^* \neq \pi_t, \quad t = 0, 1, \ldots , T
275+
$$ (eq:notre)
276+
277+
This outcome is typical in models in which adaptive expectations hypothesis like equation {eq}`eq:adaptexpn` appear as a
278+
component.
279+
280+
In a companion lecture, we'll discuss a version of the model that replaces hypothesis {eq}`eq:adaptexpn` with
281+
a "perfect foresight" or "rational expectations" hypothesis.
282+
283+
```python
284+
class Cagan_Adaptive:
285+
" Solve the Cagan model in finite time. "
286+
287+
def __init__(self, α, m0, Eπ0, μ_seq, T, λ):
288+
self.α, self.m0, self.Eπ0, self.μ_seq, self.T, self.λ = α, m0, Eπ0, μ_seq, T, λ
289+
290+
def solve(self):
291+
α, m0, Eπ0, μ_seq, T, λ = self.α, self.m0, self.Eπ0, self.μ_seq, self.T, self.λ
292+
293+
A = np.eye(T+2, T+2) - λ*np.eye(T+2, T+2, k=-1)
294+
B = np.eye(T+2, T+1, k=-1)
295+
C = -α*np.eye(T+1, T+2) + α*np.eye(T+1, T+2, k=1)
296+
Eπ0_seq = np.append(Eπ0, np.zeros(T+1))
297+
298+
# Eπ_seq is of length T+2
299+
Eπ_seq = np.linalg.inv(A - (1-λ)*B @ C) @ ((1-λ) * B @ μ_seq + Eπ0_seq)
300+
301+
# π_seq is of length T+1
302+
π_seq = μ_seq + C @ Eπ_seq
303+
304+
D = np.eye(T+1, T+1) - np.eye(T+1, T+1, k=-1)
305+
m0_seq = np.append(m0, np.zeros(T))
306+
307+
# m_seq is of length T+2
308+
m_seq = np.linalg.inv(D) @ (μ_seq + m0_seq)
309+
m_seq = np.append(m0, m_seq)
310+
311+
# p_seq is of length T+2
312+
p_seq = m_seq + α * Eπ_seq
313+
314+
return π_seq, Eπ_seq, m_seq, p_seq
315+
316+
317+
def solve_and_plot(α, m0, Eπ0, μ_seq, T, λ):
318+
319+
mc = Cagan_Adaptive(α=α, m0=m0, Eπ0=Eπ0, μ_seq=μ_seq, T=T, λ=λ)
320+
π_seq, Eπ_seq, m_seq, p_seq = mc.solve()
321+
T_seq = range(T+2)
322+
323+
fig, ax = plt.subplots(2, 3, figsize=[10,5], dpi=200)
324+
ax[0,0].plot(T_seq[:-1], μ_seq)
325+
ax[0,1].plot(T_seq[:-1], π_seq, label=r'$\pi_t$')
326+
ax[0,1].plot(T_seq, Eπ_seq, label=r'$\pi^{*}_{t}$')
327+
ax[0,2].plot(T_seq, m_seq - p_seq)
328+
ax[1,0].plot(T_seq, m_seq)
329+
ax[1,1].plot(T_seq, p_seq)
330+
331+
ax[0,0].set_ylabel(r'$\mu$')
332+
ax[0,0].set_xlabel(r'$t$')
333+
ax[0,1].set_ylabel(r'$\pi$')
334+
ax[0,1].set_xlabel(r'$t$')
335+
ax[0,2].set_xlabel(r'$t$')
336+
ax[0,2].set_ylabel(r'$m - p}$')
337+
ax[1,0].set_ylabel(r'$m$')
338+
ax[1,0].set_xlabel(r'$t$')
339+
ax[1,1].set_ylabel(r'$p$')
340+
ax[1,1].set_xlabel(r'$t$')
341+
342+
ax[0,1].legend()
343+
ax[1,2].set_axis_off()
344+
plt.tight_layout()
345+
plt.show()
346+
347+
return π_seq, Eπ_seq, m_seq, p_seq
348+
```
349+
350+
### Experiment 1
351+
352+
Jiacheng:
353+
$$
354+
\begin{align*}
355+
\pi_{t}&=\mu_{t}+\alpha\pi_{t+1}^{*}-\alpha\pi_{t}^{*}\\\pi_{t+1}^{*}&=\lambda\pi_{t}^{*}+(1-\lambda)\pi_{t}\\\left[1-\alpha(1-\lambda)\right]\pi_{t}&=\mu_{t}+\left(\alpha\lambda-\alpha\right)\pi_{t}^{*}\\\pi_{t}&=\frac{\mu_{t}}{1-\alpha(1-\lambda)}-\frac{\alpha\left(1-\lambda\right)}{1-\alpha(1-\lambda)}\pi_{t}^{*}
356+
\end{align*}
357+
$$
358+
359+
If $1-\alpha(1-\lambda)<0$, expectation would explode.
360+
361+
```python
362+
# parameters
363+
T = 80
364+
T1 = 60
365+
α = 4
366+
λ = 0.9
367+
m0 = 1
368+
369+
μ0 = 0.2
370+
μ_star = 0
371+
```
372+
373+
```python
374+
print(1 - α*(1-λ))
375+
```
376+
377+
```python
378+
μ_seq_1 = np.append(μ0*np.ones(T1), μ_star*np.ones(T+1-T1))
379+
380+
# solve and plot
381+
π_seq_1, Eπ_seq_1, m_seq_1, p_seq_1 = solve_and_plot(α=α, m0=m0, Eπ0=μ0, μ_seq=μ_seq_1, T=T, λ=λ)
382+
```
383+
384+
### Experiment 2
385+
386+
```python
387+
# parameters
388+
ϕ = 0.9
389+
μ_seq_2 = np.array([ϕ**t * μ0 + (1-ϕ**t)*μ_star for t in range(T)])
390+
μ_seq_2 = np.append(μ_seq_2, μ_star)
391+
392+
393+
# solve and plot
394+
π_seq_2, Eπ_seq_2, m_seq_2, p_seq_2 = solve_and_plot(α=α, m0=m0, Eπ0=μ0, μ_seq=μ_seq_2, T=T, λ=λ)
395+
```

0 commit comments

Comments
 (0)