AI in Finance Capstone Project A comprehensive comparison of ARIMA, LSTM, and GRU models for stock price prediction across three distinct market sectors.
This project implements and compares three forecasting approaches for stock price prediction:
- ARIMA(3,1,5) - Classical time series model
- LSTM - Long Short-Term Memory neural network
- GRU - Gated Recurrent Unit neural network
The analysis covers three stocks with different market characteristics:
- ๐ AAPL (Apple) - Large-cap technology, stable growth
- ๐ฎ NVDA (NVIDIA) - High-volatility semiconductor/AI
- ๐ LYFT - Small-cap ride-sharing, erratic patterns
Time Period: 2020-01-01 to Present (~5 years) Data Source: Yahoo Finance Training/Test Split: 80/20
| Stock | Best Model | RMSE Improvement vs ARIMA | Directional Accuracy |
|---|---|---|---|
| AAPL | GRU | 64% reduction | ~52% |
| NVDA | LSTM | 80% reduction | ~51% |
| LYFT | GRU | 80% reduction | ~53% |
- Neural networks significantly outperform ARIMA for all stocks studied (64-82% RMSE reduction)
- GRU is the practical winner - best balance of accuracy, training speed, and simplicity
- LSTM excels for high-volatility stocks - superior long-term memory for explosive growth patterns (NVDA)
- ARIMA remains valuable for baseline comparison and interpretable forecasts
- Directional accuracy ~51% - even sophisticated models struggle to beat random chance (50%)
Stock-analytics/
โโโ main.ipynb # Main analysis notebook
โโโ README.md # This file
Completed Tasks:
- โ Data extraction from Yahoo Finance API
- โ Exploratory data analysis with interactive visualizations
- โ Time series decomposition (trend, seasonality, residuals)
- โ Stationarity testing (ADF test)
- โ ACF/PACF analysis
- โ Feature engineering (EMA, DEMA)
- โ
Classical model implementation:
- MA(20) - Moving Average
- AR(20) - Autoregressive
- ARIMA(3,1,5) - Grid search optimal model
Key Results:
- ARIMA(3,1,5) selected by grid search on NVDA (AIC = 4378.65)
- Stationarity achieved with first-order differencing (d=1)
- Applied consistently across all three stocks
Completed Tasks:
- โ Data normalization (MinMaxScaler 0-1 range)
- โ Sequence generation (60-day lookback window)
- โ
LSTM implementation:
- 2-layer architecture (50 units each)
- Dropout regularization (0.2)
- Early stopping (patience=5)
- โ
GRU implementation:
- 2-layer architecture (50 units each)
- 25% fewer parameters than LSTM
- Faster training convergence
- โ Training/validation split (90/10 within training set)
- โ Convergence behavior analysis
Architecture Details:
Input: 60 days ร 5 features (Open, High, Low, Close, Volume)
Layer 1: LSTM/GRU (50 units, return_sequences=True)
Dropout: 0.2
Layer 2: LSTM/GRU (50 units)
Dropout: 0.2
Dense: 25 units
Output: 1 unit (next day's closing price)
Completed Tasks:
- โ
Comprehensive metrics calculation:
- RMSE (Root Mean Squared Error)
- MAE (Mean Absolute Error)
- MAPE (Mean Absolute Percentage Error)
- DA (Directional Accuracy)
- โ Side-by-side model comparison (3 stocks ร 3 models = 9 combinations)
- โ Prediction visualizations with interactive Plotly charts
- โ Detailed interpretation of when LSTM/GRU outperform ARIMA
- โ Practical recommendations for different use cases
Performance Breakdown:
AAPL (Apple):
- ARIMA(3,1,5): RMSE $24.29
- LSTM: RMSE $8.89
- GRU: RMSE $8.75 โจ Winner
NVDA (NVIDIA):
- ARIMA(3,1,5): RMSE $42.10
- LSTM: RMSE $8.56 โจ Winner
- GRU: RMSE $9.84
LYFT:
- ARIMA(3,1,5): RMSE $4.53
- LSTM: RMSE $1.11
- GRU: RMSE $0.92 โจ Winner
Python Libraries:
pandas- Data manipulationnumpy- Numerical computingyfinance- Yahoo Finance API wrapperstatsmodels- ARIMA, ACF/PACF, ADF testtensorflow/keras- LSTM/GRU implementationscikit-learn- Preprocessing, metricsplotly- Interactive visualizations
Environment:
- Python 3.8+
- TensorFlow 2.x
- Jupyter Notebook
# Clone the repository
git clone https://github.com/allanilya/Stock-analytics.git
cd Stock-analytics
# Install dependencies
pip install pandas numpy yfinance statsmodels tensorflow scikit-learn plotly
# Launch Jupyter Notebook
jupyter notebook main.ipynb- Open
main.ipynbin Jupyter Notebook - Run all cells sequentially (Kernel โ Restart & Run All)
- Expected runtime: ~10-15 minutes
- Data extraction: ~2 min
- Classical models: ~2 min
- Neural network training: ~5-8 min
- Visualization: ~2 min
pandas>=1.3.0
numpy>=1.21.0
yfinance>=0.1.63
statsmodels>=0.13.0
tensorflow>=2.8.0
scikit-learn>=1.0.0
plotly>=5.3.0
matplotlib>=3.4.0
- โ Stock has high volatility (e.g., NVDA, tech growth stocks)
- โ Long-term dependencies matter (product cycles, earnings patterns)
- โ Computational cost is not a constraint
- โ You need the most accurate predictions
- โ Default choice for most applications
- โ Training speed matters (production systems)
- โ Stable or moderately volatile stocks (e.g., AAPL, LYFT)
- โ You want best accuracy-to-complexity ratio
- โ Interpretability is critical (regulatory requirements)
- โ Limited data available (<1000 samples)
- โ Quick baseline needed
- โ Stock follows linear patterns (index funds, utilities)
- Univariate models - Only uses past prices, ignores volume/sentiment
- Single architecture - Did not test 1-layer vs 3-layer networks
- One-day-ahead only - Multi-day forecasts may favor different models
- Train/test split - Walk-forward validation would be more rigorous
- Directional accuracy ~51% - Barely beats random (50%)
- Multivariate models - Add volume, RSI, MACD, sentiment scores
- Attention mechanisms - Transformer models for sequence-to-sequence
- Hybrid models - ARIMA for trend + LSTM for residuals
- Architecture search - Grid search over layers, units, sequence length
- Walk-forward validation - Rolling window retraining
- Risk metrics - Sharpe ratio, maximum drawdown, VaR
The notebook includes:
- ๐ Price trends with exponential moving averages
- ๐ Time series decomposition (trend/seasonality/residuals)
- ๐ ACF/PACF plots for model selection
- ๐ฏ Forecast vs actual comparison charts
- ๐ Training history (loss curves)
- ๐ Model performance comparison tables
This project fulfills the requirements for a three-milestone capstone in AI for Finance:
- Milestone 1: Classical time series analysis with ARIMA
- Milestone 2: Deep learning implementation with LSTM/GRU
- Milestone 3: Comprehensive model evaluation and comparison
The analysis demonstrates that while neural networks significantly outperform classical models in terms of RMSE, the near-random directional accuracy (~51%) aligns with the semi-strong efficient market hypothesis - short-term stock prices are fundamentally difficult to predict.
- ARIMA Modeling: Box, G. E. P., & Jenkins, G. M. (1976). Time Series Analysis: Forecasting and Control
- LSTM Networks: Hochreiter, S., & Schmidhuber, J. (1997). Long Short-Term Memory
- GRU Networks: Cho, K., et al. (2014). Learning Phrase Representations using RNN Encoder-Decoder
- Financial Time Series: Tsay, R. S. (2005). Analysis of Financial Time Series
Allan Ilyasov Giulio Bardelli Peter Roumeliotis
This project is for educational purposes as part of an academic capstone.
- Professor's reference notebook:
04-05 ARIMA_with_AlphaVantage_Vintage_API.ipynb - Yahoo Finance for providing free historical stock data
- TensorFlow/Keras teams for deep learning framework
- Statsmodels for classical time series tools
Last Updated: 2025-11-23 Status: โ Complete - All three milestones fulfilled