{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"pycharm": {
"name": "#%% md\n"
}
},
"source": [
"## ARMA Modeling: Model Selection\n",
"\n",
"**Functions**\n",
"\n",
"`sm.tsa.SARIMAX`\n",
"\n",
"### Exercise 68\n",
"Perform a model selection exercise on the term premium using\n",
"\n",
"1. General-to-Specific\n",
"2. Specific-to-General\n",
"3. Minimizing an Information Criteria\n",
"\n",
"**Note**: Some models, especially if not well specified, may show various warnings. These can be ignored"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"execution": {
"iopub.execute_input": "2021-09-22T10:06:18.192654Z",
"iopub.status.busy": "2021-09-22T10:06:18.192654Z",
"iopub.status.idle": "2021-09-22T10:06:18.864655Z",
"shell.execute_reply": "2021-09-22T10:06:18.864655Z"
},
"pycharm": {
"is_executing": false,
"name": "#%%\n"
}
},
"outputs": [],
"source": [
"import pandas as pd\n",
"\n",
"data = pd.read_hdf(\"data/term-premium.h5\", \"term_premium\")\n",
"term = data[\"TERM\"]"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"execution": {
"iopub.execute_input": "2021-09-22T10:06:18.868655Z",
"iopub.status.busy": "2021-09-22T10:06:18.868655Z",
"iopub.status.idle": "2021-09-22T10:06:33.897816Z",
"shell.execute_reply": "2021-09-22T10:06:33.897816Z"
},
"pycharm": {
"is_executing": false,
"name": "#%%\n"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"AR: 0, MA: 0\n",
"AR: 0, MA: 1\n",
"AR: 0, MA: 2\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"c:\\git\\statsmodels\\statsmodels\\tsa\\statespace\\sarimax.py:978: UserWarning: Non-invertible starting MA parameters found. Using zeros as starting parameters.\n",
" warn('Non-invertible starting MA parameters found.'\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"AR: 0, MA: 3\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"c:\\git\\statsmodels\\statsmodels\\tsa\\statespace\\sarimax.py:978: UserWarning: Non-invertible starting MA parameters found. Using zeros as starting parameters.\n",
" warn('Non-invertible starting MA parameters found.'\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"AR: 0, MA: 4\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"AR: 1, MA: 0\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"AR: 1, MA: 1\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"AR: 1, MA: 2\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"AR: 1, MA: 3\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"AR: 1, MA: 4\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"AR: 2, MA: 0\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"AR: 2, MA: 1\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"AR: 2, MA: 2\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"AR: 2, MA: 3\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"AR: 2, MA: 4\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"AR: 3, MA: 0\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"AR: 3, MA: 1\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"AR: 3, MA: 2\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"c:\\git\\statsmodels\\statsmodels\\tsa\\statespace\\sarimax.py:966: UserWarning: Non-stationary starting autoregressive parameters found. Using zeros as starting parameters.\n",
" warn('Non-stationary starting autoregressive parameters'\n",
"c:\\git\\statsmodels\\statsmodels\\tsa\\statespace\\sarimax.py:978: UserWarning: Non-invertible starting MA parameters found. Using zeros as starting parameters.\n",
" warn('Non-invertible starting MA parameters found.'\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"AR: 3, MA: 3\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"c:\\git\\statsmodels\\statsmodels\\tsa\\statespace\\sarimax.py:966: UserWarning: Non-stationary starting autoregressive parameters found. Using zeros as starting parameters.\n",
" warn('Non-stationary starting autoregressive parameters'\n",
"c:\\git\\statsmodels\\statsmodels\\tsa\\statespace\\sarimax.py:978: UserWarning: Non-invertible starting MA parameters found. Using zeros as starting parameters.\n",
" warn('Non-invertible starting MA parameters found.'\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"c:\\git\\statsmodels\\statsmodels\\base\\model.py:582: ConvergenceWarning: Maximum Likelihood optimization failed to converge. Check mle_retvals\n",
" warnings.warn(\"Maximum Likelihood optimization failed to \"\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"AR: 3, MA: 4\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"c:\\git\\statsmodels\\statsmodels\\base\\model.py:582: ConvergenceWarning: Maximum Likelihood optimization failed to converge. Check mle_retvals\n",
" warnings.warn(\"Maximum Likelihood optimization failed to \"\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"AR: 4, MA: 0\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"AR: 4, MA: 1\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"AR: 4, MA: 2\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"c:\\git\\statsmodels\\statsmodels\\tsa\\statespace\\sarimax.py:966: UserWarning: Non-stationary starting autoregressive parameters found. Using zeros as starting parameters.\n",
" warn('Non-stationary starting autoregressive parameters'\n",
"c:\\git\\statsmodels\\statsmodels\\tsa\\statespace\\sarimax.py:978: UserWarning: Non-invertible starting MA parameters found. Using zeros as starting parameters.\n",
" warn('Non-invertible starting MA parameters found.'\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"c:\\git\\statsmodels\\statsmodels\\base\\model.py:582: ConvergenceWarning: Maximum Likelihood optimization failed to converge. Check mle_retvals\n",
" warnings.warn(\"Maximum Likelihood optimization failed to \"\n",
"c:\\git\\statsmodels\\statsmodels\\tsa\\statespace\\sarimax.py:966: UserWarning: Non-stationary starting autoregressive parameters found. Using zeros as starting parameters.\n",
" warn('Non-stationary starting autoregressive parameters'\n",
"c:\\git\\statsmodels\\statsmodels\\tsa\\statespace\\sarimax.py:978: UserWarning: Non-invertible starting MA parameters found. Using zeros as starting parameters.\n",
" warn('Non-invertible starting MA parameters found.'\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"AR: 4, MA: 3\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"c:\\git\\statsmodels\\statsmodels\\base\\model.py:582: ConvergenceWarning: Maximum Likelihood optimization failed to converge. Check mle_retvals\n",
" warnings.warn(\"Maximum Likelihood optimization failed to \"\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"AR: 4, MA: 4\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"c:\\git\\statsmodels\\statsmodels\\base\\model.py:582: ConvergenceWarning: Maximum Likelihood optimization failed to converge. Check mle_retvals\n",
" warnings.warn(\"Maximum Likelihood optimization failed to \"\n"
]
},
{
"data": {
"text/html": [
"
\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" | \n",
" AIC | \n",
" BIC | \n",
"
\n",
" \n",
" AR | \n",
" MA | \n",
" | \n",
" | \n",
"
\n",
" \n",
" \n",
" \n",
" 0 | \n",
" 0 | \n",
" 2446.502424 | \n",
" 2455.923470 | \n",
"
\n",
" \n",
" 1 | \n",
" 1459.658418 | \n",
" 1473.789987 | \n",
"
\n",
" \n",
" 2 | \n",
" 892.995533 | \n",
" 911.837626 | \n",
"
\n",
" \n",
" 3 | \n",
" 544.132966 | \n",
" 567.685581 | \n",
"
\n",
" \n",
" 4 | \n",
" 378.778704 | \n",
" 407.041842 | \n",
"
\n",
" \n",
" 1 | \n",
" 0 | \n",
" 84.506334 | \n",
" 98.637903 | \n",
"
\n",
" \n",
" 1 | \n",
" -21.530719 | \n",
" -2.688626 | \n",
"
\n",
" \n",
" 2 | \n",
" -24.091152 | \n",
" -0.538537 | \n",
"
\n",
" \n",
" 3 | \n",
" -24.132206 | \n",
" 4.130932 | \n",
"
\n",
" \n",
" 4 | \n",
" -25.328477 | \n",
" 7.645185 | \n",
"
\n",
" \n",
" 2 | \n",
" 0 | \n",
" 3.099523 | \n",
" 21.941616 | \n",
"
\n",
" \n",
" 1 | \n",
" -25.747284 | \n",
" -2.194669 | \n",
"
\n",
" \n",
" 2 | \n",
" -25.623889 | \n",
" 2.639250 | \n",
"
\n",
" \n",
" 3 | \n",
" -23.893953 | \n",
" 9.079709 | \n",
"
\n",
" \n",
" 4 | \n",
" -23.535545 | \n",
" 14.148640 | \n",
"
\n",
" \n",
" 3 | \n",
" 0 | \n",
" -12.832290 | \n",
" 10.720326 | \n",
"
\n",
" \n",
" 1 | \n",
" -25.737191 | \n",
" 2.525948 | \n",
"
\n",
" \n",
" 2 | \n",
" -23.784929 | \n",
" 9.188733 | \n",
"
\n",
" \n",
" 3 | \n",
" -31.136602 | \n",
" 6.547583 | \n",
"
\n",
" \n",
" 4 | \n",
" -31.148575 | \n",
" 11.246133 | \n",
"
\n",
" \n",
" 4 | \n",
" 0 | \n",
" -14.471428 | \n",
" 13.791711 | \n",
"
\n",
" \n",
" 1 | \n",
" -23.854585 | \n",
" 9.119077 | \n",
"
\n",
" \n",
" 2 | \n",
" -21.933692 | \n",
" 15.750493 | \n",
"
\n",
" \n",
" 3 | \n",
" -31.001905 | \n",
" 11.392803 | \n",
"
\n",
" \n",
" 4 | \n",
" -23.746023 | \n",
" 23.359208 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" AIC BIC\n",
"AR MA \n",
"0 0 2446.502424 2455.923470\n",
" 1 1459.658418 1473.789987\n",
" 2 892.995533 911.837626\n",
" 3 544.132966 567.685581\n",
" 4 378.778704 407.041842\n",
"1 0 84.506334 98.637903\n",
" 1 -21.530719 -2.688626\n",
" 2 -24.091152 -0.538537\n",
" 3 -24.132206 4.130932\n",
" 4 -25.328477 7.645185\n",
"2 0 3.099523 21.941616\n",
" 1 -25.747284 -2.194669\n",
" 2 -25.623889 2.639250\n",
" 3 -23.893953 9.079709\n",
" 4 -23.535545 14.148640\n",
"3 0 -12.832290 10.720326\n",
" 1 -25.737191 2.525948\n",
" 2 -23.784929 9.188733\n",
" 3 -31.136602 6.547583\n",
" 4 -31.148575 11.246133\n",
"4 0 -14.471428 13.791711\n",
" 1 -23.854585 9.119077\n",
" 2 -21.933692 15.750493\n",
" 3 -31.001905 11.392803\n",
" 4 -23.746023 23.359208"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import statsmodels.tsa.api as tsa\n",
"\n",
"ic = {}\n",
"for ar in range(5):\n",
" for ma in range(5):\n",
" print(f\"AR: {ar}, MA: {ma}\")\n",
" mod = tsa.SARIMAX(term, order=(ar, 0, ma), trend=\"c\")\n",
" res = mod.fit()\n",
" ic[(ar, ma)] = [res.aic, res.bic]\n",
"\n",
"ic = pd.DataFrame(ic, index=[\"AIC\", \"BIC\"]).T\n",
"ic.index = ic.index.set_names([\"AR\", \"MA\"])\n",
"ic"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"execution": {
"iopub.execute_input": "2021-09-22T10:06:33.901814Z",
"iopub.status.busy": "2021-09-22T10:06:33.901814Z",
"iopub.status.idle": "2021-09-22T10:06:33.913815Z",
"shell.execute_reply": "2021-09-22T10:06:33.913815Z"
},
"pycharm": {
"is_executing": false,
"name": "#%%\n"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"AIC selects AR 3, MA 4\n",
"BIC selects AR 1, MA 1\n"
]
}
],
"source": [
"aic = ic.sort_values(\"AIC\")\n",
"aic_ar, aic_ma = aic.index[0]\n",
"print(f\"AIC selects AR {aic_ar}, MA {aic_ma}\")\n",
"\n",
"bic = ic.sort_values(\"BIC\")\n",
"bic_ar, bic_ma = bic.index[0]\n",
"print(f\"BIC selects AR {bic_ar}, MA {bic_ma}\")"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"execution": {
"iopub.execute_input": "2021-09-22T10:06:33.916816Z",
"iopub.status.busy": "2021-09-22T10:06:33.915814Z",
"iopub.status.idle": "2021-09-22T10:06:35.237816Z",
"shell.execute_reply": "2021-09-22T10:06:35.237816Z"
},
"pycharm": {
"is_executing": false,
"name": "#%%\n"
}
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"c:\\git\\statsmodels\\statsmodels\\base\\model.py:582: ConvergenceWarning: Maximum Likelihood optimization failed to converge. Check mle_retvals\n",
" warnings.warn(\"Maximum Likelihood optimization failed to \"\n"
]
},
{
"data": {
"text/plain": [
"intercept 3.169315\n",
"ar.L1 3.502662\n",
"ar.L2 -2.196129\n",
"ar.L3 1.793205\n",
"ar.L4 3.267782\n",
"ma.L1 4.951384\n",
"ma.L2 6.300074\n",
"ma.L3 4.604737\n",
"ma.L4 0.968661\n",
"sigma2 37.269149\n",
"dtype: float64"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"res = tsa.SARIMAX(term, order=(4, 0, 4), trend=\"c\").fit()\n",
"res.tvalues"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"execution": {
"iopub.execute_input": "2021-09-22T10:06:35.241814Z",
"iopub.status.busy": "2021-09-22T10:06:35.241814Z",
"iopub.status.idle": "2021-09-22T10:06:36.570817Z",
"shell.execute_reply": "2021-09-22T10:06:36.570817Z"
},
"pycharm": {
"is_executing": false,
"name": "#%%\n"
}
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"c:\\git\\statsmodels\\statsmodels\\tsa\\statespace\\sarimax.py:966: UserWarning: Non-stationary starting autoregressive parameters found. Using zeros as starting parameters.\n",
" warn('Non-stationary starting autoregressive parameters'\n",
"c:\\git\\statsmodels\\statsmodels\\tsa\\statespace\\sarimax.py:978: UserWarning: Non-invertible starting MA parameters found. Using zeros as starting parameters.\n",
" warn('Non-invertible starting MA parameters found.'\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"c:\\git\\statsmodels\\statsmodels\\base\\model.py:582: ConvergenceWarning: Maximum Likelihood optimization failed to converge. Check mle_retvals\n",
" warnings.warn(\"Maximum Likelihood optimization failed to \"\n"
]
},
{
"data": {
"text/html": [
"\n",
"SARIMAX Results\n",
"\n",
" Dep. Variable: | TERM | No. Observations: | 821 | \n",
"
\n",
"\n",
" Model: | SARIMAX(4, 0, 3) | Log Likelihood | 24.501 | \n",
"
\n",
"\n",
" Date: | Wed, 22 Sep 2021 | AIC | -31.002 | \n",
"
\n",
"\n",
" Time: | 11:06:36 | BIC | 11.393 | \n",
"
\n",
"\n",
" Sample: | 04-01-1953 | HQIC | -14.736 | \n",
"
\n",
"\n",
" | - 08-01-2021 | | | \n",
"
\n",
"\n",
" Covariance Type: | opg | | | \n",
"
\n",
"
\n",
"\n",
"\n",
" | coef | std err | z | P>|z| | [0.025 | 0.975] | \n",
"
\n",
"\n",
" intercept | 0.1427 | 0.039 | 3.668 | 0.000 | 0.066 | 0.219 | \n",
"
\n",
"\n",
" ar.L1 | -0.1950 | 0.045 | -4.377 | 0.000 | -0.282 | -0.108 | \n",
"
\n",
"\n",
" ar.L2 | 0.0228 | 0.045 | 0.511 | 0.609 | -0.065 | 0.110 | \n",
"
\n",
"\n",
" ar.L3 | 0.8256 | 0.043 | 19.204 | 0.000 | 0.741 | 0.910 | \n",
"
\n",
"\n",
" ar.L4 | 0.2075 | 0.053 | 3.947 | 0.000 | 0.104 | 0.310 | \n",
"
\n",
"\n",
" ma.L1 | 1.5455 | 0.042 | 36.477 | 0.000 | 1.462 | 1.629 | \n",
"
\n",
"\n",
" ma.L2 | 1.4873 | 0.062 | 24.077 | 0.000 | 1.366 | 1.608 | \n",
"
\n",
"\n",
" ma.L3 | 0.6098 | 0.047 | 12.838 | 0.000 | 0.517 | 0.703 | \n",
"
\n",
"\n",
" sigma2 | 0.0547 | 0.001 | 39.262 | 0.000 | 0.052 | 0.057 | \n",
"
\n",
"
\n",
"\n",
"\n",
" Ljung-Box (L1) (Q): | 0.00 | Jarque-Bera (JB): | 3550.80 | \n",
"
\n",
"\n",
" Prob(Q): | 0.95 | Prob(JB): | 0.00 | \n",
"
\n",
"\n",
" Heteroskedasticity (H): | 0.68 | Skew: | 0.69 | \n",
"
\n",
"\n",
" Prob(H) (two-sided): | 0.00 | Kurtosis: | 13.09 | \n",
"
\n",
"
Warnings:
[1] Covariance matrix calculated using the outer product of gradients (complex-step)."
],
"text/plain": [
"\n",
"\"\"\"\n",
" SARIMAX Results \n",
"==============================================================================\n",
"Dep. Variable: TERM No. Observations: 821\n",
"Model: SARIMAX(4, 0, 3) Log Likelihood 24.501\n",
"Date: Wed, 22 Sep 2021 AIC -31.002\n",
"Time: 11:06:36 BIC 11.393\n",
"Sample: 04-01-1953 HQIC -14.736\n",
" - 08-01-2021 \n",
"Covariance Type: opg \n",
"==============================================================================\n",
" coef std err z P>|z| [0.025 0.975]\n",
"------------------------------------------------------------------------------\n",
"intercept 0.1427 0.039 3.668 0.000 0.066 0.219\n",
"ar.L1 -0.1950 0.045 -4.377 0.000 -0.282 -0.108\n",
"ar.L2 0.0228 0.045 0.511 0.609 -0.065 0.110\n",
"ar.L3 0.8256 0.043 19.204 0.000 0.741 0.910\n",
"ar.L4 0.2075 0.053 3.947 0.000 0.104 0.310\n",
"ma.L1 1.5455 0.042 36.477 0.000 1.462 1.629\n",
"ma.L2 1.4873 0.062 24.077 0.000 1.366 1.608\n",
"ma.L3 0.6098 0.047 12.838 0.000 0.517 0.703\n",
"sigma2 0.0547 0.001 39.262 0.000 0.052 0.057\n",
"===================================================================================\n",
"Ljung-Box (L1) (Q): 0.00 Jarque-Bera (JB): 3550.80\n",
"Prob(Q): 0.95 Prob(JB): 0.00\n",
"Heteroskedasticity (H): 0.68 Skew: 0.69\n",
"Prob(H) (two-sided): 0.00 Kurtosis: 13.09\n",
"===================================================================================\n",
"\n",
"Warnings:\n",
"[1] Covariance matrix calculated using the outer product of gradients (complex-step).\n",
"\"\"\""
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"gts_res = tsa.SARIMAX(term, order=(4, 0, 3), trend=\"c\").fit()\n",
"gts_res.summary()"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"execution": {
"iopub.execute_input": "2021-09-22T10:06:36.574814Z",
"iopub.status.busy": "2021-09-22T10:06:36.574814Z",
"iopub.status.idle": "2021-09-22T10:06:36.790816Z",
"shell.execute_reply": "2021-09-22T10:06:36.790816Z"
},
"pycharm": {
"is_executing": false,
"name": "#%%\n"
}
},
"outputs": [
{
"data": {
"text/plain": [
"intercept 3.096112\n",
"ar.L1 154.969395\n",
"sigma2 58.220475\n",
"dtype: float64"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"res = tsa.SARIMAX(term, order=(1, 0, 0), trend=\"c\").fit()\n",
"res.tvalues"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"execution": {
"iopub.execute_input": "2021-09-22T10:06:36.794814Z",
"iopub.status.busy": "2021-09-22T10:06:36.793814Z",
"iopub.status.idle": "2021-09-22T10:06:36.917815Z",
"shell.execute_reply": "2021-09-22T10:06:36.917815Z"
},
"pycharm": {
"is_executing": false,
"name": "#%%\n"
}
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"c:\\git\\statsmodels\\statsmodels\\tsa\\statespace\\sarimax.py:978: UserWarning: Non-invertible starting MA parameters found. Using zeros as starting parameters.\n",
" warn('Non-invertible starting MA parameters found.'\n"
]
},
{
"data": {
"text/plain": [
"intercept 24.389775\n",
"ma.L1 74.017777\n",
"sigma2 21.999551\n",
"dtype: float64"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"res = tsa.SARIMAX(term, order=(0, 0, 1), trend=\"c\").fit()\n",
"res.tvalues"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {
"execution": {
"iopub.execute_input": "2021-09-22T10:06:36.921814Z",
"iopub.status.busy": "2021-09-22T10:06:36.921814Z",
"iopub.status.idle": "2021-09-22T10:06:37.357816Z",
"shell.execute_reply": "2021-09-22T10:06:37.357816Z"
},
"pycharm": {
"is_executing": false,
"name": "#%%\n"
}
},
"outputs": [
{
"data": {
"text/plain": [
"intercept 4.244909\n",
"ar.L1 93.891822\n",
"ar.L2 -22.426362\n",
"sigma2 50.391595\n",
"dtype: float64"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"res = tsa.SARIMAX(term, order=(2, 0, 0), trend=\"c\").fit()\n",
"res.tvalues"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {
"execution": {
"iopub.execute_input": "2021-09-22T10:06:37.361817Z",
"iopub.status.busy": "2021-09-22T10:06:37.360817Z",
"iopub.status.idle": "2021-09-22T10:06:37.596816Z",
"shell.execute_reply": "2021-09-22T10:06:37.596816Z"
},
"pycharm": {
"is_executing": false,
"name": "#%%\n"
}
},
"outputs": [
{
"data": {
"text/plain": [
"intercept 4.053603\n",
"ar.L1 117.546963\n",
"ma.L1 33.983406\n",
"sigma2 43.174806\n",
"dtype: float64"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"res = tsa.SARIMAX(term, order=(1, 0, 1), trend=\"c\").fit()\n",
"res.tvalues"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {
"execution": {
"iopub.execute_input": "2021-09-22T10:06:37.600814Z",
"iopub.status.busy": "2021-09-22T10:06:37.599814Z",
"iopub.status.idle": "2021-09-22T10:06:38.052816Z",
"shell.execute_reply": "2021-09-22T10:06:38.052816Z"
},
"pycharm": {
"is_executing": false,
"name": "#%%\n"
}
},
"outputs": [
{
"data": {
"text/plain": [
"intercept 3.752052\n",
"ar.L1 18.512311\n",
"ar.L2 6.003319\n",
"ma.L1 16.754859\n",
"sigma2 38.684049\n",
"dtype: float64"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"res = tsa.SARIMAX(term, order=(2, 0, 1), trend=\"c\").fit()\n",
"res.tvalues"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {
"execution": {
"iopub.execute_input": "2021-09-22T10:06:38.056814Z",
"iopub.status.busy": "2021-09-22T10:06:38.056814Z",
"iopub.status.idle": "2021-09-22T10:06:38.385816Z",
"shell.execute_reply": "2021-09-22T10:06:38.385816Z"
},
"pycharm": {
"is_executing": false,
"name": "#%%\n"
}
},
"outputs": [
{
"data": {
"text/plain": [
"intercept 3.724566\n",
"ar.L1 117.277030\n",
"ma.L1 26.188197\n",
"ma.L2 -3.595584\n",
"sigma2 37.913572\n",
"dtype: float64"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"res = tsa.SARIMAX(term, order=(1, 0, 2), trend=\"c\").fit()\n",
"res.tvalues"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {
"execution": {
"iopub.execute_input": "2021-09-22T10:06:38.389814Z",
"iopub.status.busy": "2021-09-22T10:06:38.388814Z",
"iopub.status.idle": "2021-09-22T10:06:38.874816Z",
"shell.execute_reply": "2021-09-22T10:06:38.874816Z"
},
"pycharm": {
"is_executing": false,
"name": "#%%\n"
}
},
"outputs": [
{
"data": {
"text/plain": [
"intercept 3.798727\n",
"ar.L1 11.830394\n",
"ar.L2 4.810068\n",
"ar.L3 -1.934410\n",
"ma.L1 12.735244\n",
"sigma2 37.999059\n",
"dtype: float64"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"res = tsa.SARIMAX(term, order=(3, 0, 1), trend=\"c\").fit()\n",
"res.tvalues"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {
"execution": {
"iopub.execute_input": "2021-09-22T10:06:38.877814Z",
"iopub.status.busy": "2021-09-22T10:06:38.877814Z",
"iopub.status.idle": "2021-09-22T10:06:39.588817Z",
"shell.execute_reply": "2021-09-22T10:06:39.588817Z"
},
"pycharm": {
"is_executing": false,
"name": "#%%\n"
}
},
"outputs": [
{
"data": {
"text/plain": [
"intercept 3.245250\n",
"ar.L1 2.111979\n",
"ar.L2 3.056135\n",
"ma.L1 4.948013\n",
"ma.L2 1.668112\n",
"sigma2 38.191631\n",
"dtype: float64"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"res = tsa.SARIMAX(term, order=(2, 0, 2), trend=\"c\").fit()\n",
"res.tvalues"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {
"execution": {
"iopub.execute_input": "2021-09-22T10:06:39.592814Z",
"iopub.status.busy": "2021-09-22T10:06:39.591814Z",
"iopub.status.idle": "2021-09-22T10:06:40.047816Z",
"shell.execute_reply": "2021-09-22T10:06:40.047816Z"
},
"pycharm": {
"is_executing": false,
"name": "#%%\n"
},
"tags": []
},
"outputs": [
{
"data": {
"text/html": [
"\n",
"SARIMAX Results\n",
"\n",
" Dep. Variable: | TERM | No. Observations: | 821 | \n",
"
\n",
"\n",
" Model: | SARIMAX(2, 0, 1) | Log Likelihood | 17.874 | \n",
"
\n",
"\n",
" Date: | Wed, 22 Sep 2021 | AIC | -25.747 | \n",
"
\n",
"\n",
" Time: | 11:06:40 | BIC | -2.195 | \n",
"
\n",
"\n",
" Sample: | 04-01-1953 | HQIC | -16.711 | \n",
"
\n",
"\n",
" | - 08-01-2021 | | | \n",
"
\n",
"\n",
" Covariance Type: | opg | | | \n",
"
\n",
"
\n",
"\n",
"\n",
" | coef | std err | z | P>|z| | [0.025 | 0.975] | \n",
"
\n",
"\n",
" intercept | 0.0510 | 0.014 | 3.752 | 0.000 | 0.024 | 0.078 | \n",
"
\n",
"\n",
" ar.L1 | 0.7160 | 0.039 | 18.512 | 0.000 | 0.640 | 0.792 | \n",
"
\n",
"\n",
" ar.L2 | 0.2307 | 0.038 | 6.003 | 0.000 | 0.155 | 0.306 | \n",
"
\n",
"\n",
" ma.L1 | 0.6209 | 0.037 | 16.755 | 0.000 | 0.548 | 0.694 | \n",
"
\n",
"\n",
" sigma2 | 0.0558 | 0.001 | 38.684 | 0.000 | 0.053 | 0.059 | \n",
"
\n",
"
\n",
"\n",
"\n",
" Ljung-Box (L1) (Q): | 0.06 | Jarque-Bera (JB): | 3194.19 | \n",
"
\n",
"\n",
" Prob(Q): | 0.81 | Prob(JB): | 0.00 | \n",
"
\n",
"\n",
" Heteroskedasticity (H): | 0.70 | Skew: | 0.58 | \n",
"
\n",
"\n",
" Prob(H) (two-sided): | 0.00 | Kurtosis: | 12.59 | \n",
"
\n",
"
Warnings:
[1] Covariance matrix calculated using the outer product of gradients (complex-step)."
],
"text/plain": [
"\n",
"\"\"\"\n",
" SARIMAX Results \n",
"==============================================================================\n",
"Dep. Variable: TERM No. Observations: 821\n",
"Model: SARIMAX(2, 0, 1) Log Likelihood 17.874\n",
"Date: Wed, 22 Sep 2021 AIC -25.747\n",
"Time: 11:06:40 BIC -2.195\n",
"Sample: 04-01-1953 HQIC -16.711\n",
" - 08-01-2021 \n",
"Covariance Type: opg \n",
"==============================================================================\n",
" coef std err z P>|z| [0.025 0.975]\n",
"------------------------------------------------------------------------------\n",
"intercept 0.0510 0.014 3.752 0.000 0.024 0.078\n",
"ar.L1 0.7160 0.039 18.512 0.000 0.640 0.792\n",
"ar.L2 0.2307 0.038 6.003 0.000 0.155 0.306\n",
"ma.L1 0.6209 0.037 16.755 0.000 0.548 0.694\n",
"sigma2 0.0558 0.001 38.684 0.000 0.053 0.059\n",
"===================================================================================\n",
"Ljung-Box (L1) (Q): 0.06 Jarque-Bera (JB): 3194.19\n",
"Prob(Q): 0.81 Prob(JB): 0.00\n",
"Heteroskedasticity (H): 0.70 Skew: 0.58\n",
"Prob(H) (two-sided): 0.00 Kurtosis: 12.59\n",
"===================================================================================\n",
"\n",
"Warnings:\n",
"[1] Covariance matrix calculated using the outer product of gradients (complex-step).\n",
"\"\"\""
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"stg_res = tsa.SARIMAX(term, order=(2, 0, 1), trend=\"c\").fit()\n",
"stg_res.summary()"
]
}
],
"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
}