Skip to content

Commit

Permalink
Merge pull request #435 from QuantEcon/update_cobweb
Browse files Browse the repository at this point in the history
[cobweb] Update editorial suggestions
  • Loading branch information
jstac authored Jul 1, 2024
2 parents 04907d0 + 703b7b0 commit d9f5fb9
Showing 1 changed file with 32 additions and 49 deletions.
81 changes: 32 additions & 49 deletions lectures/cobweb.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ jupytext:
extension: .md
format_name: myst
format_version: 0.13
jupytext_version: 1.14.1
jupytext_version: 1.16.2
kernelspec:
display_name: Python 3 (ipykernel)
language: python
Expand All @@ -14,7 +14,6 @@ kernelspec:
(cobweb)=
# The Cobweb Model


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

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

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

There is a market for soy beans, say, where prices and traded quantities
There is a market for soybeans, say, where prices and traded quantities
depend on the choices of buyers and sellers.

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

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

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

Seeing this low price, the farmers now shift out of soy beans, restricting
Seeing this low price, the farmers now shift out of soybeans, restricting
supply and causing the price to climb again.

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

In this lecture, we investigate and simulate the basic model under different
assumptions regarding the way that produces form expectations.
assumptions regarding the way that producers form expectations.

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).


+++

We will use the following imports.

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

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

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

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

Expand All @@ -90,13 +86,11 @@ ax.grid()
plt.show()
```



## The model

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

We suppose that demand for soy beans is given by
We suppose that demand for soybeans is given by

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

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

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}$.
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$.

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

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

where $\lambda$ is a positive constant and $c, d \geq 0$.
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).

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

Expand Down Expand Up @@ -149,7 +143,7 @@ m = Market()
fig, ax = plt.subplots()
ax.plot(p_grid, m.demand(p_grid), label="$D$")
ax.plot(p_grid, m.supply(p_grid), label="S")
ax.plot(p_grid, m.supply(p_grid), label="$S$")
ax.set_xlabel("price")
ax.set_ylabel("quantity")
ax.legend()
Expand All @@ -160,13 +154,13 @@ plt.show()
Market equilibrium requires that supply equals demand, or

$$
a - b p_t = S(p^e_{t-1})
a - b p_t = S(p^e_t)
$$

Rewriting in terms of $p_t$ gives

$$
p_t = - \frac{1}{b} [S(p^e_{t-1}) - a]
p_t = - \frac{1}{b} [S(p^e_t) - a]
$$

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

```{math}
:label: p_et
p^e_{t-1} = f(p_{t-1}, p_{t-2})
p^e_t = f(p_{t-1}, p_{t-2})
```

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

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


## Naive expectations

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

In other words,

$$ p_{t-1}^e = p_{t-1} $$
$$
p_t^e = p_{t-1}
$$

Using {eq}`price_t`, we then have

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


Here we represent the function $g$

```{code-cell} ipython3
Expand All @@ -239,9 +233,9 @@ def g(model, current_price):
return next_price
```

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

The function `plot45` defined below helps us draw the 45 degree diagram.
The function `plot45` defined below helps us draw the 45-degree diagram.

```{code-cell} ipython3
:tags: [hide-input]
Expand Down Expand Up @@ -277,7 +271,7 @@ def plot45(model, pmin, pmax, p0, num_arrows=5):
ax.plot(pgrid, g(model, pgrid), 'b-',
lw=2, alpha=0.6, label='g')
ax.plot(pgrid, pgrid, lw=1, alpha=0.7, label='45')
ax.plot(pgrid, pgrid, lw=1, alpha=0.7, label='$45\degree$')
x = p0
xticks = [pmin]
Expand Down Expand Up @@ -316,7 +310,7 @@ def plot45(model, pmin, pmax, p0, num_arrows=5):
plt.show()
```

Now we can set up a market and plot the 45 degree diagram.
Now we can set up a market and plot the 45-degree diagram.

```{code-cell} ipython3
m = Market()
Expand All @@ -326,21 +320,21 @@ m = Market()
plot45(m, 0, 9, 2, num_arrows=3)
```

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

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

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

Clearly,

- If $ g $ lies above the 45 degree line at $p_t$, then we have $ p_{t+1} > p_t $.
- If $ g $ lies below the 45 degree line at $p_t$, then we have $ p_{t+1} < p_t $.
- 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.
- If $ g $ lies above the 45-degree line at $p_t$, then we have $ p_{t+1} > p_t $.
- If $ g $ lies below the 45-degree line at $p_t$, then we have $ p_{t+1} < p_t $.
- 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.

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

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).
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).

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

Expand Down Expand Up @@ -408,15 +402,15 @@ That is,

```{math}
:label: pe_adaptive
p_{t-1}^e = \alpha p_{t-1} + (1-\alpha) p^e_{t-2}
p_t^e = \alpha p_{t-1} + (1-\alpha) p^e_{t-1}
\qquad (0 \leq \alpha \leq 1)
```

Another way to write this is

```{math}
:label: pe_adaptive_2
p_{t-1}^e = p^e_{t-2} + \alpha (p_{t-1} - p_{t-2}^e)
p_t^e = p^e_{t-1} + \alpha (p_{t-1} - p_{t-1}^e)
```

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

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


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

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

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

TODO does this fit well in the page, even in the pdf? If not should it be stacked vertically?

```{code-cell} ipython3
ts_price_plot_adaptive(m, 5, ts_length=30)
```
Expand All @@ -477,9 +468,6 @@ expectations, which stabilizes expected prices.

This increased stability can be seen in the figures.


TODO check / fix exercises

## Exercises

```{exercise-start}
Expand Down Expand Up @@ -547,7 +535,7 @@ That is,

```{math}
:label: pe_blae
p_{t-1}^e = \alpha p_{t-1} + (1-\alpha) p_{t-2}
p_t^e = \alpha p_{t-1} + (1-\alpha) p_{t-2}
```


Expand Down Expand Up @@ -605,9 +593,4 @@ ts_plot_price_blae(m,
```

```{solution-end}
```

```{code-cell} ipython3
```

```

0 comments on commit d9f5fb9

Please sign in to comment.