Skip to content

Commit 3b18dee

Browse files
committed
minor updates
1 parent fdef06a commit 3b18dee

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

lectures/ak_aiyagari.md

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -733,8 +733,10 @@ def find_ss(household, firm, pol_target, Q, tol=1e-6, verbose=False):
733733
ss1 = find_ss(hh, firm, [0, 0.1, np.zeros(hh.j_grid.size)], Q, verbose=True)
734734
```
735735

736+
Let's time the computation
737+
736738
```{code-cell} ipython3
737-
%time find_ss(hh, firm, [0, 0.1, np.zeros(hh.j_grid.size)], Q).block_until_ready();
739+
%time find_ss(hh, firm, [0, 0.1, np.zeros(hh.j_grid.size)], Q)[0].block_until_ready();
738740
```
739741

740742
```{code-cell} ipython3
@@ -994,10 +996,12 @@ def path_iteration(ss1, ss2, pol_target, household, firm, Q, tol=1e-4, verbose=F
994996
price_seq = (r_seq, w_seq)
995997
996998
# Solve optimal policies backwards
997-
V_seq, σ_seq = solve_backwards(V_ss2, σ_ss2, hh, firm, price_seq, pol_seq, Q)
999+
V_seq, σ_seq = solve_backwards(
1000+
V_ss2, σ_ss2, hh, firm, price_seq, pol_seq, Q)
9981001
9991002
# Compute population evolution forwards
1000-
μ_seq, K_seq, L_seq = simulate_forwards(σ_seq, D_seq, μ_ss1, K_ss1, L_ss1, household, Q)
1003+
μ_seq, K_seq, L_seq = simulate_forwards(
1004+
σ_seq, D_seq, μ_ss1, K_ss1, L_ss1, household, Q)
10011005
10021006
# Update prices by aggregate capital and labor supply
10031007
r_seq = KL_to_r(K_seq, L_seq, firm)
@@ -1015,7 +1019,7 @@ def path_iteration(ss1, ss2, pol_target, household, firm, Q, tol=1e-4, verbose=F
10151019
10161020
num_iter += 1
10171021
if verbose:
1018-
print(error)
1022+
print(f"Iteration {num_iter:3d}: error = {error:.6e}")
10191023
axs[0].plot(jnp.arange(T), r_seq)
10201024
axs[1].plot(jnp.arange(T), w_seq)
10211025
axs[2].plot(jnp.arange(T), τ_seq, label=f'iter {num_iter}')
@@ -1035,7 +1039,8 @@ def path_iteration(ss1, ss2, pol_target, household, firm, Q, tol=1e-4, verbose=F
10351039
10361040
axs[2].legend(loc='center left', bbox_to_anchor=(1, 0.5))
10371041
1038-
return V_seq, σ_seq, μ_seq, K_seq, L_seq, r_seq, w_seq, τ_seq, D_seq, G_seq, δ_seq
1042+
return V_seq, σ_seq, μ_seq, K_seq, L_seq, r_seq, w_seq, \
1043+
τ_seq, D_seq, G_seq, δ_seq
10391044
```
10401045

10411046
We can now compute equilibrium transitions that are ignited by fiscal policy reforms.
@@ -1112,7 +1117,8 @@ t = 0
11121117
ap = hh.a_grid[σ_seq[t]]
11131118
δ = δ_seq[t].reshape((hh.j_grid.size, 1, 1))
11141119
1115-
inc = (1 + r_seq[t]*(1-τ_seq[t])) * a + (1-τ_seq[t]) * w_seq[t] * lj * γ - δ
1120+
inc = (1 + r_seq[t]*(1-τ_seq[t])) * a \
1121+
+ (1-τ_seq[t]) * w_seq[t] * lj * γ - δ
11161122
inc = inc.reshape((hh.j_grid.size, hh.a_grid.size * hh.γ_grid.size))
11171123
11181124
c = inc - ap
@@ -1142,6 +1148,7 @@ for t in [1, 10, 20, 50, 149]:
11421148
plt.legend()
11431149
plt.xlabel(r'j')
11441150
plt.title(r'$\Delta mean(C(j))$')
1151+
plt.show()
11451152
```
11461153

11471154
To summarize the transition, we can plot paths as we did in {doc}`ak2`.
@@ -1289,7 +1296,8 @@ ss2 = find_ss(hh, firm, [D_seq[-1], G_seq[-1], δ_seq[-1]], Q)
12891296
```
12901297

12911298
```{code-cell} ipython3
1292-
paths = path_iteration(ss1, ss2, [D_seq, G_seq, δ_seq], hh, firm, Q, verbose=True)
1299+
paths = path_iteration(ss1, ss2, [D_seq, G_seq, δ_seq],
1300+
hh, firm, Q, verbose=True)
12931301
```
12941302

12951303
```{code-cell} ipython3
@@ -1370,6 +1378,7 @@ plt.text(17, 6.56, r'tax cut')
13701378
plt.ylim([6.52, 6.65])
13711379
plt.title("K")
13721380
plt.xlabel("t")
1381+
plt.show()
13731382
```
13741383

13751384
After the tax cut policy is implemented at $t=20$, the aggregate capital will decrease because of the crowding out effect.
@@ -1398,7 +1407,8 @@ for t in range(T):
13981407
c = inc - ap
13991408
14001409
Cmean_seq[t] = (c * μ_seq[t]).sum(axis=1)
1401-
Cvar_seq[t] = ((c - Cmean_seq[t].reshape((J, 1))) ** 2 * μ_seq[t]).sum(axis=1)
1410+
Cvar_seq[t] = (
1411+
(c - Cmean_seq[t].reshape((J, 1))) ** 2 * μ_seq[t]).sum(axis=1)
14021412
```
14031413

14041414
```{code-cell} ipython3

0 commit comments

Comments
 (0)