Skip to content

Commit 91f2520

Browse files
jstacSmit-create
authored andcommitted
misc
1 parent d935b47 commit 91f2520

File tree

1 file changed

+124
-116
lines changed

1 file changed

+124
-116
lines changed

lectures/olg.md

Lines changed: 124 additions & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -151,17 +151,15 @@ Thus first-order condition for a maximum can be obtained
151151
by plugging $c^2_{t+1}$ into the objective function, taking the derivative
152152
with respect to $c^1_t$, and setting it to zero.
153153

154-
This leads to
154+
This leads to the **Euler equation** of the OLG model, which is
155155

156156
```{math}
157157
:label: euler_1_olg
158158
u'(c^1_t) = \beta R_{t+1} u'( R_{t+1} (w_t - c^1_t))
159159
```
160160

161-
This restriction is called the **Euler equation**
162-
163-
From the first constraint we get $c^1_{t} = w_t - s_t$,
164-
so the Euler equation can also be expressed as
161+
From the first constraint we get $c^1_{t} = w_t - s_t$, so the Euler equation
162+
can also be expressed as
165163

166164
```{math}
167165
:label: euler_2_olg
@@ -189,11 +187,7 @@ Thus, [](saving_1_olg) states the quantity of savings given prices.
189187
### Example: log preferences
190188

191189
In the special case $u(c) = \log c$, the Euler equation simplifies to
192-
193-
```{math}
194-
:label: saving_log_1_olg
195-
s_t= \beta (w_t - s_t)
196-
```
190+
$s_t= \beta (w_t - s_t)$.
197191

198192
Solving for saving, we get
199193

@@ -262,7 +256,6 @@ and
262256
```
263257

264258

265-
266259
### Demand
267260

268261
Using our assumption $\ell_1 = 1$ allows us to write
@@ -285,9 +278,15 @@ Rearranging [](interest_rate_2) gives the aggregate demand for capital
285278
```{math}
286279
:label: aggregate_demand_capital_olg
287280
k^d (R_{t+1})
288-
:= \left (\frac{R_{t+1}}{\alpha} \right )^{1/(\alpha - 1)}
281+
:= \left (\frac{\alpha}{R_{t+1}} \right )^{1/(1-\alpha)}
289282
```
290283

284+
In Python code this is
285+
286+
```{code-cell} ipython3
287+
def capital_demand(R, α):
288+
return (α/R)**(1/(1-α))
289+
```
291290

292291

293292
## Equilibrium
@@ -340,156 +339,87 @@ Solving for the equilibrium interest rate gives
340339
\right )^{\alpha - 1}
341340
```
342341

342+
In Python we can compute this via
343+
344+
```{code-cell} ipython3
345+
def equilibrium_R_log_utility(α, β, k_prev):
346+
R = α * ( β * (1-α) * k_prev**α / (1+β))**(α-1)
347+
return R
348+
```
349+
343350
Plugging into either the demand or the supply function gives the equilibrium quantity
344351

345352
```{math}
346353
:label: equilibrium_quantity
347354
k_{t+1} = \frac{\beta }{1+\beta} (1-\alpha)k_t^{\alpha}
348355
```
349356

350-
```{code-cell} ipython3
351-
Model = namedtuple('Model', ['α', # output elasticity of capital in the Cobb-Douglas production function
352-
'β', # discount factor
353-
'u', # parameter which defines the flow utility
354-
'L', # population size
355-
'u_params'] # other params used to define u
356-
)
357-
```
357+
In Python this is
358358

359-
```{code-cell} ipython3
360-
def u(c):
361-
return np.log(c)
362-
```
363359

364360
```{code-cell} ipython3
365-
def create_olg_model(α=0.3, β=0.9, u=u, L=10.0, u_params=dict()):
366-
return Model(α=α, β=β, u=u, L=L, u_params=u_params)
361+
def capital_supply_log_utility(R, α, β, k_prev):
362+
return (β / (1+β)) * (1-α) * k_prev**α
367363
```
368364

369-
```{code-cell} ipython3
370-
def equilibrium(model, K_prev):
371-
α, β, L = model.α, model.β, model.L
372-
R = α * ( β * (1-α) * (K_prev / L)**α / (1+β))**(α-1)
373-
K = β / (1+β) * (1-α) * (K_prev / L)**α * L
374-
return R, K
375-
```
376365

377-
```{code-cell} ipython3
378-
def aggregate_capital_demand(R, model, K_prev):
379-
α, L = model.α, model.L
380-
return (R/α)**(1/(α-1)) * L
381-
```
382366

383-
```{code-cell} ipython3
384-
def aggregate_capital_supply(R, model, K_prev):
385-
α, β, L = model.α, model.β, model.L
386-
λ = np.ones_like(R)
387-
return λ * β / (1+β) * (1-α) * (K_prev / L)**α * L
388-
```
367+
Here is a plot of the demand and supply curves for capital, along with the
368+
equilibrium values.
369+
389370

390371
```{code-cell} ipython3
391-
def plot_ad_as(demand, supply, m, K_prev, E_star=None):
372+
def plot_ad_as(α, β, k_prev):
392373
393374
R_vals = np.linspace(0.3, 1)
394375
395376
fig, ax = plt.subplots()
396377
397-
ax.plot(R_vals, demand(R_vals, m, K_prev), label="aggregate demand")
398-
ax.plot(R_vals, supply(R_vals, m, K_prev), label="aggregate supply")
378+
ax.plot(R_vals, capital_demand(R_vals, α),
379+
label="aggregate demand")
380+
ax.plot(R_vals, capital_supply_log_utility(R_vals, α, β, k_prev),
381+
label="aggregate supply")
399382
400-
if E_star:
401-
R_star, K_star = E_star
383+
R_e = equilibrium_R_log_utility
384+
k_e = capital_supply_log_utility(R_e, α, β, k_prev)
402385
403-
ax.plot(R_star, K_star, 'go', ms=10, alpha=0.6)
386+
ax.plot(R_e, k_e, 'go', ms=10, alpha=0.6)
404387
405-
ax.annotate(r'Equilibrium',
406-
xy=(R_star, K_star),
407-
xycoords='data',
408-
xytext=(0, -60),
409-
textcoords='offset points',
410-
fontsize=14,
411-
arrowprops=dict(arrowstyle="->"))
388+
ax.annotate(r'Equilibrium',
389+
xy=(R_e, k_e),
390+
xycoords='data',
391+
xytext=(0, -60),
392+
textcoords='offset points',
393+
fontsize=14,
394+
arrowprops=dict(arrowstyle="->"))
412395
413396
ax.set_xlabel("$R_{t+1}$")
414-
ax.set_ylabel("$K_{t+1}$")
397+
ax.set_ylabel("$k_{t+1}$")
415398
ax.legend()
416399
plt.show()
417400
```
418401

419-
```{code-cell} ipython3
420-
m = create_olg_model()
421-
K_prev = 50
422-
```
423402

424-
```{code-cell} ipython3
425-
E_star = equilibrium(m, K_prev)
426-
```
427-
428-
```{code-cell} ipython3
429-
R_star, K_star = E_star
430-
```
431403

432-
```{code-cell} ipython3
433-
plot_ad_as(aggregate_capital_demand, aggregate_capital_supply, m, K_prev=50, E_star=E_star)
434-
```
435404

436-
Let's observe the dynamics of the equilibrium price $R^*_{t+1}$.
437-
438-
```{code-cell} ipython3
439-
K_t_vals = np.linspace(10, 500, 10_000)
440-
R_t1_vals = m.α * (m.β * (1-m.α) * (K_t_vals / m.L)**m.α / (1+m.β))**(m.α-1)
441-
```
442-
443-
```{code-cell} ipython3
444-
fig, ax = plt.subplots()
445-
ax.plot(K_t_vals, R_t1_vals)
446-
ax.set_ylabel("$R^*_{t+1}$")
447-
ax.set_xlabel("$K_{t}$")
448-
plt.show()
449-
```
450405

451406
## Dynamics and steady state
452407

453-
Let $k_t := K_t / L$.
408+
The discussion above shows how equilibrium $k_{t+1}$ is obtained given $k_t$.
454409

410+
If we keep repeating this process we get a sequence for capital stock.
455411

456-
Aggregate supply of capital becomes
457-
```{math}
458-
:label: supply_capital_log_olg
459-
k_{t+1} = k^s(R_{t+1}) = \frac{\beta}{1+\beta} w_t
460-
```
461412

462-
[](wage) becomes
463-
```{math}
464-
:label: wage_2
465-
(1-\alpha)(k_t)^{\alpha} = w_t
466-
```
413+
### Dynamics with log utility
467414

415+
In the case of log utility, we saw that these dynamics are given by
468416

469-
470-
Combining [](supply_capital_log_olg) and [](wage_2) yields the law of motion for capital
471417
```{math}
472418
:label: law_of_motion_capital
473419
k_{t+1} = \frac{\beta}{1+\beta} (1-\alpha)(k_t)^{\alpha}
474420
```
475421

476-
477-
478-
A steady state can be solved analytically in this case.
479-
480-
That is, $k_{t+1} = k_t = k^*$, where
481-
```{math}
482-
:label: steady_state_1
483-
k^* = \frac{\beta (1-\alpha) (k^*)^{\alpha}}{(1+\beta)}
484-
```
485-
486-
487-
488-
We can solve this equation to obtain
489-
```{math}
490-
:label: steady_state_2
491-
k^* = \left (\frac{\beta (1-\alpha)}{1+\beta} \right )^{1/(1-\alpha)}
492-
```
422+
Let's plot the 45 degree diagram.
493423

494424
```{code-cell} ipython3
495425
def k_update(k, model):
@@ -538,6 +468,81 @@ def plot_45(m, k_update, kstar=None):
538468
plot_45(m, k_update, kstar=None)
539469
```
540470

471+
Let's plot some time series
472+
473+
observe the dynamics of the equilibrium price $R^*_{t+1}$.
474+
475+
```{code-cell} ipython3
476+
K_t_vals = np.linspace(10, 500, 10_000)
477+
R_t1_vals = m.α * (m.β * (1-m.α) * (K_t_vals / m.L)**m.α / (1+m.β))**(m.α-1)
478+
```
479+
480+
```{code-cell} ipython3
481+
fig, ax = plt.subplots()
482+
ax.plot(K_t_vals, R_t1_vals)
483+
ax.set_ylabel("$R^*_{t+1}$")
484+
ax.set_xlabel("$K_{t}$")
485+
plt.show()
486+
```
487+
488+
489+
### Steady state (log case)
490+
491+
The diagram shows that the model has a unique positive steady state, which we
492+
denote by $k^*$.
493+
494+
We can solve for $k^*$ by setting $k_{t+1} = k_t = k^*$ in [](law_of_motion_capital), which yields
495+
496+
```{math}
497+
:label: steady_state_1
498+
k^* = \frac{\beta (1-\alpha) (k^*)^{\alpha}}{(1+\beta)}
499+
```
500+
501+
502+
503+
504+
505+
506+
507+
508+
```{code-cell} ipython3
509+
Model = namedtuple('Model', ['α', # Cobb-Douglas parameter
510+
'β', # discount factor
511+
'u'] # flow utility
512+
)
513+
```
514+
```{code-cell} ipython3
515+
def create_olg_model(α=0.3, β=0.9, u=u, L=10.0, u_params=dict()):
516+
return Model(α=α, β=β, u=u, L=L, u_params=u_params)
517+
```
518+
519+
520+
```{code-cell} ipython3
521+
m = create_olg_model()
522+
K_prev = 50
523+
```
524+
525+
```{code-cell} ipython3
526+
E_star = equilibrium(m, K_prev)
527+
```
528+
529+
```{code-cell} ipython3
530+
R_star, K_star = E_star
531+
```
532+
533+
```{code-cell} ipython3
534+
plot_ad_as(aggregate_capital_demand, aggregate_capital_supply, m, K_prev=50, E_star=E_star)
535+
```
536+
537+
538+
539+
We can solve this equation to obtain
540+
```{math}
541+
:label: steady_state_2
542+
k^* = \left (\frac{\beta (1-\alpha)}{1+\beta} \right )^{1/(1-\alpha)}
543+
```
544+
545+
541546
```{code-cell} ipython3
542547
def k_star(model):
543548
α, β = model.α, model.β
@@ -549,6 +554,9 @@ plot_45(m, k_update, kstar=k_star(m))
549554
```
550555

551556

557+
558+
559+
552560
## CRRA preferences
553561

554562

0 commit comments

Comments
 (0)