Skip to content

Commit bb6b5d4

Browse files
committed
Remove unused import
1 parent 600eff4 commit bb6b5d4

File tree

1 file changed

+37
-38
lines changed

1 file changed

+37
-38
lines changed

lectures/commod_price.md

Lines changed: 37 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ For this lecture we need the `yfinance` library.
1313

1414
```{code-cell} ipython3
1515
:tags: [hide-output]
16-
!pip install yfinance
16+
!pip install yfinance
1717
```
1818

1919

@@ -55,10 +55,10 @@ In general, prices depend on the choices and actions of suppliers, consumers and
5555
speculators.
5656

5757
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
5959

6060
This model was developed by
61-
{cite}`samuelson1971stochastic`,
61+
{cite}`samuelson1971stochastic`,
6262
{cite}`wright1982economic`, {cite}`scheinkman1983simple`,
6363
{cite}`deaton1992on`, {cite}`deaton1996competitive`, and
6464
{cite}`chambers1996theory`.
@@ -81,7 +81,7 @@ Supply is exogenous, depending on "harvests".
8181
These days, goods such as basic computer chips and integrated circuits are
8282
often treated as commodities in financial markets, being highly standardized,
8383
and, for these kinds of commodities, the word "harvest" is not
84-
appropriate.
84+
appropriate.
8585
8686
Nonetheless, we maintain it for simplicity.
8787
```
@@ -97,7 +97,6 @@ We begin with the following imports
9797
```{code-cell} ipython3
9898
import numpy as np
9999
import matplotlib.pyplot as plt
100-
from numba import jit, vectorize
101100
from scipy.interpolate import interp1d
102101
from scipy.optimize import minimize_scalar, brentq
103102
from scipy.stats import beta
@@ -107,25 +106,25 @@ from scipy.stats import beta
107106
## The Model
108107

109108
Consider a market for a single commodity, whose price is given at $t$ by
110-
$p_t$.
109+
$p_t$.
111110

112111
The harvest of the commodity at time $t$ is $Z_t$.
113112

114113
We assume that the sequence $\{ Z_t \}_{t \geq 1}$ is IID with common
115-
density function $\phi$.
114+
density function $\phi$.
116115

117116
The harvests take values in $S$, a subset of the nonnegative numbers.
118117

119118
Speculators can store the commodity between periods, with $I_t$ units
120119
purchased in the current period yielding $\alpha I_t$ units in the next.
121120

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

124123
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
126125

127126
$$
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
129128
= (\alpha \mathbb{E}_t \, p_{t+1} - p_t) I_t
130129
$$
131130

@@ -162,7 +161,7 @@ $$
162161
$$ (eq:pmco)
163162
164163
165-
We also require that the market clears in each period.
164+
We also require that the market clears in each period.
166165
167166
We assume that consumers generate demand quantity $D(p)$ corresponding to
168167
price $p$.
@@ -173,14 +172,14 @@ Let $P := D^{-1}$ be the inverse demand function.
173172
Regarding quantities,
174173
175174
* 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.
177176
178177
Mathematically,
179178
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$
182181
183-
Thus, the market equilibrium condition is
182+
Thus, the market equilibrium condition is
184183
185184
$$
186185
\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.
194193
195194
### An equilibrium function
196195
197-
Now to find an equilibrium?
196+
Now to find an equilibrium?
198197
199198
Our path of attack will be to seek a system of prices that depend only on the
200199
current state.
201200
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$.
203202
204-
Prices and quantities then follow
203+
Prices and quantities then follow
205204
206205
$$
207206
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$
218217
satisfying
219218
220219
$$
221-
p^*(x) = \max
220+
p^*(x) = \max
222221
\left\{
223222
\alpha \int_0^\infty p^*(\alpha I(x) + z) \phi(z)dz, P(x)
224223
\right\}
@@ -233,14 +232,14 @@ $$
233232
$$ (eq:einvf)
234233
235234
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).
237236
238-
To see this, observe first that
237+
To see this, observe first that
239238
240239
$$
241240
\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})
244243
= \int_0^\infty p^*(\alpha I(X_t) + z) \phi(z)dz
245244
$$
246245
@@ -249,20 +248,20 @@ Thus [](eq:arbi) requires that
249248
$$
250249
\alpha \int_0^\infty p^*(\alpha I(X_t) + z) \phi(z)dz \leq p^*(X_t)
251250
$$
252-
253-
This inequality is immediate from [](eq:dopf).
254251
255-
Second, regarding [](eq:pmco), suppose that
252+
This inequality is immediate from [](eq:dopf).
253+
254+
Second, regarding [](eq:pmco), suppose that
256255
257256
$$
258257
\alpha \int_0^\infty p^*(\alpha I(X_t) + z) \phi(z)dz < p^*(X_t)
259258
$$
260259
261260
Then by [](eq:dopf) we have $p^*(X_t) = P(X_t)$
262261
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$.
264263
265-
As a consequence, both [](eq:arbi) and [](eq:pmco) hold.
264+
As a consequence, both [](eq:arbi) and [](eq:pmco) hold.
266265
267266
We have found an equilibrium.
268267
@@ -293,16 +292,16 @@ To implement our update step, it is helpful if we put [](eq:dopf) and
293292
This leads us to the update rule
294293
295294
$$
296-
p_{k+1}(x) = \max
295+
p_{k+1}(x) = \max
297296
\left\{
298297
\alpha \int_0^\infty p_k(\alpha ( x - D(p_{k+1}(x))) + z) \phi(z)dz, P(x)
299298
\right\}
300299
$$ (eq:dopf2)
301300
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
303302
304303
$$
305-
q = \max
304+
q = \max
306305
\left\{
307306
\alpha \int_0^\infty p_k(\alpha ( x - D(q)) + z) \phi(z)dz, P(x)
308307
\right\}
@@ -313,7 +312,7 @@ points $x_1, \ldots, x_n$.
313312
314313
Then we get the corresponding values $q_1, \ldots, q_n$.
315314
316-
Then we compute $p_{k+1}$ as the linear interpolation of
315+
Then we compute $p_{k+1}$ as the linear interpolation of
317316
the values $q_1, \ldots, q_n$ over the grid $x_1, \ldots, x_n$.
318317
319318
Then we repeat, seeking convergence.
@@ -330,7 +329,7 @@ The integral in [](eq:dopf3) is computed via Monte Carlo.
330329
331330
332331
```{code-cell} ipython3
333-
α, a, c = 0.8, 1.0, 2.0
332+
α, a, c = 0.8, 1.0, 2.0
334333
beta_a, beta_b = 5, 5
335334
mc_draw_size = 250
336335
gridsize = 150
@@ -339,7 +338,7 @@ grid = np.linspace(a, grid_max, gridsize)
339338
340339
beta_dist = beta(5, 5)
341340
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
343342
tol = 1e-4
344343
345344
@@ -348,8 +347,8 @@ def T(p_array):
348347
new_p = np.empty_like(p_array)
349348
350349
# Interpolate to obtain p as a function.
351-
p = interp1d(grid,
352-
p_array,
350+
p = interp1d(grid,
351+
p_array,
353352
fill_value=(p_array[0], p_array[-1]),
354353
bounds_error=False)
355354
@@ -388,8 +387,8 @@ prices.
388387
389388
```{code-cell} ipython3
390389
# Turn the price array into a price function
391-
p_star = interp1d(grid,
392-
price,
390+
p_star = interp1d(grid,
391+
price,
393392
fill_value=(price[0], price[-1]),
394393
bounds_error=False)
395394

0 commit comments

Comments
 (0)