Skip to content

Commit d9f5fb9

Browse files
authored
Merge pull request #435 from QuantEcon/update_cobweb
[cobweb] Update editorial suggestions
2 parents 04907d0 + 703b7b0 commit d9f5fb9

File tree

1 file changed

+32
-49
lines changed

1 file changed

+32
-49
lines changed

lectures/cobweb.md

Lines changed: 32 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ jupytext:
44
extension: .md
55
format_name: myst
66
format_version: 0.13
7-
jupytext_version: 1.14.1
7+
jupytext_version: 1.16.2
88
kernelspec:
99
display_name: Python 3 (ipykernel)
1010
language: python
@@ -14,7 +14,6 @@ kernelspec:
1414
(cobweb)=
1515
# The Cobweb Model
1616

17-
1817
The cobweb model is a model of prices and quantities in a given market, and how they evolve over time.
1918

2019
## Overview
@@ -24,7 +23,7 @@ because it shows the fundamental importance of *expectations*.
2423

2524
To give some idea of how the model operates, and why expectations matter, imagine the following scenario.
2625

27-
There is a market for soy beans, say, where prices and traded quantities
26+
There is a market for soybeans, say, where prices and traded quantities
2827
depend on the choices of buyers and sellers.
2928

3029
The buyers are represented by a demand curve --- they buy more at low prices
@@ -38,11 +37,11 @@ However, the sellers (who are farmers) need time to grow their crops.
3837
Suppose now that the price is currently high.
3938

4039
Seeing this high price, and perhaps expecting that the high price will remain
41-
for some time, the farmers plant many fields with soy beans.
40+
for some time, the farmers plant many fields with soybeans.
4241

4342
Next period the resulting high supply floods the market, causing the price to drop.
4443

45-
Seeing this low price, the farmers now shift out of soy beans, restricting
44+
Seeing this low price, the farmers now shift out of soybeans, restricting
4645
supply and causing the price to climb again.
4746

4847
You can imagine how these dynamics could cause cycles in prices and quantities
@@ -52,13 +51,10 @@ The cobweb model puts these ideas into equations so we can try to quantify
5251
them, and to study conditions under which cycles persist (or disappear).
5352

5453
In this lecture, we investigate and simulate the basic model under different
55-
assumptions regarding the way that produces form expectations.
54+
assumptions regarding the way that producers form expectations.
5655

5756
Our discussion and simulations draw on [high quality lectures](https://comp-econ.org/CEF_2013/downloads/Complex%20Econ%20Systems%20Lecture%20II.pdf) by [Cars Hommes](https://www.uva.nl/en/profile/h/o/c.h.hommes/c.h.hommes.html).
5857

59-
60-
+++
61-
6258
We will use the following imports.
6359

6460
```{code-cell} ipython3
@@ -70,7 +66,7 @@ import matplotlib.pyplot as plt
7066

7167
Early papers on the cobweb cycle include {cite}`cobweb_model` and {cite}`hog_cycle`.
7268

73-
The paper {cite}`hog_cycle` uses the cobweb theorem to explain the prices of hog in the US over 1920--1950
69+
The paper {cite}`hog_cycle` uses the cobweb theorem to explain the prices of hog in the US over 1920--1950.
7470

7571
The next plot replicates part of Figure 2 from that paper, which plots the price of hogs at yearly frequency.
7672

@@ -90,13 +86,11 @@ ax.grid()
9086
plt.show()
9187
```
9288

93-
94-
9589
## The model
9690

97-
Let's return to our discussion of a hypothetical soy bean market, where price is determined by supply and demand.
91+
Let's return to our discussion of a hypothetical soybean market, where price is determined by supply and demand.
9892

99-
We suppose that demand for soy beans is given by
93+
We suppose that demand for soybeans is given by
10094

10195
$$
10296
D(p_t) = a - b p_t
@@ -106,15 +100,15 @@ where $a, b$ are nonnegative constants and $p_t$ is the spot (i.e, current marke
106100

107101
($D(p_t)$ is the quantity demanded in some fixed unit, such as thousands of tons.)
108102

109-
Because the crop of soy beans for time $t$ is planted at $t-1$, supply of soy beans at time $t$ depends on *expected* prices at time $t$, which we denote $p^e_{t-1}$.
103+
Because the crop of soybeans for time $t$ is planted at $t-1$, supply of soybeans at time $t$ depends on *expected* prices at time $t$, which we denote $p^e_t$.
110104

111105
We suppose that supply is nonlinear in expected prices, and takes the form
112106

113107
$$
114-
S(p^e_{t-1}) = \tanh(\lambda(p^e_{t-1} - c)) + d
108+
S(p^e_t) = \tanh(\lambda(p^e_t - c)) + d
115109
$$
116110

117-
where $\lambda$ is a positive constant and $c, d \geq 0$.
111+
where $\lambda$ is a positive constant, $c, d$ are nonnegative constants and $\tanh$ is a type of [hyperbolic function](https://en.wikipedia.org/wiki/Hyperbolic_functions).
118112

119113
Let's make a plot of supply and demand for particular choices of the parameter values.
120114

@@ -149,7 +143,7 @@ m = Market()
149143
fig, ax = plt.subplots()
150144
151145
ax.plot(p_grid, m.demand(p_grid), label="$D$")
152-
ax.plot(p_grid, m.supply(p_grid), label="S")
146+
ax.plot(p_grid, m.supply(p_grid), label="$S$")
153147
ax.set_xlabel("price")
154148
ax.set_ylabel("quantity")
155149
ax.legend()
@@ -160,13 +154,13 @@ plt.show()
160154
Market equilibrium requires that supply equals demand, or
161155

162156
$$
163-
a - b p_t = S(p^e_{t-1})
157+
a - b p_t = S(p^e_t)
164158
$$
165159

166160
Rewriting in terms of $p_t$ gives
167161

168162
$$
169-
p_t = - \frac{1}{b} [S(p^e_{t-1}) - a]
163+
p_t = - \frac{1}{b} [S(p^e_t) - a]
170164
$$
171165

172166
Finally, to complete the model, we need to describe how price expectations are formed.
@@ -177,7 +171,7 @@ In particular, we suppose that
177171

178172
```{math}
179173
:label: p_et
180-
p^e_{t-1} = f(p_{t-1}, p_{t-2})
174+
p^e_t = f(p_{t-1}, p_{t-2})
181175
```
182176

183177
where $f$ is some function.
@@ -195,7 +189,6 @@ Combining the last two equations gives the dynamics for prices:
195189

196190
The price dynamics depend on the parameter values and also on the function $f$ that determines how producers form expectations.
197191

198-
199192
## Naive expectations
200193

201194
To go further in our analysis we need to specify the function $f$; that is, how expectations are formed.
@@ -204,7 +197,9 @@ Let's start with naive expectations, which refers to the case where producers ex
204197

205198
In other words,
206199

207-
$$ p_{t-1}^e = p_{t-1} $$
200+
$$
201+
p_t^e = p_{t-1}
202+
$$
208203

209204
Using {eq}`price_t`, we then have
210205

@@ -225,7 +220,6 @@ where $g$ is the function defined by
225220
g(p) = - \frac{1}{b} [ S(p) - a]
226221
```
227222

228-
229223
Here we represent the function $g$
230224

231225
```{code-cell} ipython3
@@ -239,9 +233,9 @@ def g(model, current_price):
239233
return next_price
240234
```
241235

242-
Let's try to understand how prices will evolve using a 45 degree diagram, which is a tool for studying one-dimensional dynamics.
236+
Let's try to understand how prices will evolve using a 45-degree diagram, which is a tool for studying one-dimensional dynamics.
243237

244-
The function `plot45` defined below helps us draw the 45 degree diagram.
238+
The function `plot45` defined below helps us draw the 45-degree diagram.
245239

246240
```{code-cell} ipython3
247241
:tags: [hide-input]
@@ -277,7 +271,7 @@ def plot45(model, pmin, pmax, p0, num_arrows=5):
277271
278272
ax.plot(pgrid, g(model, pgrid), 'b-',
279273
lw=2, alpha=0.6, label='g')
280-
ax.plot(pgrid, pgrid, lw=1, alpha=0.7, label='45')
274+
ax.plot(pgrid, pgrid, lw=1, alpha=0.7, label='$45\degree$')
281275
282276
x = p0
283277
xticks = [pmin]
@@ -316,7 +310,7 @@ def plot45(model, pmin, pmax, p0, num_arrows=5):
316310
plt.show()
317311
```
318312

319-
Now we can set up a market and plot the 45 degree diagram.
313+
Now we can set up a market and plot the 45-degree diagram.
320314

321315
```{code-cell} ipython3
322316
m = Market()
@@ -326,21 +320,21 @@ m = Market()
326320
plot45(m, 0, 9, 2, num_arrows=3)
327321
```
328322

329-
The plot shows the function $g$ defined in {eq}`def_g` and the $45$ degree line.
323+
The plot shows the function $g$ defined in {eq}`def_g` and the 45-degree line.
330324

331325
Think of $ p_t $ as a value on the horizontal axis.
332326

333327
Since $p_{t+1} = g(p_t)$, we use the graph of $g$ to see $p_{t+1}$ on the vertical axis.
334328

335329
Clearly,
336330

337-
- If $ g $ lies above the 45 degree line at $p_t$, then we have $ p_{t+1} > p_t $.
338-
- If $ g $ lies below the 45 degree line at $p_t$, then we have $ p_{t+1} < p_t $.
339-
- If $ g $ hits the 45 degree line at $p_t$, then we have $ p_{t+1} = p_t $, so $ p_t $ is a steady state.
331+
- If $ g $ lies above the 45-degree line at $p_t$, then we have $ p_{t+1} > p_t $.
332+
- If $ g $ lies below the 45-degree line at $p_t$, then we have $ p_{t+1} < p_t $.
333+
- If $ g $ hits the 45-degree line at $p_t$, then we have $ p_{t+1} = p_t $, so $ p_t $ is a steady state.
340334

341335
Consider the sequence of prices starting at $p_0$, as shown in the figure.
342336

343-
We find $p_1$ on the vertical axis and then shift it to the horizontal axis using the 45 degree line (where values on the two axes are equal).
337+
We find $p_1$ on the vertical axis and then shift it to the horizontal axis using the 45-degree line (where values on the two axes are equal).
344338

345339
Then from $p_1$ we obtain $p_2$ and continue.
346340

@@ -408,15 +402,15 @@ That is,
408402

409403
```{math}
410404
:label: pe_adaptive
411-
p_{t-1}^e = \alpha p_{t-1} + (1-\alpha) p^e_{t-2}
405+
p_t^e = \alpha p_{t-1} + (1-\alpha) p^e_{t-1}
412406
\qquad (0 \leq \alpha \leq 1)
413407
```
414408

415409
Another way to write this is
416410

417411
```{math}
418412
:label: pe_adaptive_2
419-
p_{t-1}^e = p^e_{t-2} + \alpha (p_{t-1} - p_{t-2}^e)
413+
p_t^e = p^e_{t-1} + \alpha (p_{t-1} - p_{t-1}^e)
420414
```
421415

422416
This equation helps to show that expectations shift
@@ -427,10 +421,9 @@ This equation helps to show that expectations shift
427421
Using {eq}`pe_adaptive`, we obtain the dynamics
428422

429423
$$
430-
p_t = - \frac{1}{b} [ S(\alpha p_{t-1} + (1-\alpha) p^e_{t-2}) - a]
424+
p_t = - \frac{1}{b} [ S(\alpha p_{t-1} + (1-\alpha) p^e_{t-1}) - a]
431425
$$
432426

433-
434427
Let's try to simulate the price and observe the dynamics using different values of $\alpha$.
435428

436429
```{code-cell} ipython3
@@ -464,8 +457,6 @@ def ts_price_plot_adaptive(model, p0, ts_length=10, α=[1.0, 0.9, 0.75]):
464457

465458
Let's call the function with prices starting at $p_0 = 5$.
466459

467-
TODO does this fit well in the page, even in the pdf? If not should it be stacked vertically?
468-
469460
```{code-cell} ipython3
470461
ts_price_plot_adaptive(m, 5, ts_length=30)
471462
```
@@ -477,9 +468,6 @@ expectations, which stabilizes expected prices.
477468

478469
This increased stability can be seen in the figures.
479470

480-
481-
TODO check / fix exercises
482-
483471
## Exercises
484472

485473
```{exercise-start}
@@ -547,7 +535,7 @@ That is,
547535

548536
```{math}
549537
:label: pe_blae
550-
p_{t-1}^e = \alpha p_{t-1} + (1-\alpha) p_{t-2}
538+
p_t^e = \alpha p_{t-1} + (1-\alpha) p_{t-2}
551539
```
552540

553541

@@ -605,9 +593,4 @@ ts_plot_price_blae(m,
605593
```
606594

607595
```{solution-end}
608-
```
609-
610-
```{code-cell} ipython3
611-
612-
```
613-
596+
```

0 commit comments

Comments
 (0)