Skip to content

Commit f39311a

Browse files
committed
use brute force
1 parent fb44e24 commit f39311a

File tree

1 file changed

+27
-5
lines changed

1 file changed

+27
-5
lines changed

lectures/olg.md

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ kernelspec:
1212
---
1313

1414

15+
1516
# The Overlapping Generations Model
1617

1718
In this lecture we study the overlapping generations (OLG) model.
@@ -58,6 +59,7 @@ plt.rcParams["figure.figsize"] = (11, 5) #set default figure size
5859
```
5960

6061

62+
6163
## Environment
6264

6365
TODO add timing and basic ideas of OLG
@@ -360,6 +362,7 @@ plot_ad_as(aggregate_capital_demand, aggregate_capital_supply, m, K_prev=50, E_s
360362
```
361363

362364

365+
363366
Let's observe the dynamics of the equilibrium price $R^*_{t+1}$.
364367

365368
```{code-cell} ipython3
@@ -376,6 +379,7 @@ plt.show()
376379
```
377380

378381

382+
379383
## Dynamics and steady state
380384

381385
Let $k_t := K_t / L$.
@@ -477,6 +481,7 @@ plot_45(m, k_update, kstar=k_star(m))
477481
```
478482

479483

484+
480485
## Another special case: CRRA preference
481486

482487

@@ -493,6 +498,7 @@ m_crra = create_olg_model(u=crra, u_params={'γ': 0.5})
493498
```
494499

495500

501+
496502
### New aggregate supply
497503

498504

@@ -565,6 +571,7 @@ plot_ad_as(aggregate_capital_demand, aggregate_supply_capital_crra, m_crra, K_pr
565571
```
566572

567573

574+
568575
Let's plot the aggregate supply with different values of utility parameter $\gamma$ and observe it's behaviour.
569576

570577
```{code-cell} ipython3
@@ -587,6 +594,7 @@ plt.show()
587594
```
588595

589596

597+
590598
When $\gamma <1$ the supply curve is downward sloping. When $\gamma > 1$ the supply curve is upward sloping.
591599

592600
TODO: Do we need to add some explanation?
@@ -650,6 +658,7 @@ def f(k_prime, k, model):
650658
```
651659

652660

661+
653662
Let's define a function `k_next` that finds the value of $k_{t+1}$.
654663

655664
```{code-cell} ipython3
@@ -662,6 +671,7 @@ plot_45(m_crra, k_next, kstar=None)
662671
```
663672

664673

674+
665675
Unlike the log preference case now a steady state cannot be solved analytically.
666676

667677
To see this recall that, a steady state can be obtained by setting [](law_of_motion_capital_crra) to $k_{t+1} = k_t = k^*$, i.e.,
@@ -700,6 +710,7 @@ plot_45(m_crra, k_next, k_star)
700710
```
701711

702712

713+
703714
The next figure shows three time paths for capital, from
704715
three distinct initial conditions, under the parameterization listed above.
705716

@@ -742,6 +753,7 @@ simulate_ts(m_crra, x0, ts_length)
742753
```
743754

744755

756+
745757
## Exercises
746758

747759

@@ -784,6 +796,7 @@ def find_Kstar(R_star, model):
784796
```
785797

786798

799+
787800
The following function plots the equilibrium quantity and equilibrium price.
788801

789802
```{code-cell} ipython3
@@ -825,6 +838,7 @@ plot_ks_rs(K_t_vals, m_crra)
825838
```
826839

827840

841+
828842
```{solution-end}
829843
```
830844

@@ -867,11 +881,12 @@ To solve for $k_{t+1}$ we need to turn to the newton's method.
867881
Let's start by defining the utility function.
868882

869883
```{code-cell} ipython3
870-
def u_quasilinear(c, θ=6):
884+
def u_quasilinear(c, θ=3):
871885
return c + c**θ
872886
```
873887

874888

889+
875890
The function `find_k_next` is used to find $k_{t+1}$ by finding
876891
the root of equation [](euler_quasilinear1) using the helper
877892
function `solve_for_k_next` for a given value of $k_t$.
@@ -887,7 +902,10 @@ def solve_for_k_next(x, k_t, model):
887902

888903
```{code-cell} ipython3
889904
def find_k_next(k_t, model):
890-
return optimize.newton(solve_for_k_next, k_t, args=(k_t, model))
905+
x_vals = np.linspace(0.1, k_t, 200_000)
906+
k_vals = solve_for_k_next(x_vals, k_t, model)
907+
return x_vals[np.argmin(np.abs(k_vals-0))]
908+
# return optimize.newton(solve_for_k_next, k_t, args=(k_t, model))
891909
```
892910

893911
```{code-cell} ipython3
@@ -899,10 +917,14 @@ def solve_for_k_star_q(x, model):
899917
return l - r
900918
901919
def find_k_star_q(model):
902-
return optimize.newton(solve_for_k_star_q, 0.2, args=(model,))
920+
x_vals = np.linspace(0.1, 3, 200_000)
921+
k_vals = solve_for_k_next(x_vals, x_vals, model)
922+
return x_vals[np.argmin(np.abs(k_vals-0))]
923+
# return optimize.newton(solve_for_k_star_q, 0.2, args=(model,))
903924
```
904925

905926

927+
906928
Let's simulate and plot the time path capital $\{k_t\}$.
907929

908930
```{code-cell} ipython3
@@ -932,8 +954,8 @@ def simulate_ts(k0_values, model, ts_length=6):
932954
```
933955

934956
```{code-cell} ipython3
935-
k0_values = [0.2, 10, 50, 100]
936-
m_quasilinear = create_olg_model(u=u_quasilinear, u_params={'θ': 6})
957+
k0_values = [0.02, 10, 50, 100]
958+
m_quasilinear = create_olg_model(u=u_quasilinear, u_params={'θ': 3})
937959
simulate_ts(k0_values, m_quasilinear)
938960
```
939961

0 commit comments

Comments
 (0)