@@ -79,7 +79,7 @@ from itertools import combinations
7979import matplotlib.pyplot as plt
8080import numpy as np
8181import pandas as pd
82- from IPython.display import Math
82+ from IPython.display import Latex
8383from pandas_datareader import data as web
8484from scipy import stats
8585from scipy.linalg import LinAlgError, cholesky, solve_triangular
@@ -88,7 +88,7 @@ from statsmodels.stats.stattools import durbin_watson
8888
8989warnings.filterwarnings(
9090 "ignore", message=".*date_parser.*", category=FutureWarning
91- )
91+ )
9292```
9393
9494We also define a helper to display DataFrames as LaTeX arrays in the hidden cell below
@@ -98,7 +98,7 @@ We also define a helper to display DataFrames as LaTeX arrays in the hidden cell
9898
9999def display_table(df, title=None, fmt=None):
100100 """
101- Display a DataFrame as a LaTeX array using IPython Math .
101+ Display a DataFrame as a LaTeX array.
102102 """
103103 if fmt is None:
104104 fmt = {}
@@ -107,6 +107,7 @@ def display_table(df, title=None, fmt=None):
107107 if col in fmt:
108108 formatted[col] = formatted[col].apply(
109109 lambda x: fmt[col].format(x) if np.isfinite(x) else str(x))
110+ n_cols = len(formatted.columns)
110111 idx_header = r"\text{" + df.index.name + "}" if df.index.name else ""
111112 columns = " & ".join(
112113 [idx_header] + [r"\text{" + c + "}" if "\\" not in c
@@ -115,15 +116,16 @@ def display_table(df, title=None, fmt=None):
115116 rows = r" \\".join(
116117 [" & ".join([str(idx)] + [str(v) for v in row])
117118 for idx, row in zip(formatted.index, formatted.values)])
118- align = "r" + "c" * len(formatted.columns)
119- latex = rf"""\begin{{array}}{{{align}}}
120- {columns} \\
121- \hline
122- {rows}
123- \end{{array}}"""
119+ col_format = "r" + "c" * n_cols
120+ lines = [r"\begin{array}{" + col_format + "}"]
121+ lines.append(columns + r" \\")
122+ lines.append(r"\hline")
123+ lines.append(rows)
124+ lines.append(r"\end{array}")
125+ latex = "\n".join(lines)
124126 if title:
125127 latex = rf"\textbf{{{title}}}" + r"\\" + "\n" + latex
126- display(Math( latex))
128+ display(Latex("$" + latex + "$" ))
127129```
128130
129131## Euler equation
@@ -964,7 +966,7 @@ def run_mle_by_lag(
964966
965967 rows.append(
966968 {
967- "n_lags ": lag,
969+ "NLAG ": lag,
968970 "α_hat": fit["params"][0],
969971 "se_α": fit["se"][0],
970972 "β_hat": fit["params"][1],
@@ -974,7 +976,7 @@ def run_mle_by_lag(
974976 }
975977 )
976978
977- table = pd.DataFrame(rows).set_index("n_lags ")
979+ table = pd.DataFrame(rows).set_index("NLAG ")
978980 return table, fits
979981```
980982
@@ -1165,13 +1167,13 @@ def run_unrestricted_var_by_lag(data, lags=(2, 4, 6)):
11651167 fits[lag] = fit
11661168 rows.append(
11671169 {
1168- "n_lags ": lag,
1170+ "NLAG ": lag,
11691171 "loglike": fit["loglike"],
11701172 "n_obs": fit["n_obs"],
11711173 }
11721174 )
11731175
1174- table = pd.DataFrame(rows).set_index("n_lags ")
1176+ table = pd.DataFrame(rows).set_index("NLAG ")
11751177 return table, fits
11761178```
11771179
@@ -1191,7 +1193,7 @@ def restricted_vs_unrestricted_lr(mle_fits, unrestricted_fits, lags=(2, 4, 6)):
11911193 lr = likelihood_ratio_test(fit_restricted=fit_r, fit_unrestricted=fit_u, df_diff=df_diff)
11921194 rows.append(
11931195 {
1194- "n_lags ": lag,
1196+ "NLAG ": lag,
11951197 "lr_stat": lr["lr_stat"],
11961198 "p_value": lr["p_value"],
11971199 "chi2_cdf": lr["chi2_cdf"],
@@ -1200,10 +1202,10 @@ def restricted_vs_unrestricted_lr(mle_fits, unrestricted_fits, lags=(2, 4, 6)):
12001202 }
12011203 )
12021204
1203- return pd.DataFrame(rows).set_index("n_lags ")
1205+ return pd.DataFrame(rows).set_index("NLAG ")
12041206```
12051207
1206- ## Predictability and the $R^2$ restriction
1208+ ## Predictability and the R-squared restriction
12071209
12081210Section II of {cite: t }` hansen1983stochastic ` emphasizes an implication of the restricted system for return predictability.
12091211
@@ -1603,9 +1605,9 @@ for lag in lags:
16031605 unrestricted_fit=unres_fits[lag],
16041606 n_lags=lag,
16051607 )
1606- pred_rows.append({"n_lags ": lag, **metrics})
1608+ pred_rows.append({"NLAG ": lag, **metrics})
16071609
1608- pred_df = pd.DataFrame(pred_rows).set_index("n_lags ")
1610+ pred_df = pd.DataFrame(pred_rows).set_index("NLAG ")
16091611pred_pretty = pred_df[
16101612 [
16111613 "alpha_hat",
@@ -1732,9 +1734,9 @@ for lag in lags:
17321734 unrestricted_fit=tbill_unres_fits[lag],
17331735 n_lags=lag,
17341736 )
1735- tbill_pred_rows.append({"n_lags ": lag, **metrics})
1737+ tbill_pred_rows.append({"NLAG ": lag, **metrics})
17361738
1737- tbill_pred_df = pd.DataFrame(tbill_pred_rows).set_index("n_lags ")
1739+ tbill_pred_df = pd.DataFrame(tbill_pred_rows).set_index("NLAG ")
17381740tbill_pred_pretty = tbill_pred_df[
17391741 [
17401742 "alpha_hat",
@@ -1798,7 +1800,7 @@ Why does the LR test not reject the model for stocks?
17981800
17991801As we hinted earlier, one reason may be limited test power when return predictability is small (as reflected in the low $R_R^2$ for stocks).
18001802
1801- When aggregate stock returns are nearly unpredictable ($R_R^2 \approx 0.02$–$0.06$ in Table 1 of {cite : t } ` hansen1983stochastic ` ) , there is almost no predictable variation to constrain.
1803+ When aggregate stock returns are nearly unpredictable, there is almost no predictable variation to constrain.
18021804
18031805## Residual diagnostics
18041806
0 commit comments