diff --git a/lectures/BCG_complete_mkts.md b/lectures/BCG_complete_mkts.md index 282a692b..ab195e93 100644 --- a/lectures/BCG_complete_mkts.md +++ b/lectures/BCG_complete_mkts.md @@ -1090,8 +1090,8 @@ epsgrid = np.linspace(-1,1,1000) fig, ax = plt.subplots(1,2,figsize=(14,6)) -ax[0].plot(epsgrid, mdl1.w11(epsgrid), color='black', label='Agent 1\'s endowment') -ax[0].plot(epsgrid, mdl1.w21(epsgrid), color='blue', label='Agent 2\'s endowment') +ax[0].plot(epsgrid, mdl1.w11(epsgrid), color='black', label=r'Agent 1\'s endowment') +ax[0].plot(epsgrid, mdl1.w21(epsgrid), color='blue', label=r'Agent 2\'s endowment') ax[0].plot(epsgrid, mdl1.Y(epsgrid,1), color='red', label=r'Production with $k=1$') ax[0].set_xlim([-1,1]) ax[0].set_ylim([0,7]) @@ -1100,8 +1100,8 @@ ax[0].set_title(r'Model with $\chi_1 = 0$, $\chi_2 = 0.9$') ax[0].legend() ax[0].grid() -ax[1].plot(epsgrid, mdl2.w11(epsgrid), color='black', label='Agent 1\'s endowment') -ax[1].plot(epsgrid, mdl2.w21(epsgrid), color='blue', label='Agent 2\'s endowment') +ax[1].plot(epsgrid, mdl2.w11(epsgrid), color='black', label=r'Agent 1\'s endowment') +ax[1].plot(epsgrid, mdl2.w21(epsgrid), color='blue', label=r'Agent 2\'s endowment') ax[1].plot(epsgrid, mdl2.Y(epsgrid,1), color='red', label=r'Production with $k=1$') ax[1].set_xlim([-1,1]) ax[1].set_ylim([0,7]) diff --git a/lectures/arma.md b/lectures/arma.md index 9147f80e..a7718ef1 100644 --- a/lectures/arma.md +++ b/lectures/arma.md @@ -241,7 +241,7 @@ for i, ϕ in enumerate((0.8, -0.8)): times = list(range(16)) acov = [ϕ**k / (1 - ϕ**2) for k in times] ax.plot(times, acov, 'bo-', alpha=0.6, - label=f'autocovariance, $\phi = {ϕ:.2}$') + label=fr'autocovariance, $\phi = {ϕ:.2}$') ax.legend(loc='upper right') ax.set(xlabel='time', xlim=(0, 15)) ax.hlines(0, 0, 15, linestyle='--', alpha=0.5) @@ -479,7 +479,7 @@ for i, ϕ in enumerate((0.8, -0.8)): ax = axes[i] sd = ar1_sd(ϕ, ωs) ax.plot(ωs, sd, 'b-', alpha=0.6, lw=2, - label='spectral density, $\phi = {ϕ:.2}$') + label=fr'spectral density, $\phi = {ϕ:.2}$') ax.legend(loc='upper center') ax.set(xlabel='frequency', xlim=(0, np.pi)) plt.show() @@ -525,21 +525,21 @@ plt.subplots_adjust(hspace=0.25) # Autocovariance when ϕ = -0.8 ax = axes[0] -ax.plot(times, y1, 'bo-', alpha=0.6, label='$\gamma(k)$') +ax.plot(times, y1, 'bo-', alpha=0.6, label=r'$\gamma(k)$') ax.legend(loc='upper right') ax.set(xlim=(0, 15), yticks=(-2, 0, 2)) ax.hlines(0, 0, 15, linestyle='--', alpha=0.5) # Cycles at frequency π ax = axes[1] -ax.plot(times, y2, 'bo-', alpha=0.6, label='$\cos(\pi k)$') +ax.plot(times, y2, 'bo-', alpha=0.6, label=r'$\cos(\pi k)$') ax.legend(loc='upper right') ax.set(xlim=(0, 15), yticks=(-1, 0, 1)) ax.hlines(0, 0, 15, linestyle='--', alpha=0.5) # Product ax = axes[2] -ax.stem(times, y3, label='$\gamma(k) \cos(\pi k)$') +ax.stem(times, y3, label=r'$\gamma(k) \cos(\pi k)$') ax.legend(loc='upper right') ax.set(xlim=(0, 15), ylim=(-3, 3), yticks=(-1, 0, 1, 2, 3)) ax.hlines(0, 0, 15, linestyle='--', alpha=0.5) @@ -565,21 +565,21 @@ plt.subplots_adjust(hspace=0.25) # Autocovariance when phi = -0.8 ax = axes[0] -ax.plot(times, y1, 'bo-', alpha=0.6, label='$\gamma(k)$') +ax.plot(times, y1, 'bo-', alpha=0.6, label=r'$\gamma(k)$') ax.legend(loc='upper right') ax.set(xlim=(0, 15), yticks=(-2, 0, 2)) ax.hlines(0, 0, 15, linestyle='--', alpha=0.5) # Cycles at frequency π ax = axes[1] -ax.plot(times, y2, 'bo-', alpha=0.6, label='$\cos(\pi k/3)$') +ax.plot(times, y2, 'bo-', alpha=0.6, label=r'$\cos(\pi k/3)$') ax.legend(loc='upper right') ax.set(xlim=(0, 15), yticks=(-1, 0, 1)) ax.hlines(0, 0, 15, linestyle='--', alpha=0.5) # Product ax = axes[2] -ax.stem(times, y3, label='$\gamma(k) \cos(\pi k/3)$') +ax.stem(times, y3, label=r'$\gamma(k) \cos(\pi k/3)$') ax.legend(loc='upper right') ax.set(xlim=(0, 15), ylim=(-3, 3), yticks=(-1, 0, 1, 2, 3)) ax.hlines(0, 0, 15, linestyle='--', alpha=0.5) diff --git a/lectures/asset_pricing_lph.md b/lectures/asset_pricing_lph.md index 09509356..8dcfd275 100644 --- a/lectures/asset_pricing_lph.md +++ b/lectures/asset_pricing_lph.md @@ -384,7 +384,7 @@ plt.title('mean standard deviation frontier') plt.xlabel(r"$\sigma(R^i)$") plt.ylabel(r"$E (R^i) $") plt.text(.053, 1.015, "(.05,1.015)") -ax.plot(.05, 1.015, 'o', label="$(\sigma(R^j), E R^j)$") +ax.plot(.05, 1.015, 'o', label=r"$(\sigma(R^j), E R^j)$") # Add a legend and show the plot ax.legend() plt.show() diff --git a/lectures/black_litterman.md b/lectures/black_litterman.md index 59c3cdbe..44cc29c6 100644 --- a/lectures/black_litterman.md +++ b/lectures/black_litterman.md @@ -319,8 +319,8 @@ d_m = r_m / σ_m x = np.arange(N) + 1 fig, ax = plt.subplots(figsize=(8, 5)) ax.set_title(r'Difference between $\hat{\mu}$ (estimate) and $\mu_{BL}$ (market implied)') -ax.plot(x, μ_est, 'o', c='k', label='$\hat{\mu}$') -ax.plot(x, μ_m, 'o', c='r', label='$\mu_{BL}$') +ax.plot(x, μ_est, 'o', c='k', label=r'$\hat{\mu}$') +ax.plot(x, μ_m, 'o', c='r', label=r'$\mu_{BL}$') ax.vlines(x, μ_m, μ_est, lw=1) ax.axhline(0, c='k', ls='--') ax.set_xlabel('Assets') diff --git a/lectures/calvo_machine_learn.md b/lectures/calvo_machine_learn.md index daac8aa6..ec6abc69 100644 --- a/lectures/calvo_machine_learn.md +++ b/lectures/calvo_machine_learn.md @@ -1230,7 +1230,7 @@ Let's plot the regression line $\mu_t = .0645 + 1.5995 \theta_t$ and the points ```{code-cell} ipython3 plt.scatter(θs, μs, label=r'$\mu_t$') -plt.plot(θs, results1.predict(X1_θ), 'grey', label='$\hat \mu_t$', linestyle='--') +plt.plot(θs, results1.predict(X1_θ), 'grey', label=r'$\hat \mu_t$', linestyle='--') plt.xlabel(r'$\theta_t$') plt.ylabel(r'$\mu_t$') plt.legend() @@ -1271,7 +1271,7 @@ Let's plot $\theta_t$ for $t =0, 1, \ldots, T$ along the line. ```{code-cell} ipython3 plt.scatter(θ_t, θ_t1, label=r'$\theta_{t+1}$') -plt.plot(θ_t, results2.predict(X2_θ), color='grey', label='$\hat θ_{t+1}$', linestyle='--') +plt.plot(θ_t, results2.predict(X2_θ), color='grey', label=r'$\hat θ_{t+1}$', linestyle='--') plt.xlabel(r'$\theta_t$') plt.ylabel(r'$\theta_{t+1}$') plt.legend() @@ -1321,7 +1321,7 @@ X3_grid = np.column_stack((np.ones(len(θ_grid)), θ_grid, θ_grid**2)) plt.scatter(θs, v_t) plt.plot(θ_grid, results3.predict(X3_grid), color='grey', - label='$\hat v_t$', linestyle='--') + label=r'$\hat v_t$', linestyle='--') plt.axhline(V_CR, color='C1', alpha=0.5) plt.text(max(θ_grid) - max(θ_grid)*0.025, V_CR, '$V^{CR}$', color='C1', diff --git a/lectures/coase.md b/lectures/coase.md index 112c0f8e..97f2c379 100644 --- a/lectures/coase.md +++ b/lectures/coase.md @@ -552,7 +552,7 @@ for i, s in enumerate(pc.grid): ell_star[i] = e fig, ax = plt.subplots() -ax.plot(pc.grid, ell_star, label="$\ell^*$") +ax.plot(pc.grid, ell_star, label=r"$\ell^*$") ax.legend(fontsize=14) plt.show() ``` diff --git a/lectures/discrete_dp.md b/lectures/discrete_dp.md index a70b2977..96581d7d 100644 --- a/lectures/discrete_dp.md +++ b/lectures/discrete_dp.md @@ -935,7 +935,7 @@ for beta in discount_factors: res0 = ddp0.solve() k_path_ind = res0.mc.simulate(init=k_init_ind, ts_length=sample_size) k_path = grid[k_path_ind] - ax.plot(k_path, 'o-', lw=2, alpha=0.75, label=f'$\\beta = {beta}$') + ax.plot(k_path, 'o-', lw=2, alpha=0.75, label=fr'$\beta = {beta}$') ax.legend(loc='lower right') plt.show() diff --git a/lectures/markov_jump_lq.md b/lectures/markov_jump_lq.md index d7bf7c47..7285e7cf 100644 --- a/lectures/markov_jump_lq.md +++ b/lectures/markov_jump_lq.md @@ -444,8 +444,8 @@ u1_star = - ex1_a.Fs[0, 0, 1] - ex1_a.Fs[0, 0, 0] * k_grid u2_star = - ex1_a.Fs[1, 0, 1] - ex1_a.Fs[1, 0, 0] * k_grid fig, ax = plt.subplots() -ax.plot(k_grid, k_grid + u1_star, label="$\overline{s}_1$ (high)") -ax.plot(k_grid, k_grid + u2_star, label="$\overline{s}_2$ (low)") +ax.plot(k_grid, k_grid + u1_star, label=r"$\overline{s}_1$ (high)") +ax.plot(k_grid, k_grid + u2_star, label=r"$\overline{s}_2$ (low)") # The optimal k* ax.scatter([0.5, 0.5], [0.5, 0.5], marker="*") @@ -546,10 +546,10 @@ for i, λ in enumerate(λ_vals): ```{code-cell} python3 for i, state_var in enumerate(state_vec1): fig, ax = plt.subplots() - ax.plot(λ_vals, F1[:, i], label="$\overline{s}_1$", color="b") - ax.plot(λ_vals, F2[:, i], label="$\overline{s}_2$", color="r") + ax.plot(λ_vals, F1[:, i], label=r"$\overline{s}_1$", color="b") + ax.plot(λ_vals, F2[:, i], label=r"$\overline{s}_2$", color="r") - ax.set_xlabel("$\lambda$") + ax.set_xlabel(r"$\lambda$") ax.set_ylabel("$F_{s_t}$") ax.set_title(f"Coefficient on {state_var}") ax.legend() @@ -617,8 +617,8 @@ for i, state_var in enumerate(state_vec1): ax.plot_surface(λ_grid, δ_grid, F1_grid[:, :, i], color="b") # low adjustment cost, red surface ax.plot_surface(λ_grid, δ_grid, F2_grid[:, :, i], color="r") - ax.set_xlabel("$\lambda$") - ax.set_ylabel("$\delta$") + ax.set_xlabel(r"$\lambda$") + ax.set_ylabel(r"$\delta$") ax.set_zlabel("$F_{s_t}$") ax.set_title(f"coefficient on {state_var}") plt.show() @@ -656,11 +656,11 @@ def run(construct_func, vals_dict, state_vec): for i, state_var in enumerate(state_vec): fig = plt.figure() ax = fig.add_subplot(111) - ax.plot(λ_vals, F1[:, i], label="$\overline{s}_1$", color="b") - ax.plot(λ_vals, F2[:, i], label="$\overline{s}_2$", color="r") + ax.plot(λ_vals, F1[:, i], label=r"$\overline{s}_1$", color="b") + ax.plot(λ_vals, F2[:, i], label=r"$\overline{s}_2$", color="r") - ax.set_xlabel("$\lambda$") - ax.set_ylabel("$F(\overline{s}_t)$") + ax.set_xlabel(r"$\lambda$") + ax.set_ylabel(r"$F(\overline{s}_t)$") ax.set_title(f"coefficient on {state_var}") ax.legend() plt.show() @@ -674,17 +674,17 @@ def run(construct_func, vals_dict, state_vec): F = [F1, F2][i] c = ["b", "r"][i] ax.plot([0, 1], [k_star[i], k_star[i]], "--", - color=c, label="$k^*(\overline{s}_"+str(i+1)+")$") + color=c, label=r"$k^*(\overline{s}_"+str(i+1)+")$") ax.plot(λ_vals, - F[:, 1] / F[:, 0], color=c, - label="$k^{target}(\overline{s}_"+str(i+1)+")$") + label=r"$k^{target}(\overline{s}_"+str(i+1)+")$") # Plot a vertical line at λ=0.5 ax.plot([0.5, 0.5], [min(k_star), max(k_star)], "-.") - ax.set_xlabel("$\lambda$") + ax.set_xlabel(r"$\lambda$") ax.set_ylabel("$k$") ax.set_title("Optimal k levels and k targets") - ax.text(0.5, min(k_star)+(max(k_star)-min(k_star))/20, "$\lambda=0.5$") + ax.text(0.5, min(k_star)+(max(k_star)-min(k_star))/20, r"$\lambda=0.5$") ax.legend(bbox_to_anchor=(1., 1.)) plt.show() @@ -714,9 +714,9 @@ def run(construct_func, vals_dict, state_vec): ax = fig.add_subplot(111, projection='3d') ax.plot_surface(λ_grid, δ_grid, F1_grid[:, :, i], color="b") ax.plot_surface(λ_grid, δ_grid, F2_grid[:, :, i], color="r") - ax.set_xlabel("$\lambda$") - ax.set_ylabel("$\delta$") - ax.set_zlabel("$F(\overline{s}_t)$") + ax.set_xlabel(r"$\lambda$") + ax.set_ylabel(r"$\delta$") + ax.set_zlabel(r"$F(\overline{s}_t)$") ax.set_title(f"coefficient on {state_var}") plt.show() ``` diff --git a/lectures/opt_tax_recur.md b/lectures/opt_tax_recur.md index 92c5c734..6ca476d6 100644 --- a/lectures/opt_tax_recur.md +++ b/lectures/opt_tax_recur.md @@ -1242,7 +1242,7 @@ for ax, title, plot in zip(axes, titles, [tax_policy, interest_rate]): ax.set(title=title, xlim=(min(gov_debt), max(gov_debt))) ax.grid() -axes[0].legend(('Time $t=0$', 'Time $t \geq 1$')) +axes[0].legend(('Time $t=0$', r'Time $t \geq 1$')) axes[1].set_xlabel('Initial Government Debt') fig.tight_layout() diff --git a/lectures/rob_markov_perf.md b/lectures/rob_markov_perf.md index a4825a33..ff77cf2a 100644 --- a/lectures/rob_markov_perf.md +++ b/lectures/rob_markov_perf.md @@ -469,7 +469,7 @@ The function's code is as follows def nnash_robust(A, C, B1, B2, R1, R2, Q1, Q2, S1, S2, W1, W2, M1, M2, θ1, θ2, beta=1.0, tol=1e-8, max_iter=1000): - """ + r""" Compute the limit of a Nash linear quadratic dynamic game with robustness concern. diff --git a/lectures/rosen_schooling_model.md b/lectures/rosen_schooling_model.md index 5a489803..ec0e21bb 100644 --- a/lectures/rosen_schooling_model.md +++ b/lectures/rosen_schooling_model.md @@ -291,13 +291,13 @@ shock on $N_t$ is larger ```{code-cell} python3 fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(12, 4)) -ax1.plot(econ1.c_irf,label='$\\alpha_d = 0.1$') -ax1.plot(econ2.c_irf,label='$\\alpha_d = 2$') +ax1.plot(econ1.c_irf,label=r'$\alpha_d = 0.1$') +ax1.plot(econ2.c_irf,label=r'$\alpha_d = 2$') ax1.legend() ax1.set_title('Response of $n_t$ to a demand shock') -ax2.plot(econ1.h_irf[:, 0], label='$\\alpha_d = 0.1$') -ax2.plot(econ2.h_irf[:, 0], label='$\\alpha_d = 24$') +ax2.plot(econ1.h_irf[:, 0], label=r'$\alpha_d = 0.1$') +ax2.plot(econ2.h_irf[:, 0], label=r'$\alpha_d = 24$') ax2.legend() ax2.set_title('Response of $N_t$ to a demand shock') plt.show()