@@ -13,7 +13,7 @@ For this lecture we need the `yfinance` library.
13
13
14
14
``` {code-cell} ipython3
15
15
:tags: [hide-output]
16
- !pip install yfinance
16
+ !pip install yfinance
17
17
```
18
18
19
19
@@ -55,10 +55,10 @@ In general, prices depend on the choices and actions of suppliers, consumers and
55
55
speculators.
56
56
57
57
Our focus will be on the interaction between these parties, viewed through the
58
- lens of the standard competitive storage model
58
+ lens of the standard competitive storage model
59
59
60
60
This model was developed by
61
- {cite}` samuelson1971stochastic ` ,
61
+ {cite}` samuelson1971stochastic ` ,
62
62
{cite}` wright1982economic ` , {cite}` scheinkman1983simple ` ,
63
63
{cite}` deaton1992on ` , {cite}` deaton1996competitive ` , and
64
64
{cite}` chambers1996theory ` .
@@ -81,7 +81,7 @@ Supply is exogenous, depending on "harvests".
81
81
These days, goods such as basic computer chips and integrated circuits are
82
82
often treated as commodities in financial markets, being highly standardized,
83
83
and, for these kinds of commodities, the word "harvest" is not
84
- appropriate.
84
+ appropriate.
85
85
86
86
Nonetheless, we maintain it for simplicity.
87
87
```
@@ -97,7 +97,6 @@ We begin with the following imports
97
97
``` {code-cell} ipython3
98
98
import numpy as np
99
99
import matplotlib.pyplot as plt
100
- from numba import jit, vectorize
101
100
from scipy.interpolate import interp1d
102
101
from scipy.optimize import minimize_scalar, brentq
103
102
from scipy.stats import beta
@@ -107,25 +106,25 @@ from scipy.stats import beta
107
106
## The Model
108
107
109
108
Consider a market for a single commodity, whose price is given at $t$ by
110
- $p_t$.
109
+ $p_t$.
111
110
112
111
The harvest of the commodity at time $t$ is $Z_t$.
113
112
114
113
We assume that the sequence $\{ Z_t \} _ {t \geq 1}$ is IID with common
115
- density function $\phi$.
114
+ density function $\phi$.
116
115
117
116
The harvests take values in $S$, a subset of the nonnegative numbers.
118
117
119
118
Speculators can store the commodity between periods, with $I_t$ units
120
119
purchased in the current period yielding $\alpha I_t$ units in the next.
121
120
122
- Here $\alpha \in (0,1)$ is a depreciation rate for the commodity.
121
+ Here $\alpha \in (0,1)$ is a depreciation rate for the commodity.
123
122
124
123
For simplicity, the risk free interest rate is taken to be
125
- zero, so expected profit on purchasing $I_t$ units is
124
+ zero, so expected profit on purchasing $I_t$ units is
126
125
127
126
$$
128
- \mathbb{E}_t \, p_{t+1} \cdot \alpha I_t - p_t I_t
127
+ \mathbb{E}_t \, p_{t+1} \cdot \alpha I_t - p_t I_t
129
128
= (\alpha \mathbb{E}_t \, p_{t+1} - p_t) I_t
130
129
$$
131
130
162
161
$$ (eq:pmco)
163
162
164
163
165
- We also require that the market clears in each period.
164
+ We also require that the market clears in each period.
166
165
167
166
We assume that consumers generate demand quantity $D(p)$ corresponding to
168
167
price $p$.
@@ -173,14 +172,14 @@ Let $P := D^{-1}$ be the inverse demand function.
173
172
Regarding quantities,
174
173
175
174
* supply is the sum of carryover by speculators and the current harvest
176
- * demand is the sum of purchases by consumers and purchases by speculators.
175
+ * demand is the sum of purchases by consumers and purchases by speculators.
177
176
178
177
Mathematically,
179
178
180
- * supply $ = X_t = \alpha I_{t-1} + Z_t$
181
- * demand $ = D(p_t) + I_t$
179
+ * supply $ = X_t = \alpha I_{t-1} + Z_t$
180
+ * demand $ = D(p_t) + I_t$
182
181
183
- Thus, the market equilibrium condition is
182
+ Thus, the market equilibrium condition is
184
183
185
184
$$
186
185
\alpha I_ {t-1} + Z_t = D(p_t) + I_t
@@ -194,14 +193,14 @@ The initial condition $X_0 \in S$ is treated as given.
194
193
195
194
### An equilibrium function
196
195
197
- Now to find an equilibrium?
196
+ Now to find an equilibrium?
198
197
199
198
Our path of attack will be to seek a system of prices that depend only on the
200
199
current state.
201
200
202
- In other words, we take a function $p$ on $S$ and set $p_t = p(X_t)$ for every $t$.
201
+ In other words, we take a function $p$ on $S$ and set $p_t = p(X_t)$ for every $t$.
203
202
204
- Prices and quantities then follow
203
+ Prices and quantities then follow
205
204
206
205
$$
207
206
p_t = p(X_t), \quad I_t = X_t - D(p_t), \quad X_ {t+1} = \alpha I_t + Z_ {t+1}
@@ -218,7 +217,7 @@ To this end, suppose that there exists a function $p^*$ on $S$
218
217
satisfying
219
218
220
219
$$
221
- p^* (x) = \max
220
+ p^* (x) = \max
222
221
\left\{
223
222
\alpha \int_0^\infty p^* (\alpha I(x) + z) \phi(z)dz, P(x)
224
223
\right\}
233
232
$$ (eq:einvf)
234
233
235
234
It turns out that such a $p^*$ will suffice, in the sense that [](eq:arbi)
236
- and [](eq:pmco) hold for the corresponding system [](eq:eosy).
235
+ and [](eq:pmco) hold for the corresponding system [](eq:eosy).
237
236
238
- To see this, observe first that
237
+ To see this, observe first that
239
238
240
239
$$
241
240
\mathbb{E}_ t \, p_ {t+1}
242
- = \mathbb{E}_ t \, p^* (X_ {t+1})
243
- = \mathbb{E}_ t \, p^* (\alpha I(X_t) + Z_ {t+1})
241
+ = \mathbb{E}_ t \, p^* (X_ {t+1})
242
+ = \mathbb{E}_ t \, p^* (\alpha I(X_t) + Z_ {t+1})
244
243
= \int_0^\infty p^* (\alpha I(X_t) + z) \phi(z)dz
245
244
$$
246
245
@@ -249,20 +248,20 @@ Thus [](eq:arbi) requires that
249
248
$$
250
249
\alpha \int_0^\infty p^* (\alpha I(X_t) + z) \phi(z)dz \leq p^* (X_t)
251
250
$$
252
-
253
- This inequality is immediate from [](eq:dopf).
254
251
255
- Second, regarding [](eq:pmco), suppose that
252
+ This inequality is immediate from [](eq:dopf).
253
+
254
+ Second, regarding [](eq:pmco), suppose that
256
255
257
256
$$
258
257
\alpha \int_0^\infty p^* (\alpha I(X_t) + z) \phi(z)dz < p^* (X_t)
259
258
$$
260
259
261
260
Then by [](eq:dopf) we have $p^*(X_t) = P(X_t)$
262
261
263
- But then $D(p^*(X_t)) = X_t$ and $I_t = I(X_t) = 0$.
262
+ But then $D(p^*(X_t)) = X_t$ and $I_t = I(X_t) = 0$.
264
263
265
- As a consequence, both [](eq:arbi) and [](eq:pmco) hold.
264
+ As a consequence, both [](eq:arbi) and [](eq:pmco) hold.
266
265
267
266
We have found an equilibrium.
268
267
@@ -293,16 +292,16 @@ To implement our update step, it is helpful if we put [](eq:dopf) and
293
292
This leads us to the update rule
294
293
295
294
$$
296
- p_ {k+1}(x) = \max
295
+ p_ {k+1}(x) = \max
297
296
\left\{
298
297
\alpha \int_0^\infty p_k(\alpha ( x - D(p_ {k+1}(x))) + z) \phi(z)dz, P(x)
299
298
\right\}
300
299
$$ (eq:dopf2)
301
300
302
- In other words, we take $p_k$ as given and, at each $x$, solve for $q$ in
301
+ In other words, we take $p_k$ as given and, at each $x$, solve for $q$ in
303
302
304
303
$$
305
- q = \max
304
+ q = \max
306
305
\left\{
307
306
\alpha \int_0^\infty p_k(\alpha ( x - D(q)) + z) \phi(z)dz, P(x)
308
307
\right\}
@@ -313,7 +312,7 @@ points $x_1, \ldots, x_n$.
313
312
314
313
Then we get the corresponding values $q_1, \ldots, q_n$.
315
314
316
- Then we compute $p_{k+1}$ as the linear interpolation of
315
+ Then we compute $p_{k+1}$ as the linear interpolation of
317
316
the values $q_1, \ldots, q_n$ over the grid $x_1, \ldots, x_n$.
318
317
319
318
Then we repeat, seeking convergence.
@@ -330,7 +329,7 @@ The integral in [](eq:dopf3) is computed via Monte Carlo.
330
329
331
330
332
331
```{code-cell} ipython3
333
- α, a, c = 0.8, 1.0, 2.0
332
+ α, a, c = 0.8, 1.0, 2.0
334
333
beta_a, beta_b = 5, 5
335
334
mc_draw_size = 250
336
335
gridsize = 150
@@ -339,7 +338,7 @@ grid = np.linspace(a, grid_max, gridsize)
339
338
340
339
beta_dist = beta(5, 5)
341
340
Z = a + beta_dist.rvs(mc_draw_size) * c # Shock observations
342
- D = P = lambda x: 1.0 / x
341
+ D = P = lambda x: 1.0 / x
343
342
tol = 1e-4
344
343
345
344
@@ -348,8 +347,8 @@ def T(p_array):
348
347
new_p = np.empty_like(p_array)
349
348
350
349
# Interpolate to obtain p as a function.
351
- p = interp1d(grid,
352
- p_array,
350
+ p = interp1d(grid,
351
+ p_array,
353
352
fill_value=(p_array[0], p_array[-1]),
354
353
bounds_error=False)
355
354
@@ -388,8 +387,8 @@ prices.
388
387
389
388
```{code-cell} ipython3
390
389
# Turn the price array into a price function
391
- p_star = interp1d(grid,
392
- price,
390
+ p_star = interp1d(grid,
391
+ price,
393
392
fill_value=(price[0], price[-1]),
394
393
bounds_error=False)
395
394
0 commit comments