๐ Advanced Time Series Forecasting of Tesla Stock
Comparative Analysis of Classical, Seasonal, and Deep Learning Models with Exogenous Predictors
๐ง Overview
This project presents a comprehensive time series forecasting framework for Tesla Inc. (TSLA) stock using a range of modeling techniques:
- ๐ Classical statistical models: AR, MA, ARIMA
- ๐
Seasonal models: SARIMA, Seasonal Decomposition
- ๐ค Deep learning: LSTM Neural Networks
- ๐ Exogenous variable-enhanced models: ARIMAX, SARIMAX
- ๐งฌ Hybrid methodologies: Statistical + Machine Learning combinations
๐ Project Details
- Data Source: Yahoo Finance (
yfinance)
- Ticker: TSLA
- Time Frame: January 2015 โ January 2024
- Language: Python
- Type: Time Series Forecasting & Predictive Modeling
pandas, numpy โ Data wrangling and preprocessing
matplotlib, seaborn, plotly โ Visualization
statsmodels, pmdarima โ Classical & Seasonal time series models
tensorflow, keras โ Deep learning (LSTM)
scikit-learn โ Evaluation and scaling
yfinance โ Stock data extraction
๐ฏ Objectives
- Perform EDA on Teslaโs historical stock prices & returns
- Build and compare AR, MA, ARIMA, and SARIMA models
- Implement exogenous variable models (e.g., ARIMAX, SARIMAX)
- Train and evaluate deep learning models such as LSTM for sequence prediction
- Compare classical vs deep learning approaches
- Evaluate model performance using:
- RMSE, MAE, MAPE
- AIC / BIC
- Ljung-Box test for residual independence
- Residual plots and prediction accuracy
๐ Model Suite
- AR, MA, ARIMA: Classical univariate models for time series
- SARIMA: Seasonal modeling with trend + seasonality
- ARIMAX / SARIMAX: Includes external regressors
- Seasonal Decomposition: Trend, Seasonality, Residual breakdown
- LSTM (RNN): Deep learning for sequential data
- Hybrid Models: Combinations (e.g., ARIMA + LSTM)
โ
Results Summary
- Best Classical Model:
SARIMA(1,1,1)(1,1,0)[12]
- Best Deep Learning Model: LSTM with TimeDistributed layers
- Best Hybrid: ARIMA + LSTM performed competitively
Key Insights:
- Seasonality and external market signals improved accuracy
- Deep learning models showed strong performance on volatile periods
- Hybrid strategies delivered the most consistent forecasts in noisy datasets
๐ Project Structure
tesla-stock-forecasting/
โโโ data/
โ โโโ raw/
โโโ src/
โ โโโ models/
โ โ โโโ classical/
โ โ โโโ deep_learning/
โ โโโ preprocessing/
โ โโโ visualization/
โโโ notebooks/
โโโ results/
๐ฎ Future Work
- Integrate Meta Prophet for trend + seasonality forecasting
- Include macroeconomic indicators as exogenous variables
- Deploy a web dashboard for interactive forecast visualization
Sospeter Njenga Wainaina
๐ง sospeternjenga03@gmail.com
๐ Nairobi, Kenya
๐ Conclusion & Recommendations
After evaluating six models โ AR, MA, ARIMA, SARIMA, SARIMAX, and LSTM, and implementing a Hybrid ARIMA + LSTM, we conclude:
๐ฅ Hybrid ARIMA + LSTM is the most accurate model for forecasting Tesla stock prices.
- It outperformed others in RMSE, MAE, MAPE.
- Statistically significant accuracy advantage confirmed via Diebold-Mariano test vs. SARIMAX (
p โ 0.0000).
๐ง Model Strengths by Category
| Model |
Strengths |
Best Use Cases |
| AR / MA |
Simplicity, fast computation |
Short-term trend capturing, quick benchmarks |
| ARIMA |
Handles non-stationarity |
Medium-term forecasting without seasonality |
| SARIMA |
Accounts for both trend + seasonality |
Monthly/quarterly financial patterns |
| SARIMAX |
Integrates external variables like volume or lagged returns |
Multivariate forecasting, macro-driven influence |
| LSTM |
Learns complex, nonlinear temporal dependencies |
High-volatility prediction, adaptive learning |
| Hybrid |
ARIMA models trend, LSTM models residuals (nonlinear patterns) |
Highly volatile, non-linear series like stocks |
โ ๏ธ Limitations
- No macroeconomic data like interest rates or inflation included.
- LSTM training can be time-consuming and sensitive to hyperparameters.
- Assumes stable market conditions, which may not hold in extreme economic events.
๐ Future Improvements
- Add exogenous features (e.g., S&P500 index, news sentiment, global indicators).
- Tune deep learning models with Bayesian optimization or Grid Search.
- Explore attention-based architectures like Transformer models for enhanced context learning.
- Deploy as a web app using Streamlit for interactive forecasting.