{ "cells": [ { "cell_type": "markdown", "metadata": { "pycharm": { "name": "#%% md\n" } }, "source": [ "## Linear Regression: Model Estimation\n", "\n", "**Functions**\n", "\n", "`sm.OLS`\n", "\n", "### Exercise 32\n", "Use the OLS function to estimate the coefficients of the Fama-French portfolios (monthly data) on the\n", "market, size and value factors. Include a constant in the regressions. Use only the four\n", "extremum portfolios – that is the 1-1, 1-5, 5-1 and 5-5 portfolios. Estimate the model with\n", "homoskedastic errors and with White's covariance estimator." ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "execution": { "iopub.execute_input": "2021-09-22T10:07:16.072021Z", "iopub.status.busy": "2021-09-22T10:07:16.072021Z", "iopub.status.idle": "2021-09-22T10:07:16.758021Z", "shell.execute_reply": "2021-09-22T10:07:16.757024Z" }, "pycharm": { "is_executing": false, "name": "#%%\n" } }, "outputs": [], "source": [ "import pandas as pd\n", "\n", "ff = pd.read_hdf(\"data/ff.h5\", \"ff\")\n", "ff.head()\n", "\n", "factors = ff.iloc[:, :3]\n", "portfolios = ff.iloc[:, 4:]\n", "portfolios = portfolios[[\"SMALL LoBM\", \"SMALL HiBM\", \"BIG LoBM\", \"BIG HiBM\"]]" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "execution": { "iopub.execute_input": "2021-09-22T10:07:16.760021Z", "iopub.status.busy": "2021-09-22T10:07:16.760021Z", "iopub.status.idle": "2021-09-22T10:07:17.646021Z", "shell.execute_reply": "2021-09-22T10:07:17.646021Z" }, "pycharm": { "is_executing": false, "name": "#%%\n" } }, "outputs": [], "source": [ "import statsmodels.api as sm\n", "\n", "factors = sm.add_constant(factors)\n", "all_results = {}\n", "homosk_results = {}" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "execution": { "iopub.execute_input": "2021-09-22T10:07:17.650021Z", "iopub.status.busy": "2021-09-22T10:07:17.649020Z", "iopub.status.idle": "2021-09-22T10:07:17.677021Z", "shell.execute_reply": "2021-09-22T10:07:17.677021Z" }, "pycharm": { "is_executing": false, "name": "#%%\n" } }, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", " \n", "\n", "\n", " \n", "\n", "\n", " \n", "\n", "\n", " \n", "\n", "\n", " \n", "\n", "\n", " \n", "\n", "\n", " \n", "\n", "\n", " \n", "\n", "\n", " \n", "\n", "
OLS Regression Results
Dep. Variable: SMALL LoBM R-squared: 0.655
Model: OLS Adj. R-squared: 0.654
Method: Least Squares F-statistic: 180.8
Date: Wed, 22 Sep 2021 Prob (F-statistic): 1.77e-95
Time: 11:07:17 Log-Likelihood: -3776.8
No. Observations: 1117 AIC: 7562.
Df Residuals: 1113 BIC: 7582.
Df Model: 3
Covariance Type: HC0
\n", "\n", "\n", " \n", "\n", "\n", " \n", "\n", "\n", " \n", "\n", "\n", " \n", "\n", "\n", " \n", "\n", "
coef std err z P>|z| [0.025 0.975]
const -0.4355 0.172 -2.526 0.012 -0.773 -0.098
Mkt-RF 1.2832 0.119 10.766 0.000 1.050 1.517
SMB 1.4336 0.177 8.120 0.000 1.088 1.780
HML 0.4214 0.274 1.536 0.125 -0.116 0.959
\n", "\n", "\n", " \n", "\n", "\n", " \n", "\n", "\n", " \n", "\n", "\n", " \n", "\n", "
Omnibus: 896.514 Durbin-Watson: 2.065
Prob(Omnibus): 0.000 Jarque-Bera (JB): 102194.780
Skew: 2.973 Prob(JB): 0.00
Kurtosis: 49.480 Cond. No. 5.68


Notes:
[1] Standard Errors are heteroscedasticity robust (HC0)" ], "text/plain": [ "\n", "\"\"\"\n", " OLS Regression Results \n", "==============================================================================\n", "Dep. Variable: SMALL LoBM R-squared: 0.655\n", "Model: OLS Adj. R-squared: 0.654\n", "Method: Least Squares F-statistic: 180.8\n", "Date: Wed, 22 Sep 2021 Prob (F-statistic): 1.77e-95\n", "Time: 11:07:17 Log-Likelihood: -3776.8\n", "No. Observations: 1117 AIC: 7562.\n", "Df Residuals: 1113 BIC: 7582.\n", "Df Model: 3 \n", "Covariance Type: HC0 \n", "==============================================================================\n", " coef std err z P>|z| [0.025 0.975]\n", "------------------------------------------------------------------------------\n", "const -0.4355 0.172 -2.526 0.012 -0.773 -0.098\n", "Mkt-RF 1.2832 0.119 10.766 0.000 1.050 1.517\n", "SMB 1.4336 0.177 8.120 0.000 1.088 1.780\n", "HML 0.4214 0.274 1.536 0.125 -0.116 0.959\n", "==============================================================================\n", "Omnibus: 896.514 Durbin-Watson: 2.065\n", "Prob(Omnibus): 0.000 Jarque-Bera (JB): 102194.780\n", "Skew: 2.973 Prob(JB): 0.00\n", "Kurtosis: 49.480 Cond. No. 5.68\n", "==============================================================================\n", "\n", "Notes:\n", "[1] Standard Errors are heteroscedasticity robust (HC0)\n", "\"\"\"" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mod = sm.OLS(portfolios[\"SMALL LoBM\"], factors)\n", "res = mod.fit(cov_type=\"HC0\")\n", "all_results[\"SMALL LoBM\"] = res\n", "homosk_results[\"SMALL LoBM\"] = sm.OLS(portfolios[\"SMALL LoBM\"], factors).fit()\n", "res.summary()" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "execution": { "iopub.execute_input": "2021-09-22T10:07:17.680021Z", "iopub.status.busy": "2021-09-22T10:07:17.680021Z", "iopub.status.idle": "2021-09-22T10:07:17.693021Z", "shell.execute_reply": "2021-09-22T10:07:17.693021Z" }, "pycharm": { "is_executing": false, "name": "#%%\n" } }, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", " \n", "\n", "\n", " \n", "\n", "\n", " \n", "\n", "\n", " \n", "\n", "\n", " \n", "\n", "\n", " \n", "\n", "\n", " \n", "\n", "\n", " \n", "\n", "\n", " \n", "\n", "
OLS Regression Results
Dep. Variable: SMALL HiBM R-squared: 0.939
Model: OLS Adj. R-squared: 0.938
Method: Least Squares F-statistic: 941.0
Date: Wed, 22 Sep 2021 Prob (F-statistic): 1.19e-304
Time: 11:07:17 Log-Likelihood: -2506.2
No. Observations: 1117 AIC: 5020.
Df Residuals: 1113 BIC: 5041.
Df Model: 3
Covariance Type: HC0
\n", "\n", "\n", " \n", "\n", "\n", " \n", "\n", "\n", " \n", "\n", "\n", " \n", "\n", "\n", " \n", "\n", "
coef std err z P>|z| [0.025 0.975]
const 0.3696 0.062 6.008 0.000 0.249 0.490
Mkt-RF 0.9830 0.024 40.929 0.000 0.936 1.030
SMB 1.3001 0.065 20.068 0.000 1.173 1.427
HML 0.9124 0.058 15.624 0.000 0.798 1.027
\n", "\n", "\n", " \n", "\n", "\n", " \n", "\n", "\n", " \n", "\n", "\n", " \n", "\n", "
Omnibus: 589.467 Durbin-Watson: 2.272
Prob(Omnibus): 0.000 Jarque-Bera (JB): 15321.552
Skew: 1.888 Prob(JB): 0.00
Kurtosis: 20.747 Cond. No. 5.68


Notes:
[1] Standard Errors are heteroscedasticity robust (HC0)" ], "text/plain": [ "\n", "\"\"\"\n", " OLS Regression Results \n", "==============================================================================\n", "Dep. Variable: SMALL HiBM R-squared: 0.939\n", "Model: OLS Adj. R-squared: 0.938\n", "Method: Least Squares F-statistic: 941.0\n", "Date: Wed, 22 Sep 2021 Prob (F-statistic): 1.19e-304\n", "Time: 11:07:17 Log-Likelihood: -2506.2\n", "No. Observations: 1117 AIC: 5020.\n", "Df Residuals: 1113 BIC: 5041.\n", "Df Model: 3 \n", "Covariance Type: HC0 \n", "==============================================================================\n", " coef std err z P>|z| [0.025 0.975]\n", "------------------------------------------------------------------------------\n", "const 0.3696 0.062 6.008 0.000 0.249 0.490\n", "Mkt-RF 0.9830 0.024 40.929 0.000 0.936 1.030\n", "SMB 1.3001 0.065 20.068 0.000 1.173 1.427\n", "HML 0.9124 0.058 15.624 0.000 0.798 1.027\n", "==============================================================================\n", "Omnibus: 589.467 Durbin-Watson: 2.272\n", "Prob(Omnibus): 0.000 Jarque-Bera (JB): 15321.552\n", "Skew: 1.888 Prob(JB): 0.00\n", "Kurtosis: 20.747 Cond. No. 5.68\n", "==============================================================================\n", "\n", "Notes:\n", "[1] Standard Errors are heteroscedasticity robust (HC0)\n", "\"\"\"" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mod = sm.OLS(portfolios[\"SMALL HiBM\"], factors)\n", "res = mod.fit(cov_type=\"HC0\")\n", "all_results[\"SMALL HiBM\"] = res\n", "homosk_results[\"SMALL HiBM\"] = sm.OLS(portfolios[\"SMALL HiBM\"], factors).fit()\n", "res.summary()" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "execution": { "iopub.execute_input": "2021-09-22T10:07:17.696021Z", "iopub.status.busy": "2021-09-22T10:07:17.696021Z", "iopub.status.idle": "2021-09-22T10:07:17.709023Z", "shell.execute_reply": "2021-09-22T10:07:17.709023Z" }, "pycharm": { "is_executing": false, "name": "#%%\n" } }, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", " \n", "\n", "\n", " \n", "\n", "\n", " \n", "\n", "\n", " \n", "\n", "\n", " \n", "\n", "\n", " \n", "\n", "\n", " \n", "\n", "\n", " \n", "\n", "\n", " \n", "\n", "
OLS Regression Results
Dep. Variable: BIG LoBM R-squared: 0.952
Model: OLS Adj. R-squared: 0.952
Method: Least Squares F-statistic: 4050.
Date: Wed, 22 Sep 2021 Prob (F-statistic): 0.00
Time: 11:07:17 Log-Likelihood: -1758.6
No. Observations: 1117 AIC: 3525.
Df Residuals: 1113 BIC: 3545.
Df Model: 3
Covariance Type: HC0
\n", "\n", "\n", " \n", "\n", "\n", " \n", "\n", "\n", " \n", "\n", "\n", " \n", "\n", "\n", " \n", "\n", "
coef std err z P>|z| [0.025 0.975]
const 0.3594 0.035 10.270 0.000 0.291 0.428
Mkt-RF 1.0229 0.009 109.366 0.000 1.005 1.041
SMB -0.1485 0.023 -6.524 0.000 -0.193 -0.104
HML -0.2629 0.016 -16.645 0.000 -0.294 -0.232
\n", "\n", "\n", " \n", "\n", "\n", " \n", "\n", "\n", " \n", "\n", "\n", " \n", "\n", "
Omnibus: 109.852 Durbin-Watson: 1.791
Prob(Omnibus): 0.000 Jarque-Bera (JB): 248.017
Skew: 0.578 Prob(JB): 1.39e-54
Kurtosis: 4.998 Cond. No. 5.68


Notes:
[1] Standard Errors are heteroscedasticity robust (HC0)" ], "text/plain": [ "\n", "\"\"\"\n", " OLS Regression Results \n", "==============================================================================\n", "Dep. Variable: BIG LoBM R-squared: 0.952\n", "Model: OLS Adj. R-squared: 0.952\n", "Method: Least Squares F-statistic: 4050.\n", "Date: Wed, 22 Sep 2021 Prob (F-statistic): 0.00\n", "Time: 11:07:17 Log-Likelihood: -1758.6\n", "No. Observations: 1117 AIC: 3525.\n", "Df Residuals: 1113 BIC: 3545.\n", "Df Model: 3 \n", "Covariance Type: HC0 \n", "==============================================================================\n", " coef std err z P>|z| [0.025 0.975]\n", "------------------------------------------------------------------------------\n", "const 0.3594 0.035 10.270 0.000 0.291 0.428\n", "Mkt-RF 1.0229 0.009 109.366 0.000 1.005 1.041\n", "SMB -0.1485 0.023 -6.524 0.000 -0.193 -0.104\n", "HML -0.2629 0.016 -16.645 0.000 -0.294 -0.232\n", "==============================================================================\n", "Omnibus: 109.852 Durbin-Watson: 1.791\n", "Prob(Omnibus): 0.000 Jarque-Bera (JB): 248.017\n", "Skew: 0.578 Prob(JB): 1.39e-54\n", "Kurtosis: 4.998 Cond. No. 5.68\n", "==============================================================================\n", "\n", "Notes:\n", "[1] Standard Errors are heteroscedasticity robust (HC0)\n", "\"\"\"" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mod = sm.OLS(portfolios[\"BIG LoBM\"], factors)\n", "res = mod.fit(cov_type=\"HC0\")\n", "all_results[\"BIG LoBM\"] = res\n", "homosk_results[\"BIG LoBM\"] = sm.OLS(portfolios[\"BIG LoBM\"], factors).fit()\n", "res.summary()" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "execution": { "iopub.execute_input": "2021-09-22T10:07:17.712021Z", "iopub.status.busy": "2021-09-22T10:07:17.712021Z", "iopub.status.idle": "2021-09-22T10:07:17.725021Z", "shell.execute_reply": "2021-09-22T10:07:17.725021Z" }, "pycharm": { "is_executing": false, "name": "#%%\n" } }, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", " \n", "\n", "\n", " \n", "\n", "\n", " \n", "\n", "\n", " \n", "\n", "\n", " \n", "\n", "\n", " \n", "\n", "\n", " \n", "\n", "\n", " \n", "\n", "\n", " \n", "\n", "
OLS Regression Results
Dep. Variable: BIG HiBM R-squared: 0.838
Model: OLS Adj. R-squared: 0.838
Method: Least Squares F-statistic: 376.3
Date: Wed, 22 Sep 2021 Prob (F-statistic): 1.04e-168
Time: 11:07:17 Log-Likelihood: -2956.0
No. Observations: 1117 AIC: 5920.
Df Residuals: 1113 BIC: 5940.
Df Model: 3
Covariance Type: HC0
\n", "\n", "\n", " \n", "\n", "\n", " \n", "\n", "\n", " \n", "\n", "\n", " \n", "\n", "\n", " \n", "\n", "
coef std err z P>|z| [0.025 0.975]
const 0.1042 0.103 1.016 0.309 -0.097 0.305
Mkt-RF 1.1823 0.038 31.058 0.000 1.108 1.257
SMB -0.1573 0.069 -2.268 0.023 -0.293 -0.021
HML 1.0162 0.073 13.961 0.000 0.874 1.159
\n", "\n", "\n", " \n", "\n", "\n", " \n", "\n", "\n", " \n", "\n", "\n", " \n", "\n", "
Omnibus: 436.752 Durbin-Watson: 1.808
Prob(Omnibus): 0.000 Jarque-Bera (JB): 9887.813
Skew: 1.257 Prob(JB): 0.00
Kurtosis: 17.357 Cond. No. 5.68


Notes:
[1] Standard Errors are heteroscedasticity robust (HC0)" ], "text/plain": [ "\n", "\"\"\"\n", " OLS Regression Results \n", "==============================================================================\n", "Dep. Variable: BIG HiBM R-squared: 0.838\n", "Model: OLS Adj. R-squared: 0.838\n", "Method: Least Squares F-statistic: 376.3\n", "Date: Wed, 22 Sep 2021 Prob (F-statistic): 1.04e-168\n", "Time: 11:07:17 Log-Likelihood: -2956.0\n", "No. Observations: 1117 AIC: 5920.\n", "Df Residuals: 1113 BIC: 5940.\n", "Df Model: 3 \n", "Covariance Type: HC0 \n", "==============================================================================\n", " coef std err z P>|z| [0.025 0.975]\n", "------------------------------------------------------------------------------\n", "const 0.1042 0.103 1.016 0.309 -0.097 0.305\n", "Mkt-RF 1.1823 0.038 31.058 0.000 1.108 1.257\n", "SMB -0.1573 0.069 -2.268 0.023 -0.293 -0.021\n", "HML 1.0162 0.073 13.961 0.000 0.874 1.159\n", "==============================================================================\n", "Omnibus: 436.752 Durbin-Watson: 1.808\n", "Prob(Omnibus): 0.000 Jarque-Bera (JB): 9887.813\n", "Skew: 1.257 Prob(JB): 0.00\n", "Kurtosis: 17.357 Cond. No. 5.68\n", "==============================================================================\n", "\n", "Notes:\n", "[1] Standard Errors are heteroscedasticity robust (HC0)\n", "\"\"\"" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mod = sm.OLS(portfolios[\"BIG HiBM\"], factors)\n", "res = mod.fit(cov_type=\"HC0\")\n", "all_results[\"BIG HiBM\"] = res\n", "homosk_results[\"BIG HiBM\"] = sm.OLS(portfolios[\"BIG HiBM\"], factors).fit()\n", "res.summary()" ] }, { "cell_type": "markdown", "metadata": { "pycharm": { "name": "#%% md\n" } }, "source": [ "### Exercise 33\n", "Are the parameter standard errors similar using the two covariance estimators?\n", "If not, what does this mean? " ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "execution": { "iopub.execute_input": "2021-09-22T10:07:17.729020Z", "iopub.status.busy": "2021-09-22T10:07:17.728021Z", "iopub.status.idle": "2021-09-22T10:07:17.757021Z", "shell.execute_reply": "2021-09-22T10:07:17.757021Z" }, "pycharm": { "is_executing": false, "name": "#%%\n" } }, "outputs": [ { "data": { "text/html": [ "SMALL LoBM" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
HomoskWhite
const0.2155690.172414
Mkt-RF0.0431670.119187
SMB0.0707970.176554
HML0.0632350.274367
\n", "
" ], "text/plain": [ " Homosk White\n", "const 0.215569 0.172414\n", "Mkt-RF 0.043167 0.119187\n", "SMB 0.070797 0.176554\n", "HML 0.063235 0.274367" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "SMALL HiBM" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
HomoskWhite
const0.0691180.061514
Mkt-RF0.0138410.024017
SMB0.0226990.064785
HML0.0202750.058401
\n", "
" ], "text/plain": [ " Homosk White\n", "const 0.069118 0.061514\n", "Mkt-RF 0.013841 0.024017\n", "SMB 0.022699 0.064785\n", "HML 0.020275 0.058401" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "BIG LoBM" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
HomoskWhite
const0.0353910.034997
Mkt-RF0.0070870.009353
SMB0.0116230.022765
HML0.0103820.015797
\n", "
" ], "text/plain": [ " Homosk White\n", "const 0.035391 0.034997\n", "Mkt-RF 0.007087 0.009353\n", "SMB 0.011623 0.022765\n", "HML 0.010382 0.015797" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "BIG HiBM" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
HomoskWhite
const0.1033840.102525
Mkt-RF0.0207020.038067
SMB0.0339530.069341
HML0.0303270.072789
\n", "
" ], "text/plain": [ " Homosk White\n", "const 0.103384 0.102525\n", "Mkt-RF 0.020702 0.038067\n", "SMB 0.033953 0.069341\n", "HML 0.030327 0.072789" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "from IPython.display import HTML, display\n", "\n", "for key in all_results:\n", " white_res = all_results[key]\n", " homosk_res = homosk_results[key]\n", " std_err = pd.DataFrame({\"Homosk\": homosk_res.bse, \"White\": white_res.bse})\n", " display(HTML(key))\n", " display(std_err)" ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "execution": { "iopub.execute_input": "2021-09-22T10:07:17.761021Z", "iopub.status.busy": "2021-09-22T10:07:17.760021Z", "iopub.status.idle": "2021-09-22T10:07:17.788021Z", "shell.execute_reply": "2021-09-22T10:07:17.788021Z" }, "pycharm": { "is_executing": false, "name": "#%%\n" } }, "outputs": [ { "data": { "text/html": [ "SMALL LoBM" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
HomoskWhite
const-2.020037-2.525647
Mkt-RF29.72519110.765843
SMB20.2488668.119638
HML6.6640801.535905
\n", "
" ], "text/plain": [ " Homosk White\n", "const -2.020037 -2.525647\n", "Mkt-RF 29.725191 10.765843\n", "SMB 20.248866 8.119638\n", "HML 6.664080 1.535905" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "SMALL HiBM" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
HomoskWhite
const5.3467476.007648
Mkt-RF71.02264140.929483
SMB57.27490920.068010
HML45.00320115.623556
\n", "
" ], "text/plain": [ " Homosk White\n", "const 5.346747 6.007648\n", "Mkt-RF 71.022641 40.929483\n", "SMB 57.274909 20.068010\n", "HML 45.003201 15.623556" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "BIG LoBM" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
HomoskWhite
const10.15547410.269912
Mkt-RF144.336719109.365862
SMB-12.777091-6.523564
HML-25.327247-16.645120
\n", "
" ], "text/plain": [ " Homosk White\n", "const 10.155474 10.269912\n", "Mkt-RF 144.336719 109.365862\n", "SMB -12.777091 -6.523564\n", "HML -25.327247 -16.645120" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "BIG HiBM" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
HomoskWhite
const1.0079161.016364
Mkt-RF57.10770231.057592
SMB-4.632601-2.268375
HML33.50820413.960789
\n", "
" ], "text/plain": [ " Homosk White\n", "const 1.007916 1.016364\n", "Mkt-RF 57.107702 31.057592\n", "SMB -4.632601 -2.268375\n", "HML 33.508204 13.960789" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "for key in all_results:\n", " white_res = all_results[key]\n", " homosk_res = homosk_results[key]\n", " t_stats = pd.DataFrame({\"Homosk\": homosk_res.tvalues, \"White\": white_res.tvalues})\n", " display(HTML(key))\n", " display(t_stats)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Exercise 34\n", "How much of the variation is explained by these three regressors?" ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "execution": { "iopub.execute_input": "2021-09-22T10:07:17.793020Z", "iopub.status.busy": "2021-09-22T10:07:17.792020Z", "iopub.status.idle": "2021-09-22T10:07:17.804021Z", "shell.execute_reply": "2021-09-22T10:07:17.804021Z" }, "pycharm": { "is_executing": false, "name": "#%%\n" } }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
R2
SMALL LoBM0.654851
SMALL HiBM0.938606
BIG LoBM0.951723
BIG HiBM0.838409
\n", "
" ], "text/plain": [ " R2\n", "SMALL LoBM 0.654851\n", "SMALL HiBM 0.938606\n", "BIG LoBM 0.951723\n", "BIG HiBM 0.838409" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "rsquare = {}\n", "for key in all_results:\n", " rsquare[key] = all_results[key].rsquared\n", "pd.Series(rsquare, name=\"R2\").to_frame()" ] }, { "cell_type": "code", "execution_count": 10, "metadata": { "execution": { "iopub.execute_input": "2021-09-22T10:07:17.808021Z", "iopub.status.busy": "2021-09-22T10:07:17.807021Z", "iopub.status.idle": "2021-09-22T10:07:17.819021Z", "shell.execute_reply": "2021-09-22T10:07:17.819021Z" }, "pycharm": { "is_executing": false, "name": "#%%\n" }, "tags": [] }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
R2
SMALL LoBM0.508956
SMALL HiBM0.629589
BIG LoBM0.915187
BIG HiBM0.674243
\n", "
" ], "text/plain": [ " R2\n", "SMALL LoBM 0.508956\n", "SMALL HiBM 0.629589\n", "BIG LoBM 0.915187\n", "BIG HiBM 0.674243" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "capm_factor = factors.iloc[:, :2]\n", "for key in portfolios:\n", " res = sm.OLS(portfolios[key], capm_factor).fit()\n", " rsquare[key] = res.rsquared\n", "pd.Series(rsquare, name=\"R2\").to_frame()" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.9.6" }, "pycharm": { "stem_cell": { "cell_type": "raw", "metadata": { "collapsed": false }, "source": [] } } }, "nbformat": 4, "nbformat_minor": 4 }