Skip to content

Commit 78855b7

Browse files
committed
minor updates
1 parent 0b4ca70 commit 78855b7

24 files changed

Lines changed: 330 additions & 326 deletions

lectures/ar1_processes.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -464,8 +464,8 @@ $$
464464
For $K$ use the Gaussian kernel ($K$ is the standard normal
465465
density).
466466
467-
Write the class so that the bandwidth defaults to Silvermans rule (see
468-
the rule of thumb discussion on [this
467+
Write the class so that the bandwidth defaults to Silverman's rule (see
468+
the "rule of thumb" discussion on [this
469469
page](https://en.wikipedia.org/wiki/Kernel_density_estimation)). Test
470470
the class you have written by going through the steps
471471

lectures/cagan_adaptive.md

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -464,9 +464,9 @@ The sluggish fall in inflation is explained by how anticipated inflation $\pi_t
464464
465465
For Experiment 1 (sudden stabilization at $T_1 = 60$ from $\mu_0 = 0.5$ to $\mu^* = 0$), solve the model for $\lambda \in \{0.86,\, 0.90,\, 0.95,\, 0.98\}$ and, on a single graph, plot the actual inflation rate $\pi_t$ for each value.
466466
467-
(a) How do the sign and speed of post-stabilization convergence change as $\lambda$ varies within the stable region?
467+
a. How do the sign and speed of post-stabilization convergence change as $\lambda$ varies within the stable region?
468468
469-
(b) For each $\lambda$, print $\rho$ and the peak absolute value of $\pi_t$ for $t \geq T_1$.
469+
b. For each $\lambda$, print $\rho$ and the peak absolute value of $\pi_t$ for $t \geq T_1$.
470470
```
471471
472472
```{solution-start} ca_ex1
@@ -494,7 +494,7 @@ ax.set_title('Inflation paths for different λ (sudden stabilization)')
494494
ax.legend()
495495
plt.show()
496496
497-
print(f'{"λ":>6} | {"ρ":>10} | {"|ρ|<1":>8} | {"peak |π| after T₁":>20}')
497+
print(f'{"λ":>6} | {"ρ":>10} | {"|ρ|<1":>8} | {"peak |π| after T1":>20}')
498498
print('-' * 56)
499499
for λ in λ_vals:
500500
m = create_cagan_adaptive_model(λ=λ)
@@ -524,12 +524,12 @@ expectations, in contrast to a rational-expectations equilibrium.
524524
525525
For the default model (`md`) and both experiments:
526526
527-
(a) Compute and plot the forecast error $e_t = \pi_t^* - \pi_t$ for
527+
a. Compute and plot the forecast error $e_t = \pi_t^* - \pi_t$ for
528528
$t = 0, 1, \ldots, T$.
529529
530-
(b) For each experiment, is $e_t$ systematically positive or negative during
531-
the disinflation? Explain why this systematic bias could not survive under
532-
rational expectations.
530+
b. For each experiment, determine whether $e_t$ is systematically positive or
531+
negative during the disinflation and explain why this systematic bias could
532+
not survive under rational expectations.
533533
534534
(Recall that `Eπ_seq` returned by `solve_cagan_adaptive` has $T+2$ elements
535535
while `π_seq` has $T+1$; use `Eπ_seq[:-1]` to align them.)
@@ -575,13 +575,13 @@ axes[1].set_ylabel(r'$\pi_t^* - \pi_t$')
575575
plt.tight_layout()
576576
plt.show()
577577
578-
print(f'Exp 1mean forecast error t < T₁: {e1[:T1].mean():.4f}')
579-
print(f'Exp 1mean forecast error t ≥ T₁: {e1[T1:].mean():.4f}')
580-
print(f'Exp 2mean forecast error overall: {e2.mean():.4f}')
578+
print(f'Exp 1: mean forecast error t < T1: {e1[:T1].mean():.4f}')
579+
print(f'Exp 1: mean forecast error t >= T1: {e1[T1:].mean():.4f}')
580+
print(f'Exp 2: mean forecast error overall: {e2.mean():.4f}')
581581
```
582582
583583
During disinflation, actual inflation falls *below* expected inflation, so
584-
$e_t = \pi_t^* - \pi_t > 0$ throughout the transition the public
584+
$e_t = \pi_t^* - \pi_t > 0$ throughout the transition, so the public
585585
systematically **over-predicts** inflation.
586586
587587
Under rational expectations this persistent one-sided bias would be immediately arbitraged away as agents adjust their forecasting rule until $e_t$ has mean zero.
@@ -604,14 +604,14 @@ $$
604604
605605
Using Experiment 1 and the default model `md`:
606606
607-
(a) Compute $\rho$ analytically from the model parameters and verify that
607+
a. Compute $\rho$ analytically from the model parameters and verify that
608608
$|\rho| < 1$ (the stability condition {eq}`eq:suffcond`).
609609
610-
(b) From the solved path `π_seq`, compute the empirical ratios
610+
b. From the solved path `π_seq`, compute the empirical ratios
611611
$\pi_{t+1}/\pi_t$ for $t = T_1 + 1, \ldots, T_1 + 10$ and compare them
612612
to $\rho$.
613613
614-
(c) Plot $\log|\pi_t|$ against $t$ for $t \geq T_1$ and verify that it is
614+
c. Plot $\log|\pi_t|$ against $t$ for $t \geq T_1$ and verify that it is
615615
linear with slope $\log|\rho|$.
616616
```
617617
@@ -632,7 +632,7 @@ print(f'ρ = {ρ:.6f} (|ρ| < 1: {abs(ρ) < 1})')
632632
μ_seq = np.append(μ0 * np.ones(T1), μ_star * np.ones(md.T + 1 - T1))
633633
π_seq, _, _, _ = solve_cagan_adaptive(md, μ_seq)
634634
635-
# (b) empirical successive ratios
635+
# Part b: empirical successive ratios
636636
print(f'\n{"t":>5} | {"π_t":>12} | {"π_{t+1}/π_t":>14} | {"ρ":>8}')
637637
print('-' * 46)
638638
for t in range(T1, T1 + 10):
@@ -641,7 +641,7 @@ for t in range(T1, T1 + 10):
641641
```
642642
643643
```{code-cell} ipython3
644-
# (c) log|π_t| is linear after T1
644+
# Part c: log|π_t| is linear after T1
645645
t_post = np.arange(T1, md.T + 1)
646646
log_π = np.log(np.abs(π_seq[T1:]))
647647
@@ -676,16 +676,16 @@ $\pi_t = \rho^{t-T_1} \pi_{T_1}$ for $t \geq T_1$.
676676
Experiment 2 uses a gradual decline in money growth
677677
$\mu_t = \phi^t \mu_0 + (1-\phi^t)\mu^*$ with $\phi = 0.9$.
678678
679-
(a) For the same gradual $\mu$ path, compare the inflation $\pi_t$ and expected inflation $\pi_t^*$ paths for two stable cases:
679+
a. For the same gradual $\mu$ path, compare the inflation $\pi_t$ and expected inflation $\pi_t^*$ paths for two stable cases:
680680
681681
* **Faster adjustment**: $\lambda = 0.86$
682682
* **Slower adjustment**: $\lambda = 0.95$
683683
684684
Plot $\pi_t$, $\pi_t^*$, and $\mu_t$ for each case on side-by-side graphs.
685685
686-
(b) For each case, compute the mean absolute forecast error $\bar{e} = \frac{1}{T+1}\sum_{t=0}^T |\pi_t^* - \pi_t|$.
686+
b. For each case, compute the mean absolute forecast error $\bar{e} = \frac{1}{T+1}\sum_{t=0}^T |\pi_t^* - \pi_t|$.
687687
688-
(c) Explain why the faster-adjustment case can move below the money-growth path while the slower-adjustment case displays more persistent forecast errors.
688+
c. Explain why the faster-adjustment case can move below the money-growth path while the slower-adjustment case displays more persistent forecast errors.
689689
```
690690
691691
```{solution-start} ca_ex4

lectures/cagan_ree.md

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -461,8 +461,9 @@ Such a completely unanticipated shock is popularly known as an "MIT shock".
461461
462462
The mental experiment involves switching at time $T_1$ from an initial "continuation path" for $\{\mu_t, \pi_t\} $ to another path that involves a permanently lower inflation rate.
463463
464-
**Initial Path:** $\mu_t = \mu_0$ for all $t \geq 0$. So this path is for $\{\mu_t\}_{t=0}^\infty$; the associated
465-
path for $\pi_t$ has $\pi_t = \mu_0$.
464+
**Initial Path:** $\mu_t = \mu_0$ for all $t \geq 0$.
465+
466+
This path is for $\{\mu_t\}_{t=0}^\infty$; the associated path for $\pi_t$ has $\pi_t = \mu_0$.
466467
467468
**Revised Continuation Path** Where $ \mu_0 > \mu^*$, we construct a continuation path $\{\mu_s\}_{s=T_1}^\infty$
468469
by setting $\mu_s = \mu^*$ for all $s \geq T_1$. The perfect foresight continuation path for
@@ -661,8 +662,8 @@ at $T_1 = 60$, with $T = 80$), solve the model for
661662
$\alpha \in \{1,\, 3,\, 5,\, 10,\, 25\}$ and plot the inflation path $\pi_t$ for
662663
each value on a single graph.
663664
664-
Describe how the **anticipation effect**the pre-stabilization fall in inflation
665-
changes with $\alpha$.
665+
Describe how the **anticipation effect**, the pre-stabilization fall in inflation,
666+
changes with $\alpha$.
666667
```
667668
668669
```{solution-start} cagan_ex1
@@ -716,9 +717,9 @@ $$
716717
\pi_t = (1-\delta) \sum_{s=t}^T \delta^{s-t} \mu_s + \delta^{T+1-t} \pi_{T+1}^*
717718
$$
718719
719-
Compute $\pi_t$ directly from this formula for each $t = 0, 1, \ldots, T$ and
720-
compare it to the matrix solution returned by `solve`. Plot both on the same
721-
graph and print the maximum absolute difference.
720+
Compute $\pi_t$ directly from this formula for each $t = 0, 1, \ldots, T$,
721+
compare it to the matrix solution returned by `solve`, plot both on the same
722+
graph, and print the maximum absolute difference.
722723
```
723724
724725
```{solution-start} cagan_ex2
@@ -770,14 +771,15 @@ The two methods agree to machine precision, confirming that the matrix system
770771
**Foreseen gradual vs sudden stabilization.**
771772
772773
Experiment 1 features a *sudden* foreseen drop in money growth at $T_1 = 60$.
774+
773775
Experiment 3 features a *gradual* foreseen path $\mu_t = \phi^t \mu_0 + (1-\phi^t)\mu^*$.
774776
775777
On a single graph, plot the inflation paths for:
776778
- Experiment 1 (sudden), and
777779
- Experiment 3 with $\phi \in \{0.95, 0.85, 0.70\}$ (increasingly fast gradualism).
778780
779-
Use $\alpha = 5$, $\mu_0 = 0.5$, $\mu^* = 0$, $T = 80$. Which approach generates
780-
the smoothest pre-stabilization decline in inflation?
781+
Use $\alpha = 5$, $\mu_0 = 0.5$, $\mu^* = 0$, and $T = 80$ to determine which
782+
approach generates the smoothest pre-stabilization decline in inflation.
781783
```
782784
783785
```{solution-start} cagan_ex3

lectures/cobweb.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ ax.plot(years, hog_prices, '-o', ms=4, label='hog price')
8282
ax.set_xlabel('year')
8383
ax.set_ylabel('dollars')
8484
ax.legend()
85-
ax.grid()
8685
plt.show()
8786
```
8887

@@ -595,4 +594,4 @@ ts_plot_price_blae(m,
595594
```
596595

597596
```{solution-end}
598-
```
597+
```

lectures/complex_and_trig.md

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,6 @@ ax.text(0-0.2, 0.5, '$x = 1$') # Label x
153153
ax.text(0.5, 1.2, r'$y = \sqrt{3}$') # Label y
154154
ax.text(0.25, 0.15, r'$\theta = 60^o$') # Label θ
155155
156-
ax.grid(True)
157156
plt.show()
158157
```
159158

@@ -351,7 +350,6 @@ ticklab = ax.yaxis.get_ticklabels()[0] # Set y-label position
351350
trans = ticklab.get_transform()
352351
ax.yaxis.set_label_coords(0, 5, transform=trans)
353352
354-
ax.grid()
355353
plt.show()
356354
```
357355

@@ -582,16 +580,16 @@ from sympy import Symbol, cos, sin, simplify
582580
583581
θ = Symbol('θ', real=True)
584582
585-
print("cos(2θ) = cos²θ − sin²θ:",
583+
print("cos(2θ) = cos(θ)**2 - sin(θ)**2:",
586584
simplify(cos(2*θ) - (cos(θ)**2 - sin(θ)**2)))
587585
588586
print("sin(2θ) = 2sinθcosθ:",
589587
simplify(sin(2*θ) - 2*sin(θ)*cos(θ)))
590588
591-
print("cos(2θ) = 2cos²θ − 1:",
589+
print("cos(2θ) = 2*cos(θ)**2 - 1:",
592590
simplify(cos(2*θ) - (2*cos(θ)**2 - 1)))
593591
594-
print("cos(2θ) = 1 − 2sin²θ:",
592+
print("cos(2θ) = 1 - 2*sin(θ)**2:",
595593
simplify(cos(2*θ) - (1 - 2*sin(θ)**2)))
596594
```
597595

@@ -657,13 +655,13 @@ from sympy import symbols, cos, sin, simplify
657655
658656
θ, w = symbols('θ w', real=True)
659657
660-
print("cos(θ+w) + cos(θ-w) 2cos(θ)cos(w) =",
658+
print("cos(θ+w) + cos(θ-w) - 2cos(θ)cos(w) =",
661659
simplify(cos(θ+w) + cos(θ-w) - 2*cos(θ)*cos(w)))
662660
663-
print("cos(θ-w) cos(θ+w) 2sin(θ)sin(w) =",
661+
print("cos(θ-w) - cos(θ+w) - 2sin(θ)sin(w) =",
664662
simplify(cos(θ-w) - cos(θ+w) - 2*sin(θ)*sin(w)))
665663
666-
print("sin(θ+w) + sin(θ-w) 2sin(θ)cos(w) =",
664+
print("sin(θ+w) + sin(θ-w) - 2sin(θ)cos(w) =",
667665
simplify(sin(θ+w) + sin(θ-w) - 2*sin(θ)*cos(w)))
668666
```
669667

lectures/cons_smooth.md

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,14 @@ Now let's compute and plot consumption path variations
551551
def compute_variation(model, ξ1, ϕ, a0, y_seq, verbose=1):
552552
R, T, β_seq = model.R, model.T, model.β_seq
553553
554-
ξ0 = ξ1*((1 - 1/R) / (1 - (1/R)**(T+1))) * ((1 - (ϕ/R)**(T+1)) / (1 - ϕ/R))
554+
growth = ϕ / R
555+
if np.isclose(growth, 1):
556+
pv_sum = T + 1
557+
else:
558+
pv_sum = (1 - growth**(T+1)) / (1 - growth)
559+
560+
annuity = (1 - 1/R) / (1 - (1/R)**(T+1))
561+
ξ0 = ξ1 * annuity * pv_sum
555562
v_seq = np.array([(ξ1*ϕ**t - ξ0) for t in range(T+1)])
556563
557564
if verbose == 1:
@@ -901,11 +908,11 @@ $$
901908
902909
and the default model parameters.
903910
904-
(a) Plot all four consumption paths on a single graph. What do you notice about
905-
their shapes relative to one another?
911+
a. Plot all four consumption paths on a single graph and describe their shapes
912+
relative to one another.
906913
907-
(b) Plot $c_0$ against $a_0$ and compute the slope of the resulting line.
908-
Verify that the slope equals the annuity factor
914+
b. Plot $c_0$ against $a_0$, compute the slope of the resulting line, and verify
915+
that the slope equals the annuity factor
909916
$\left(\frac{1-R^{-1}}{1-R^{-(T+1)}}\right)$ from equation {eq}`eq:conssmoothing`.
910917
```
911918
@@ -946,7 +953,7 @@ R = cs_model.R
946953
slope = (c0_vals[-1] - c0_vals[0]) / (a0_vals[-1] - a0_vals[0])
947954
annuity = (1 - 1/R) / (1 - (1/R)**(T+1))
948955
print(f'Numerical slope of c0 w.r.t. a0: {slope:.8f}')
949-
print(f'Annuity factor (1 - R⁻¹)/(1 - R⁻⁽ᵀ⁺¹⁾): {annuity:.8f}')
956+
print(f'Annuity factor (1 - R**(-1))/(1 - R**(-(T+1))): {annuity:.8f}')
950957
print(f'Match: {np.isclose(slope, annuity)}')
951958
```
952959
@@ -968,13 +975,13 @@ maximizes welfare {eq}`welfare` among all budget-feasible paths.
968975
Using `compute_variation` with $\xi_1 = 0.1$ and the Experiment 1 income sequence
969976
($W_0 = 2.5$ windfall at $t=21$, with $a_0 = -2$):
970977
971-
(a) Compute welfare for the optimal flat path and for variations with $\phi \in \{0.7,\, 0.9,\, 0.98,\, 1.02,\, 1.1\}$.
978+
a. Compute welfare for the optimal flat path and for variations with $\phi \in \{0.7,\, 0.9,\, 0.98,\, 1.02,\, 1.1\}$.
972979
973980
Print the results in a table.
974981
975-
(b) Plot welfare as a function of $\phi$ on a fine grid in $(0.5, 1.5)$. Mark the
976-
welfare of the optimal flat path as a dashed horizontal line and confirm it is
977-
the global maximum.
982+
b. Plot welfare as a function of $\phi$ on a fine grid in $[0.7, 1.1]$ and mark
983+
the welfare of the optimal flat path as a dashed horizontal line to confirm
984+
that it lies above these budget-feasible variations.
978985
```
979986
980987
```{solution-start} consmooth_ex4
@@ -1001,7 +1008,7 @@ for ϕ in ϕ_vals:
10011008
print(f'{ϕ:>6.2f} | {w:>12.6f} | {w - w_opt:>+14.6f}')
10021009
10031010
# Fine grid
1004-
ϕ_grid = np.linspace(0.5, 1.5, 200)
1011+
ϕ_grid = np.linspace(0.7, 1.1, 200)
10051012
w_grid = np.array([
10061013
welfare(cs_model,
10071014
compute_variation(cs_model, ξ1=0.1, ϕ=ϕ, a0=a0,
@@ -1021,6 +1028,8 @@ plt.show()
10211028
10221029
Every non-zero variation in the plotted family delivers strictly lower welfare than the flat path marked by the horizontal dashed line.
10231030
1031+
The wider interval $(0.5, 1.5)$ is not informative here because values of $\phi$ well above one make the late-life variation $\xi_1\phi^t$ very large.
1032+
10241033
This numerically confirms the variational principle that the constant consumption path is the global welfare maximizer when $\beta R = 1$.
10251034
10261035
```{solution-end}

lectures/eigen_I.md

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -222,13 +222,11 @@ def grid_transform(A=np.array([[1, -1], [1, 1]])):
222222
223223
# Plot x-y grid points
224224
ax[0].scatter(xygrid[0], xygrid[1], s=36, c=colors, edgecolor="none")
225-
# ax[0].grid(True)
226225
# ax[0].axis("equal")
227226
ax[0].set_title("points $x_1, x_2, \cdots, x_k$")
228227
229228
# Plot transformed grid points
230229
ax[1].scatter(uvgrid[0], uvgrid[1], s=36, c=colors, edgecolor="none")
231-
# ax[1].grid(True)
232230
# ax[1].axis("equal")
233231
ax[1].set_title("points $Ax_1, Ax_2, \cdots, Ax_k$")
234232
@@ -746,7 +744,6 @@ for spine in ['left', 'bottom']:
746744
ax.spines[spine].set_position('zero')
747745
for spine in ['right', 'top']:
748746
ax.spines[spine].set_color('none')
749-
# ax.grid(alpha=0.4)
750747
751748
xmin, xmax = -3, 3
752749
ymin, ymax = -3, 3
@@ -1148,7 +1145,6 @@ plt.legend(lines, labels, loc='center left',
11481145
plt.xlabel("x")
11491146
plt.ylabel("y")
11501147
plt.title("Convergence towards eigenvectors")
1151-
plt.grid()
11521148
plt.gca().set_aspect('equal', adjustable='box')
11531149
plt.show()
11541150
```
@@ -1237,7 +1233,6 @@ for i, example in enumerate(examples):
12371233
12381234
ax[i].set_xlabel("x-axis")
12391235
ax[i].set_ylabel("y-axis")
1240-
ax[i].grid()
12411236
ax[i].set_aspect('equal', adjustable='box')
12421237
12431238
fig.suptitle("Vector fields of the three matrices")

0 commit comments

Comments
 (0)