Skip to content

Commit a87d92d

Browse files
committed
misc
1 parent 98ffdf0 commit a87d92d

File tree

1 file changed

+57
-38
lines changed

1 file changed

+57
-38
lines changed

lectures/cobweb.md

Lines changed: 57 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ jupytext:
33
text_representation:
44
extension: .md
55
format_name: myst
6+
format_version: 0.13
7+
jupytext_version: 1.14.1
68
kernelspec:
79
display_name: Python 3 (ipykernel)
810
language: python
@@ -13,9 +15,11 @@ kernelspec:
1315
# The Cobweb Model
1416

1517

16-
The cobweb model {cite}`cobweb_model` is a model of prices and quantities in a given market, and how they evolve over time.
18+
The cobweb model is a model of prices and quantities in a given market, and how they evolve over time.
1719

18-
The model dates back to the 1930s and, while simple, it remains significant
20+
## Overview
21+
22+
The cobweb model dates back to the 1930s and, while simple, it remains significant
1923
because it shows the fundamental importance of *expectations*.
2024

2125
To give some idea of how the model operates, and why expectations matter, imagine the following scenario.
@@ -44,49 +48,54 @@ supply and causing the price to climb again.
4448
You can imagine how these dynamics could cause cycles in prices and quantities
4549
that persist over time.
4650

47-
This motivation is also taken from one of the earliest papers that uses
48-
cobweb theorem to explain the prices of hog in the US. We will try to
49-
simulate and plot the graph that uses the rough data from the paper {cite}`hog_cycle`.
51+
The cobweb model puts these ideas into equations so we can try to quantify
52+
them, and to study conditions underw which cycles persist (or disappear).
5053

51-
We will use the following imports:
54+
In this lecture, we investigate and simulate the basic model under different
55+
assumptions regarding the way that produces form expectations.
56+
57+
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).
58+
59+
60+
+++
61+
62+
We will use the following imports.
5263

5364
```{code-cell} ipython3
5465
import numpy as np
5566
import matplotlib.pyplot as plt
5667
```
5768

58-
We will use the following data for simulation:
69+
## History
70+
71+
Early papers on the cobweb cycle include {cite}`cobweb_model` and {cite}`hog_cycle`.
72+
73+
The paper {cite}`hog_cycle` uses the cobweb theorem to explain the prices of hog in the US over 1920--1950
74+
75+
The next plot replicates part of Figure 2 from that paper, which plots the price of hogs at yearly frequency.
76+
77+
Notice the cyclical price dynamics, which match the kind of cyclical soybean price dynamics discussed above.
5978

6079
```{code-cell} ipython3
61-
:tags: [hide-input]
6280
hog_prices = [55, 57, 80, 70, 60, 65, 72, 65, 51, 49, 45, 80, 85,
6381
78, 80, 68, 52, 65, 83, 78, 60, 62, 80, 87, 81, 70,
6482
69, 65, 62, 85, 87, 65, 63, 75, 80, 62]
6583
years = np.arange(1924, 1960)
66-
```
67-
68-
Let's plot the above data and observe the graph.
69-
70-
```{code-cell} ipython3
71-
fig, ax = plt.subplots(figsize=(9, 4))
72-
ax.plot(years, hog_prices, '-o', ms=4)
84+
fig, ax = plt.subplots()
85+
ax.plot(years, hog_prices, '-o', ms=4, label='hog price')
7386
ax.set_xlabel('year')
74-
ax.set_ylabel('prices')
87+
ax.set_ylabel('dollars')
88+
ax.legend()
89+
ax.grid()
7590
plt.show()
7691
```
7792

78-
The cobweb model puts these ideas into equations so we can try to quantify
79-
them, and to study conditions underw which cycles persist (or disappear).
80-
81-
In this lecture, we investigate and simulate the basic model under different
82-
assumptions regarding the way that produces form expectations.
83-
84-
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).
85-
8693

8794

8895
## The Model
8996

97+
Let's return to our discussion of a hypothetical soy bean market, where price is determined by supply and demand.
98+
9099
We suppose that demand for soy beans is given by
91100

92101
$$
@@ -97,7 +106,7 @@ where $a, b$ are nonnegative constants and $p_t$ is the spot (i.e, current marke
97106

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

100-
Supply of soy beans depends on *expected* prices at time $t$, which we denote $p^e_t$.
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$.
101110

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

@@ -236,6 +245,7 @@ The function `plot45` defined below helps us draw the 45 degree diagram.
236245

237246
```{code-cell} ipython3
238247
:tags: [hide-input]
248+
239249
def plot45(model, pmin, pmax, p0, num_arrows=5):
240250
"""
241251
Function to plot a 45 degree plot
@@ -378,7 +388,7 @@ The cycle is "stable", in the sense that prices converge to it from most startin
378388

379389
For example,
380390

381-
```{code-cell} ipython3 tags=[]
391+
```{code-cell} ipython3
382392
ts_plot_price(m, 10, ts_length=15)
383393
```
384394

@@ -456,7 +466,6 @@ Let's call the function with prices starting at $p_0 = 5$.
456466

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

459-
460469
```{code-cell} ipython3
461470
ts_price_plot_adaptive(m, 5, ts_length=30)
462471
```
@@ -476,7 +485,7 @@ TODO check / fix exercises
476485
```{exercise-start}
477486
:label: cobweb_ex1
478487
```
479-
Using the default Market model and naive expectations, plot a time series simulation of supply (rather than the price).
488+
Using the default `Market` class and naive expectations, plot a time series simulation of supply (rather than the price).
480489

481490
Show, in particular, that supply also cycles.
482491

@@ -508,10 +517,12 @@ def ts_plot_supply(model, p0, ts_length=10):
508517
'bo-',
509518
alpha=0.6,
510519
lw=2,
511-
label=r'$S_t$')
520+
label=r'supply')
512521
513522
ax.legend(loc='best', fontsize=10)
514523
ax.set_xticks(np.arange(ts_length))
524+
ax.set_xlabel("time")
525+
ax.set_ylabel("quantity")
515526
plt.show()
516527
```
517528

@@ -564,30 +575,38 @@ def ts_plot_price_blae(model, p0, p1, alphas, ts_length=15):
564575
Function to simulate and plot the time series of price
565576
using backward looking average expectations.
566577
"""
567-
fig, ax = plt.subplots()
568-
ax.set_xlabel(r'$t$', fontsize=12)
569-
ax.set_ylabel(r'$p_t$', fontsize=12)
570-
for a in alphas:
578+
fig, axes = plt.subplots(len(alphas), 1, figsize=(8, 16))
579+
580+
for ax, a in zip(axes.flatten(), alphas):
571581
p = np.empty(ts_length)
572-
p[0] = p[0]
573-
p[1] = p[1]
582+
p[0] = p0
583+
p[1] = p1
574584
for t in range(2, ts_length):
575585
pe = a*p[t-1] + (1 - a)*p[t-2]
576586
p[t] = -(model.supply(pe) - model.a) / model.b
577587
ax.plot(np.arange(ts_length),
578588
p,
579589
'o-',
580590
alpha=0.6,
581-
label=r'$\alpha={}$'.format(a),
582-
c=np.random.rand(3))
591+
label=r'$\alpha={}$'.format(a))
583592
ax.legend(loc='best', fontsize=10)
593+
ax.set_xlabel(r'$t$', fontsize=12)
594+
ax.set_ylabel(r'$p_t$', fontsize=12)
584595
plt.show()
585596
```
586597

587598
```{code-cell} ipython3
588599
m = Market()
589-
ts_plot_price_blae(m, 1, 2.5, [0.1, 0.3, 0.5, 0.8], 20)
600+
ts_plot_price_blae(m,
601+
p0=5,
602+
p1=6,
603+
alphas=[0.1, 0.3, 0.5, 0.8],
604+
ts_length=20)
590605
```
591606

592607
```{solution-end}
593608
```
609+
610+
```{code-cell} ipython3
611+
612+
```

0 commit comments

Comments
 (0)