{
"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",
"OLS Regression Results\n",
"\n",
" Dep. Variable: | SMALL LoBM | R-squared: | 0.655 | \n",
"
\n",
"\n",
" Model: | OLS | Adj. R-squared: | 0.654 | \n",
"
\n",
"\n",
" Method: | Least Squares | F-statistic: | 180.8 | \n",
"
\n",
"\n",
" Date: | Wed, 22 Sep 2021 | Prob (F-statistic): | 1.77e-95 | \n",
"
\n",
"\n",
" Time: | 11:07:17 | Log-Likelihood: | -3776.8 | \n",
"
\n",
"\n",
" No. Observations: | 1117 | AIC: | 7562. | \n",
"
\n",
"\n",
" Df Residuals: | 1113 | BIC: | 7582. | \n",
"
\n",
"\n",
" Df Model: | 3 | | | \n",
"
\n",
"\n",
" Covariance Type: | HC0 | | | \n",
"
\n",
"
\n",
"\n",
"\n",
" | coef | std err | z | P>|z| | [0.025 | 0.975] | \n",
"
\n",
"\n",
" const | -0.4355 | 0.172 | -2.526 | 0.012 | -0.773 | -0.098 | \n",
"
\n",
"\n",
" Mkt-RF | 1.2832 | 0.119 | 10.766 | 0.000 | 1.050 | 1.517 | \n",
"
\n",
"\n",
" SMB | 1.4336 | 0.177 | 8.120 | 0.000 | 1.088 | 1.780 | \n",
"
\n",
"\n",
" HML | 0.4214 | 0.274 | 1.536 | 0.125 | -0.116 | 0.959 | \n",
"
\n",
"
\n",
"\n",
"\n",
" Omnibus: | 896.514 | Durbin-Watson: | 2.065 | \n",
"
\n",
"\n",
" Prob(Omnibus): | 0.000 | Jarque-Bera (JB): | 102194.780 | \n",
"
\n",
"\n",
" Skew: | 2.973 | Prob(JB): | 0.00 | \n",
"
\n",
"\n",
" Kurtosis: | 49.480 | Cond. No. | 5.68 | \n",
"
\n",
"
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",
"OLS Regression Results\n",
"\n",
" Dep. Variable: | SMALL HiBM | R-squared: | 0.939 | \n",
"
\n",
"\n",
" Model: | OLS | Adj. R-squared: | 0.938 | \n",
"
\n",
"\n",
" Method: | Least Squares | F-statistic: | 941.0 | \n",
"
\n",
"\n",
" Date: | Wed, 22 Sep 2021 | Prob (F-statistic): | 1.19e-304 | \n",
"
\n",
"\n",
" Time: | 11:07:17 | Log-Likelihood: | -2506.2 | \n",
"
\n",
"\n",
" No. Observations: | 1117 | AIC: | 5020. | \n",
"
\n",
"\n",
" Df Residuals: | 1113 | BIC: | 5041. | \n",
"
\n",
"\n",
" Df Model: | 3 | | | \n",
"
\n",
"\n",
" Covariance Type: | HC0 | | | \n",
"
\n",
"
\n",
"\n",
"\n",
" | coef | std err | z | P>|z| | [0.025 | 0.975] | \n",
"
\n",
"\n",
" const | 0.3696 | 0.062 | 6.008 | 0.000 | 0.249 | 0.490 | \n",
"
\n",
"\n",
" Mkt-RF | 0.9830 | 0.024 | 40.929 | 0.000 | 0.936 | 1.030 | \n",
"
\n",
"\n",
" SMB | 1.3001 | 0.065 | 20.068 | 0.000 | 1.173 | 1.427 | \n",
"
\n",
"\n",
" HML | 0.9124 | 0.058 | 15.624 | 0.000 | 0.798 | 1.027 | \n",
"
\n",
"
\n",
"\n",
"\n",
" Omnibus: | 589.467 | Durbin-Watson: | 2.272 | \n",
"
\n",
"\n",
" Prob(Omnibus): | 0.000 | Jarque-Bera (JB): | 15321.552 | \n",
"
\n",
"\n",
" Skew: | 1.888 | Prob(JB): | 0.00 | \n",
"
\n",
"\n",
" Kurtosis: | 20.747 | Cond. No. | 5.68 | \n",
"
\n",
"
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",
"OLS Regression Results\n",
"\n",
" Dep. Variable: | BIG LoBM | R-squared: | 0.952 | \n",
"
\n",
"\n",
" Model: | OLS | Adj. R-squared: | 0.952 | \n",
"
\n",
"\n",
" Method: | Least Squares | F-statistic: | 4050. | \n",
"
\n",
"\n",
" Date: | Wed, 22 Sep 2021 | Prob (F-statistic): | 0.00 | \n",
"
\n",
"\n",
" Time: | 11:07:17 | Log-Likelihood: | -1758.6 | \n",
"
\n",
"\n",
" No. Observations: | 1117 | AIC: | 3525. | \n",
"
\n",
"\n",
" Df Residuals: | 1113 | BIC: | 3545. | \n",
"
\n",
"\n",
" Df Model: | 3 | | | \n",
"
\n",
"\n",
" Covariance Type: | HC0 | | | \n",
"
\n",
"
\n",
"\n",
"\n",
" | coef | std err | z | P>|z| | [0.025 | 0.975] | \n",
"
\n",
"\n",
" const | 0.3594 | 0.035 | 10.270 | 0.000 | 0.291 | 0.428 | \n",
"
\n",
"\n",
" Mkt-RF | 1.0229 | 0.009 | 109.366 | 0.000 | 1.005 | 1.041 | \n",
"
\n",
"\n",
" SMB | -0.1485 | 0.023 | -6.524 | 0.000 | -0.193 | -0.104 | \n",
"
\n",
"\n",
" HML | -0.2629 | 0.016 | -16.645 | 0.000 | -0.294 | -0.232 | \n",
"
\n",
"
\n",
"\n",
"\n",
" Omnibus: | 109.852 | Durbin-Watson: | 1.791 | \n",
"
\n",
"\n",
" Prob(Omnibus): | 0.000 | Jarque-Bera (JB): | 248.017 | \n",
"
\n",
"\n",
" Skew: | 0.578 | Prob(JB): | 1.39e-54 | \n",
"
\n",
"\n",
" Kurtosis: | 4.998 | Cond. No. | 5.68 | \n",
"
\n",
"
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",
"OLS Regression Results\n",
"\n",
" Dep. Variable: | BIG HiBM | R-squared: | 0.838 | \n",
"
\n",
"\n",
" Model: | OLS | Adj. R-squared: | 0.838 | \n",
"
\n",
"\n",
" Method: | Least Squares | F-statistic: | 376.3 | \n",
"
\n",
"\n",
" Date: | Wed, 22 Sep 2021 | Prob (F-statistic): | 1.04e-168 | \n",
"
\n",
"\n",
" Time: | 11:07:17 | Log-Likelihood: | -2956.0 | \n",
"
\n",
"\n",
" No. Observations: | 1117 | AIC: | 5920. | \n",
"
\n",
"\n",
" Df Residuals: | 1113 | BIC: | 5940. | \n",
"
\n",
"\n",
" Df Model: | 3 | | | \n",
"
\n",
"\n",
" Covariance Type: | HC0 | | | \n",
"
\n",
"
\n",
"\n",
"\n",
" | coef | std err | z | P>|z| | [0.025 | 0.975] | \n",
"
\n",
"\n",
" const | 0.1042 | 0.103 | 1.016 | 0.309 | -0.097 | 0.305 | \n",
"
\n",
"\n",
" Mkt-RF | 1.1823 | 0.038 | 31.058 | 0.000 | 1.108 | 1.257 | \n",
"
\n",
"\n",
" SMB | -0.1573 | 0.069 | -2.268 | 0.023 | -0.293 | -0.021 | \n",
"
\n",
"\n",
" HML | 1.0162 | 0.073 | 13.961 | 0.000 | 0.874 | 1.159 | \n",
"
\n",
"
\n",
"\n",
"\n",
" Omnibus: | 436.752 | Durbin-Watson: | 1.808 | \n",
"
\n",
"\n",
" Prob(Omnibus): | 0.000 | Jarque-Bera (JB): | 9887.813 | \n",
"
\n",
"\n",
" Skew: | 1.257 | Prob(JB): | 0.00 | \n",
"
\n",
"\n",
" Kurtosis: | 17.357 | Cond. No. | 5.68 | \n",
"
\n",
"
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",
" Homosk | \n",
" White | \n",
"
\n",
" \n",
" \n",
" \n",
" const | \n",
" 0.215569 | \n",
" 0.172414 | \n",
"
\n",
" \n",
" Mkt-RF | \n",
" 0.043167 | \n",
" 0.119187 | \n",
"
\n",
" \n",
" SMB | \n",
" 0.070797 | \n",
" 0.176554 | \n",
"
\n",
" \n",
" HML | \n",
" 0.063235 | \n",
" 0.274367 | \n",
"
\n",
" \n",
"
\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",
" Homosk | \n",
" White | \n",
"
\n",
" \n",
" \n",
" \n",
" const | \n",
" 0.069118 | \n",
" 0.061514 | \n",
"
\n",
" \n",
" Mkt-RF | \n",
" 0.013841 | \n",
" 0.024017 | \n",
"
\n",
" \n",
" SMB | \n",
" 0.022699 | \n",
" 0.064785 | \n",
"
\n",
" \n",
" HML | \n",
" 0.020275 | \n",
" 0.058401 | \n",
"
\n",
" \n",
"
\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",
" Homosk | \n",
" White | \n",
"
\n",
" \n",
" \n",
" \n",
" const | \n",
" 0.035391 | \n",
" 0.034997 | \n",
"
\n",
" \n",
" Mkt-RF | \n",
" 0.007087 | \n",
" 0.009353 | \n",
"
\n",
" \n",
" SMB | \n",
" 0.011623 | \n",
" 0.022765 | \n",
"
\n",
" \n",
" HML | \n",
" 0.010382 | \n",
" 0.015797 | \n",
"
\n",
" \n",
"
\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",
" Homosk | \n",
" White | \n",
"
\n",
" \n",
" \n",
" \n",
" const | \n",
" 0.103384 | \n",
" 0.102525 | \n",
"
\n",
" \n",
" Mkt-RF | \n",
" 0.020702 | \n",
" 0.038067 | \n",
"
\n",
" \n",
" SMB | \n",
" 0.033953 | \n",
" 0.069341 | \n",
"
\n",
" \n",
" HML | \n",
" 0.030327 | \n",
" 0.072789 | \n",
"
\n",
" \n",
"
\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",
" Homosk | \n",
" White | \n",
"
\n",
" \n",
" \n",
" \n",
" const | \n",
" -2.020037 | \n",
" -2.525647 | \n",
"
\n",
" \n",
" Mkt-RF | \n",
" 29.725191 | \n",
" 10.765843 | \n",
"
\n",
" \n",
" SMB | \n",
" 20.248866 | \n",
" 8.119638 | \n",
"
\n",
" \n",
" HML | \n",
" 6.664080 | \n",
" 1.535905 | \n",
"
\n",
" \n",
"
\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",
" Homosk | \n",
" White | \n",
"
\n",
" \n",
" \n",
" \n",
" const | \n",
" 5.346747 | \n",
" 6.007648 | \n",
"
\n",
" \n",
" Mkt-RF | \n",
" 71.022641 | \n",
" 40.929483 | \n",
"
\n",
" \n",
" SMB | \n",
" 57.274909 | \n",
" 20.068010 | \n",
"
\n",
" \n",
" HML | \n",
" 45.003201 | \n",
" 15.623556 | \n",
"
\n",
" \n",
"
\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",
" Homosk | \n",
" White | \n",
"
\n",
" \n",
" \n",
" \n",
" const | \n",
" 10.155474 | \n",
" 10.269912 | \n",
"
\n",
" \n",
" Mkt-RF | \n",
" 144.336719 | \n",
" 109.365862 | \n",
"
\n",
" \n",
" SMB | \n",
" -12.777091 | \n",
" -6.523564 | \n",
"
\n",
" \n",
" HML | \n",
" -25.327247 | \n",
" -16.645120 | \n",
"
\n",
" \n",
"
\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",
" Homosk | \n",
" White | \n",
"
\n",
" \n",
" \n",
" \n",
" const | \n",
" 1.007916 | \n",
" 1.016364 | \n",
"
\n",
" \n",
" Mkt-RF | \n",
" 57.107702 | \n",
" 31.057592 | \n",
"
\n",
" \n",
" SMB | \n",
" -4.632601 | \n",
" -2.268375 | \n",
"
\n",
" \n",
" HML | \n",
" 33.508204 | \n",
" 13.960789 | \n",
"
\n",
" \n",
"
\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",
" R2 | \n",
"
\n",
" \n",
" \n",
" \n",
" SMALL LoBM | \n",
" 0.654851 | \n",
"
\n",
" \n",
" SMALL HiBM | \n",
" 0.938606 | \n",
"
\n",
" \n",
" BIG LoBM | \n",
" 0.951723 | \n",
"
\n",
" \n",
" BIG HiBM | \n",
" 0.838409 | \n",
"
\n",
" \n",
"
\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",
" R2 | \n",
"
\n",
" \n",
" \n",
" \n",
" SMALL LoBM | \n",
" 0.508956 | \n",
"
\n",
" \n",
" SMALL HiBM | \n",
" 0.629589 | \n",
"
\n",
" \n",
" BIG LoBM | \n",
" 0.915187 | \n",
"
\n",
" \n",
" BIG HiBM | \n",
" 0.674243 | \n",
"
\n",
" \n",
"
\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
}