From ef2b15dc52eec99e6296d86457ca672862a02a43 Mon Sep 17 00:00:00 2001 From: shlff Date: Thu, 16 Nov 2023 22:53:06 +1100 Subject: [PATCH] [olg] use function --- lectures/olg.md | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/lectures/olg.md b/lectures/olg.md index 2097700b..90c6789a 100644 --- a/lectures/olg.md +++ b/lectures/olg.md @@ -4,7 +4,7 @@ jupytext: extension: .md format_name: myst format_version: 0.13 - jupytext_version: 1.14.5 + jupytext_version: 1.15.2 kernelspec: display_name: Python 3 (ipykernel) language: python @@ -294,12 +294,17 @@ def capital_demand(R, α): return (α/R)**(1/(1-α)) ``` +```{code-cell} ipython3 +def capital_supply(R, β, w): + R = np.ones_like(R) + return R * (β / (1 + β)) * w +``` + 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}$. (For the special case of log utility, supply does not depend on the interest rate, so we have a constant function.) ```{code-cell} ipython3 - R_vals = np.linspace(0.3, 1) α, β = 0.5, 0.9 w = 2.0 @@ -308,7 +313,7 @@ fig, ax = plt.subplots() ax.plot(R_vals, capital_demand(R_vals, α), label="aggregate demand") -ax.plot(R_vals, np.ones_like(R_vals) * (β / (1 + β)) * w, +ax.plot(R_vals, capital_supply(R_vals, β, w), label="aggregate supply") ax.set_xlabel("$R_{t+1}$") @@ -391,7 +396,6 @@ That is, Let's redo our plot above but now inserting the equilibrium quantity and price. ```{code-cell} ipython3 - R_vals = np.linspace(0.3, 1) α, β = 0.5, 0.9 w = 2.0 @@ -400,7 +404,7 @@ fig, ax = plt.subplots() ax.plot(R_vals, capital_demand(R_vals, α), label="aggregate demand") -ax.plot(R_vals, np.ones_like(R_vals) * (β / (1 + β)) * w, +ax.plot(R_vals, capital_supply(R_vals, β, w), label="aggregate supply") R_e = equilibrium_R_log_utility(α, β, w) @@ -452,7 +456,6 @@ $$ g(k) := \frac{\beta}{1+\beta} (1-\alpha)(k)^{\alpha} $$ - ```{code-cell} ipython3 def k_update(k, α, β): return β * (1 - α) * k**α / (1 + β) @@ -627,7 +630,6 @@ def savings_crra(w, R, model): ``` ```{code-cell} ipython3 - R_vals = np.linspace(0.3, 1) model = create_olg_model() w = 2.0 @@ -760,7 +762,6 @@ ax.set_ylabel('$k_{t+1}$', fontsize=12) plt.show() ``` - ```{solution-end} ``` @@ -821,7 +822,6 @@ k_star = optimize.newton(h, 0.2, args=(model,)) print(f"k_star = {k_star}") ``` - ```{solution-end} ``` @@ -846,7 +846,6 @@ Use initial conditions for $k_0$ of $0.001, 1.2, 2.6$ and time series length 10. Let's define the constants and three distinct intital conditions - ```{code-cell} ipython3 ts_length = 10 k0 = np.array([0.001, 1.2, 2.6])