Skip to content

Commit e628e2e

Browse files
committed
final draft of SARIMAX
1 parent 6669723 commit e628e2e

File tree

9 files changed

+50
-47
lines changed

9 files changed

+50
-47
lines changed

content/posts/finance/stock_prediction/SARIMAX/index.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@ categories: ["Finance"]
1414
---
1515

1616

17+
In the previous articles we saw the limitations of the [ARIMA](/posts/finance/stock_prediction/arima) and [SARIMA](/posts/finance/stock_prediction/sarima). Therefore, in this article we are going to implement a SARIMAX model the can include **exogenous variables**
18+
1719
## Introduction to Exogenous Variables in Time Series Models
18-
In the previous articles ( [ARIMA](/posts/finance/stock_prediction/arima) and [SARIMA](/posts/finance/stock_prediction/sarima)
20+
1921

2022
Exogenous variables, also known as external regressors, are independent variables that are not part of the main time series but can influence it. In the context of stock price prediction, exogenous variables might include:
2123

content/posts/finance/stock_prediction/SARIMAX/sarimax_example.ipynb

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
},
3838
{
3939
"cell_type": "code",
40-
"execution_count": 58,
40+
"execution_count": 65,
4141
"metadata": {},
4242
"outputs": [
4343
{
@@ -53,30 +53,30 @@
5353
"output_type": "stream",
5454
"text": [
5555
"Performing stepwise search to minimize aic\n",
56-
" ARIMA(1,1,1)(1,1,1)[12] : AIC=inf, Time=1.82 sec\n",
56+
" ARIMA(1,1,1)(1,1,1)[12] : AIC=inf, Time=1.83 sec\n",
5757
" ARIMA(0,1,0)(0,1,0)[12] : AIC=3802.747, Time=0.04 sec\n",
58-
" ARIMA(1,1,0)(1,1,0)[12] : AIC=3597.813, Time=0.15 sec\n",
59-
" ARIMA(0,1,1)(0,1,1)[12] : AIC=inf, Time=0.99 sec\n",
60-
" ARIMA(1,1,0)(0,1,0)[12] : AIC=3804.105, Time=0.04 sec\n",
61-
" ARIMA(1,1,0)(2,1,0)[12] : AIC=3525.586, Time=0.34 sec\n",
62-
" ARIMA(1,1,0)(2,1,1)[12] : AIC=inf, Time=2.90 sec\n",
63-
" ARIMA(1,1,0)(1,1,1)[12] : AIC=inf, Time=1.09 sec\n",
64-
" ARIMA(0,1,0)(2,1,0)[12] : AIC=3523.686, Time=0.26 sec\n",
65-
" ARIMA(0,1,0)(1,1,0)[12] : AIC=3596.070, Time=0.08 sec\n",
66-
" ARIMA(0,1,0)(2,1,1)[12] : AIC=inf, Time=2.63 sec\n",
67-
" ARIMA(0,1,0)(1,1,1)[12] : AIC=inf, Time=0.80 sec\n",
68-
" ARIMA(0,1,1)(2,1,0)[12] : AIC=3525.569, Time=0.34 sec\n",
69-
" ARIMA(1,1,1)(2,1,0)[12] : AIC=3526.799, Time=0.70 sec\n",
70-
" ARIMA(0,1,0)(2,1,0)[12] intercept : AIC=3525.686, Time=0.76 sec\n",
58+
" ARIMA(1,1,0)(1,1,0)[12] : AIC=3597.813, Time=0.17 sec\n",
59+
" ARIMA(0,1,1)(0,1,1)[12] : AIC=inf, Time=1.05 sec\n",
60+
" ARIMA(1,1,0)(0,1,0)[12] : AIC=3804.105, Time=0.05 sec\n",
61+
" ARIMA(1,1,0)(2,1,0)[12] : AIC=3525.586, Time=0.35 sec\n",
62+
" ARIMA(1,1,0)(2,1,1)[12] : AIC=inf, Time=2.89 sec\n",
63+
" ARIMA(1,1,0)(1,1,1)[12] : AIC=inf, Time=1.08 sec\n",
64+
" ARIMA(0,1,0)(2,1,0)[12] : AIC=3523.686, Time=0.29 sec\n",
65+
" ARIMA(0,1,0)(1,1,0)[12] : AIC=3596.070, Time=0.12 sec\n",
66+
" ARIMA(0,1,0)(2,1,1)[12] : AIC=inf, Time=2.68 sec\n",
67+
" ARIMA(0,1,0)(1,1,1)[12] : AIC=inf, Time=0.81 sec\n",
68+
" ARIMA(0,1,1)(2,1,0)[12] : AIC=3525.569, Time=0.42 sec\n",
69+
" ARIMA(1,1,1)(2,1,0)[12] : AIC=3526.799, Time=0.73 sec\n",
70+
" ARIMA(0,1,0)(2,1,0)[12] intercept : AIC=3525.686, Time=0.82 sec\n",
7171
"\n",
7272
"Best model: ARIMA(0,1,0)(2,1,0)[12] \n",
73-
"Total fit time: 12.965 seconds\n",
73+
"Total fit time: 13.348 seconds\n",
7474
" SARIMAX Results \n",
7575
"==========================================================================================\n",
7676
"Dep. Variable: y No. Observations: 697\n",
7777
"Model: SARIMAX(0, 1, 0)x(2, 1, 0, 12) Log Likelihood -1758.843\n",
7878
"Date: Sun, 07 Jul 2024 AIC 3523.686\n",
79-
"Time: 00:01:08 BIC 3537.270\n",
79+
"Time: 00:23:29 BIC 3537.270\n",
8080
"Sample: 0 HQIC 3528.942\n",
8181
" - 697 \n",
8282
"Covariance Type: opg \n",
@@ -116,7 +116,7 @@
116116
"Dep. Variable: AAPL No. Observations: 697\n",
117117
"Model: SARIMAX(0, 1, 0)x(2, 1, 0, 12) Log Likelihood -1385.522\n",
118118
"Date: Sun, 07 Jul 2024 AIC 2779.044\n",
119-
"Time: 00:01:09 BIC 2797.156\n",
119+
"Time: 00:23:31 BIC 2797.156\n",
120120
"Sample: 0 HQIC 2786.053\n",
121121
" - 697 \n",
122122
"Covariance Type: opg \n",
@@ -182,7 +182,7 @@
182182
},
183183
{
184184
"cell_type": "code",
185-
"execution_count": 59,
185+
"execution_count": 66,
186186
"metadata": {},
187187
"outputs": [
188188
{
@@ -209,15 +209,15 @@
209209
"name": "stdout",
210210
"output_type": "stream",
211211
"text": [
212-
"Mean Squared Error: 1235.4974952613672\n",
213-
"Mean Absolute Error: 28.192420087703255\n",
214-
"Root Mean Squared Error: 35.14964431201783\n",
212+
"Mean Squared Error: 1235.4975\n",
213+
"Mean Absolute Error: 28.1924\n",
214+
"Root Mean Squared Error: 35.1496\n",
215215
" SARIMAX Results \n",
216216
"==========================================================================================\n",
217217
"Dep. Variable: AAPL No. Observations: 697\n",
218218
"Model: SARIMAX(0, 1, 0)x(2, 1, 0, 12) Log Likelihood -1385.522\n",
219219
"Date: Sun, 07 Jul 2024 AIC 2779.044\n",
220-
"Time: 00:01:09 BIC 2797.156\n",
220+
"Time: 00:23:31 BIC 2797.156\n",
221221
"Sample: 0 HQIC 2786.053\n",
222222
" - 697 \n",
223223
"Covariance Type: opg \n",
@@ -263,9 +263,9 @@
263263
"mse = mean_squared_error(test['AAPL'], forecast.predicted_mean)\n",
264264
"mae = mean_absolute_error(test['AAPL'], forecast.predicted_mean)\n",
265265
"rmse = np.sqrt(mse)\n",
266-
"print(f'Mean Squared Error: {mse}')\n",
267-
"print(f'Mean Absolute Error: {mae}')\n",
268-
"print(f'Root Mean Squared Error: {rmse}')\n",
266+
"print(f'Mean Squared Error: {mse:.4f}')\n",
267+
"print(f'Mean Absolute Error: {mae:.4f}')\n",
268+
"print(f'Root Mean Squared Error: {rmse:.4f}')\n",
269269
"\n",
270270
"# Check the impact of the exogenous variable\n",
271271
"print(results.summary())"
@@ -289,7 +289,7 @@
289289
},
290290
{
291291
"cell_type": "code",
292-
"execution_count": 60,
292+
"execution_count": 71,
293293
"metadata": {},
294294
"outputs": [
295295
{
@@ -403,7 +403,7 @@
403403
},
404404
{
405405
"cell_type": "code",
406-
"execution_count": 61,
406+
"execution_count": 78,
407407
"metadata": {},
408408
"outputs": [
409409
{
@@ -420,9 +420,9 @@
420420
"name": "stdout",
421421
"output_type": "stream",
422422
"text": [
423-
"Mean Squared Error: 72.54815308159101\n",
424-
"Mean Absolute Error: 5.992999880063084\n",
425-
"Root Mean Squared Error: 8.517520359916436\n"
423+
"Mean Squared Error: 72.5482\n",
424+
"Mean Absolute Error: 5.9930\n",
425+
"Root Mean Squared Error: 8.5175\n"
426426
]
427427
}
428428
],
@@ -453,9 +453,9 @@
453453
"mse = mean_squared_error(test['AAPL'], forecasts)\n",
454454
"mae = mean_absolute_error(test['AAPL'], forecasts)\n",
455455
"rmse = np.sqrt(mse)\n",
456-
"print(f'Mean Squared Error: {mse}')\n",
457-
"print(f'Mean Absolute Error: {mae}')\n",
458-
"print(f'Root Mean Squared Error: {rmse}')"
456+
"print(f'Mean Squared Error: {mse:.4f}')\n",
457+
"print(f'Mean Absolute Error: {mae:.4f}')\n",
458+
"print(f'Root Mean Squared Error: {rmse:.4f}')"
459459
]
460460
},
461461
{

public/index.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

public/index.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
<pubDate>Sat, 06 Jul 2024 00:00:00 +0100</pubDate>
1313

1414
<guid>http://localhost:1313/posts/finance/stock_prediction/sarimax/</guid>
15-
<description>Introduction to Exogenous Variables in Time Series Models Exogenous variables, also known as external regressors, are independent variables that are not part of the main time series but can influence it. In the context of stock price prediction, exogenous variables might include:
16-
Market indices (e.g., S&amp;amp;P 500) Economic indicators (e.g., GDP growth, unemployment rate) Company-specific metrics (e.g., revenue, earnings per share) Sentiment indicators (e.g., social media sentiment) Mathematical Formulation of SARIMAX The SARIMAX model extends the SARIMA model by including exogenous variables.</description>
15+
<description>In the previous articles we saw the limitations of the ARIMA and SARIMA. Therefore, in this article we are going to implement a SARIMAX model the can include exogenous variables
16+
Introduction to Exogenous Variables in Time Series Models Exogenous variables, also known as external regressors, are independent variables that are not part of the main time series but can influence it. In the context of stock price prediction, exogenous variables might include:</description>
1717
</item>
1818

1919
<item>

public/posts/finance/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -491,8 +491,8 @@
491491
<div class="card-body">
492492
<a href="/posts/finance/stock_prediction/sarimax/" class="post-card-link">
493493
<h5 class="card-title">SARIMAX Model Analysis of Apple Stock with Exogenous Variables</h5>
494-
<p class="card-text post-summary">Introduction to Exogenous Variables in Time Series Models Exogenous variables, also known as external regressors, are independent variables that are not part of the main time series but can influence it. In the context of stock price prediction, exogenous variables might include:
495-
Market indices (e.g., S&amp;P 500) Economic indicators (e.g., GDP growth, unemployment rate) Company-specific metrics (e.g., revenue, earnings per share) Sentiment indicators (e.g., social media sentiment) Mathematical Formulation of SARIMAX The SARIMAX model extends the SARIMA model by including exogenous variables.</p>
494+
<p class="card-text post-summary">In the previous articles we saw the limitations of the ARIMA and SARIMA. Therefore, in this article we are going to implement a SARIMAX model the can include exogenous variables
495+
Introduction to Exogenous Variables in Time Series Models Exogenous variables, also known as external regressors, are independent variables that are not part of the main time series but can influence it. In the context of stock price prediction, exogenous variables might include:</p>
496496
</a>
497497

498498
<div class="tags">

public/posts/finance/index.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
<pubDate>Sat, 06 Jul 2024 00:00:00 +0100</pubDate>
1313

1414
<guid>http://localhost:1313/posts/finance/stock_prediction/sarimax/</guid>
15-
<description>Introduction to Exogenous Variables in Time Series Models Exogenous variables, also known as external regressors, are independent variables that are not part of the main time series but can influence it. In the context of stock price prediction, exogenous variables might include:
16-
Market indices (e.g., S&amp;amp;P 500) Economic indicators (e.g., GDP growth, unemployment rate) Company-specific metrics (e.g., revenue, earnings per share) Sentiment indicators (e.g., social media sentiment) Mathematical Formulation of SARIMAX The SARIMAX model extends the SARIMA model by including exogenous variables.</description>
15+
<description>In the previous articles we saw the limitations of the ARIMA and SARIMA. Therefore, in this article we are going to implement a SARIMAX model the can include exogenous variables
16+
Introduction to Exogenous Variables in Time Series Models Exogenous variables, also known as external regressors, are independent variables that are not part of the main time series but can influence it. In the context of stock price prediction, exogenous variables might include:</description>
1717
</item>
1818

1919
<item>

public/posts/finance/stock_prediction/sarimax/index.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,8 @@ <h1>SARIMAX Model Analysis of Apple Stock with Exogenous Variables</h1>
527527

528528

529529
<div class="post-content" id="post-content">
530-
<h2 id="introduction-to-exogenous-variables-in-time-series-models">Introduction to Exogenous Variables in Time Series Models</h2>
530+
<p>In the previous articles we saw the limitations of the <a href="/posts/finance/stock_prediction/arima">ARIMA</a> and <a href="/posts/finance/stock_prediction/sarima">SARIMA</a>. Therefore, in this article we are going to implement a SARIMAX model the can include <strong>exogenous variables</strong></p>
531+
<h2 id="introduction-to-exogenous-variables-in-time-series-models">Introduction to Exogenous Variables in Time Series Models</h2>
531532
<p>Exogenous variables, also known as external regressors, are independent variables that are not part of the main time series but can influence it. In the context of stock price prediction, exogenous variables might include:</p>
532533
<ol>
533534
<li>Market indices (e.g., S&amp;P 500)</li>

public/posts/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -488,8 +488,8 @@
488488
<div class="card-body">
489489
<a href="/posts/finance/stock_prediction/sarimax/" class="post-card-link">
490490
<h5 class="card-title">SARIMAX Model Analysis of Apple Stock with Exogenous Variables</h5>
491-
<p class="card-text post-summary">Introduction to Exogenous Variables in Time Series Models Exogenous variables, also known as external regressors, are independent variables that are not part of the main time series but can influence it. In the context of stock price prediction, exogenous variables might include:
492-
Market indices (e.g., S&amp;P 500) Economic indicators (e.g., GDP growth, unemployment rate) Company-specific metrics (e.g., revenue, earnings per share) Sentiment indicators (e.g., social media sentiment) Mathematical Formulation of SARIMAX The SARIMAX model extends the SARIMA model by including exogenous variables.</p>
491+
<p class="card-text post-summary">In the previous articles we saw the limitations of the ARIMA and SARIMA. Therefore, in this article we are going to implement a SARIMAX model the can include exogenous variables
492+
Introduction to Exogenous Variables in Time Series Models Exogenous variables, also known as external regressors, are independent variables that are not part of the main time series but can influence it. In the context of stock price prediction, exogenous variables might include:</p>
493493
</a>
494494

495495
<div class="tags">

public/posts/index.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
<pubDate>Sat, 06 Jul 2024 00:00:00 +0100</pubDate>
1313

1414
<guid>http://localhost:1313/posts/finance/stock_prediction/sarimax/</guid>
15-
<description>Introduction to Exogenous Variables in Time Series Models Exogenous variables, also known as external regressors, are independent variables that are not part of the main time series but can influence it. In the context of stock price prediction, exogenous variables might include:
16-
Market indices (e.g., S&amp;amp;P 500) Economic indicators (e.g., GDP growth, unemployment rate) Company-specific metrics (e.g., revenue, earnings per share) Sentiment indicators (e.g., social media sentiment) Mathematical Formulation of SARIMAX The SARIMAX model extends the SARIMA model by including exogenous variables.</description>
15+
<description>In the previous articles we saw the limitations of the ARIMA and SARIMA. Therefore, in this article we are going to implement a SARIMAX model the can include exogenous variables
16+
Introduction to Exogenous Variables in Time Series Models Exogenous variables, also known as external regressors, are independent variables that are not part of the main time series but can influence it. In the context of stock price prediction, exogenous variables might include:</description>
1717
</item>
1818

1919
<item>

0 commit comments

Comments
 (0)