SARIMAX Model for GOOGL Stock Price Forecasting
Model Description
This model is a Seasonal Autoregressive Integrated Moving Average with eXogenous regressors (SARIMAX) model trained to forecast the closing prices of GOOGL stock. Time series decomposition of the GOOGL stock data revealed trend and seasonality components, making SARIMAX a suitable choice for modeling.
Purpose
The primary purpose of this model is to provide short-term forecasts for the closing price of GOOGL stock based on historical data. It can be used for exploratory analysis, understanding historical patterns, and generating potential future price scenarios.
Training Data
- Source: The model was trained on historical GOOGL stock price data extracted from an Excel file named
Additional DataSet.xlsx.
- Time Period: The training data covers the period from March 10, 2023, up to approximately 80% of the available data points, as determined by an 80/20 train/test split. The exact end date of the training period is December 29, 2023.
- Data Preprocessing: The raw data was transformed from a wide format to a long format, and the 'Date' column was converted to datetime objects. Missing values were handled using linear interpolation, followed by forward and backward fill to ensure no gaps remained in the time series data for the selected ticker.
- SARIMAX Order: A grid search was performed to find the optimal (p, d, q) order for the non-seasonal components and (P, D, Q, S) for the seasonal components based on the Akaike Information Criterion (AIC). The best order found was (1, 0, 1) for the non-seasonal part and (0, 1, 1, 12) for the seasonal part (assuming yearly seasonality with period 12).
Evaluation
The model's performance was evaluated using a rolling window approach on the test set (the remaining 20% of the data). The metrics used for evaluation were Root Mean Squared Error (RMSE), Mean Absolute Error (MAE), and Mean Absolute Percentage Error (MAPE). The SARIMAX model demonstrated lower error metrics compared to a Prophet model in this evaluation.
Usage
This model is saved in a pickle file (sarimax_model.pkl). It can be loaded using joblib in a Python environment.
1import joblib
2import pandas as pd
3
4# Load the model
5model = joblib.load('sarimax_model.pkl')
6
7# To make a forecast (example for the next 30 days)
8n_steps = 30
9# You would need to provide the historical data (ts_data used during training)
10# to the loaded model for forecasting if it's not embedded in the saved object.
11# Depending on how the model object handles forecasting after loading,
12# you might need the last few data points of the training data.
13# A typical approach is to use the .predict() or .forecast() method.
14# Example (assuming 'ts_data' is the full historical series used for the final fit):
15# forecast_result = model.get_forecast(steps=n_steps)
16# predicted_mean = forecast_result.predicted_mean
17# confidence_intervals = forecast_result.conf_int(alpha=0.05)
18
19# The exact method depends on the saved model object's capabilities.
20# Refer to the statsmodels documentation for the specific SARIMAXResultsWrapper object.
To use the model for forecasting, you would typically load the saved model object and then use its forecasting methods, providing the necessary historical data context if required by the model's implementation.
Limitations
- Data Dependency: The model's performance is highly dependent on the quality and characteristics of the historical data it was trained on.
- Stationarity Assumption: While SARIMAX handles non-stationarity through differencing, significant structural changes in the market or the stock's behavior not present in the training data may impact forecast accuracy.
- Parameter Sensitivity: The choice of (p, d, q) and (P, D, Q, S) orders can significantly affect performance. The grid search helps find optimal parameters for the training period, but these may not be universally optimal.
- Short-Term Focus: Time series models like SARIMAX are generally more reliable for short-term forecasts. Long-term predictions may have wider confidence intervals and lower accuracy.
- No External Factors: This basic SARIMAX model does not incorporate external factors (e.g., news events, economic indicators) that can influence stock prices.
License
[Specify license if applicable, e.g., MIT, Apache 2.0]