Skip to content

Commit ef2b15d

Browse files
committed
[olg] use function
1 parent 8b68b04 commit ef2b15d

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

lectures/olg.md

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ jupytext:
44
extension: .md
55
format_name: myst
66
format_version: 0.13
7-
jupytext_version: 1.14.5
7+
jupytext_version: 1.15.2
88
kernelspec:
99
display_name: Python 3 (ipykernel)
1010
language: python
@@ -294,12 +294,17 @@ def capital_demand(R, α):
294294
return (α/R)**(1/(1-α))
295295
```
296296

297+
```{code-cell} ipython3
298+
def capital_supply(R, β, w):
299+
R = np.ones_like(R)
300+
return R * (β / (1 + β)) * w
301+
```
302+
297303
The next figure plots the supply of capital, as in [](saving_log_2_olg), as well as the demand for capital, as in [](aggregate_demand_capital_olg), as functions of the interest rate $R_{t+1}$.
298304

299305
(For the special case of log utility, supply does not depend on the interest rate, so we have a constant function.)
300306

301307
```{code-cell} ipython3
302-
303308
R_vals = np.linspace(0.3, 1)
304309
α, β = 0.5, 0.9
305310
w = 2.0
@@ -308,7 +313,7 @@ fig, ax = plt.subplots()
308313
309314
ax.plot(R_vals, capital_demand(R_vals, α),
310315
label="aggregate demand")
311-
ax.plot(R_vals, np.ones_like(R_vals) * (β / (1 + β)) * w,
316+
ax.plot(R_vals, capital_supply(R_vals, β, w),
312317
label="aggregate supply")
313318
314319
ax.set_xlabel("$R_{t+1}$")
@@ -391,7 +396,6 @@ That is,
391396
Let's redo our plot above but now inserting the equilibrium quantity and price.
392397

393398
```{code-cell} ipython3
394-
395399
R_vals = np.linspace(0.3, 1)
396400
α, β = 0.5, 0.9
397401
w = 2.0
@@ -400,7 +404,7 @@ fig, ax = plt.subplots()
400404
401405
ax.plot(R_vals, capital_demand(R_vals, α),
402406
label="aggregate demand")
403-
ax.plot(R_vals, np.ones_like(R_vals) * (β / (1 + β)) * w,
407+
ax.plot(R_vals, capital_supply(R_vals, β, w),
404408
label="aggregate supply")
405409
406410
R_e = equilibrium_R_log_utility(α, β, w)
@@ -452,7 +456,6 @@ $$
452456
g(k) := \frac{\beta}{1+\beta} (1-\alpha)(k)^{\alpha}
453457
$$
454458

455-
456459
```{code-cell} ipython3
457460
def k_update(k, α, β):
458461
return β * (1 - α) * k**α / (1 + β)
@@ -627,7 +630,6 @@ def savings_crra(w, R, model):
627630
```
628631

629632
```{code-cell} ipython3
630-
631633
R_vals = np.linspace(0.3, 1)
632634
model = create_olg_model()
633635
w = 2.0
@@ -760,7 +762,6 @@ ax.set_ylabel('$k_{t+1}$', fontsize=12)
760762
plt.show()
761763
```
762764

763-
764765
```{solution-end}
765766
```
766767

@@ -821,7 +822,6 @@ k_star = optimize.newton(h, 0.2, args=(model,))
821822
print(f"k_star = {k_star}")
822823
```
823824

824-
825825
```{solution-end}
826826
```
827827

@@ -846,7 +846,6 @@ Use initial conditions for $k_0$ of $0.001, 1.2, 2.6$ and time series length 10.
846846

847847
Let's define the constants and three distinct intital conditions
848848

849-
850849
```{code-cell} ipython3
851850
ts_length = 10
852851
k0 = np.array([0.001, 1.2, 2.6])

0 commit comments

Comments
 (0)