Update README.md
Browse files
README.md
CHANGED
|
@@ -1,3 +1,102 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# π Time Series Forecasting β Stock Prices
|
| 2 |
+
|
| 3 |
+
This project demonstrates how to perform **time series forecasting** on stock prices using both **statistical models** (ARIMA, SARIMAX) and **deep learning (LSTM)**, with proper evaluation techniques like **rolling window forecasting**.
|
| 4 |
+
|
| 5 |
+
---
|
| 6 |
+
|
| 7 |
+
## π Project Overview
|
| 8 |
+
|
| 9 |
+
The notebook walks through the end-to-end pipeline of forecasting stock prices:
|
| 10 |
+
|
| 11 |
+
1. **Dataset Acquisition**
|
| 12 |
+
- Uses the Kaggle dataset: *World Stock Prices β Daily Updating*
|
| 13 |
+
- Downloaded via `kagglehub`
|
| 14 |
+
|
| 15 |
+
2. **Preprocessing**
|
| 16 |
+
- Convert `Date` column to datetime and set as index.
|
| 17 |
+
- Sort data by date.
|
| 18 |
+
- Filter for a single stock (default: **AAPL**).
|
| 19 |
+
- Handle missing values using forward-fill / interpolation.
|
| 20 |
+
|
| 21 |
+
3. **Exploratory Data Analysis (EDA)**
|
| 22 |
+
- Visualize stock closing prices over time.
|
| 23 |
+
- Check for stationarity (ADF test).
|
| 24 |
+
- Plot ACF/PACF to guide ARIMA orders.
|
| 25 |
+
|
| 26 |
+
4. **Modeling Approaches**
|
| 27 |
+
- **ARIMA**: Baseline forecasting with manually selected parameters.
|
| 28 |
+
- **Auto-ARIMA**: Automated parameter tuning using AIC/BIC.
|
| 29 |
+
- **SARIMAX**: Seasonal ARIMA with exogenous variables (optional).
|
| 30 |
+
- **LSTM**: Deep learning model for sequence prediction.
|
| 31 |
+
|
| 32 |
+
5. **Forecast Evaluation**
|
| 33 |
+
- Implement **rolling window forecasting**:
|
| 34 |
+
- Train on initial window β Forecast one step ahead β Update with true value β Repeat.
|
| 35 |
+
- Evaluate models using metrics:
|
| 36 |
+
- RMSE, MAE, MAPE
|
| 37 |
+
|
| 38 |
+
---
|
| 39 |
+
|
| 40 |
+
## βοΈ Installation & Requirements
|
| 41 |
+
|
| 42 |
+
Install dependencies:
|
| 43 |
+
|
| 44 |
+
```bash
|
| 45 |
+
pip install pandas numpy matplotlib seaborn scikit-learn statsmodels pmdarima tensorflow kagglehub
|
| 46 |
+
```
|
| 47 |
+
|
| 48 |
+
If running in **Google Colab**, you may also need:
|
| 49 |
+
|
| 50 |
+
```bash
|
| 51 |
+
pip install kagglehub
|
| 52 |
+
```
|
| 53 |
+
|
| 54 |
+
---
|
| 55 |
+
|
| 56 |
+
## π Usage
|
| 57 |
+
|
| 58 |
+
1. Clone or download the notebook:
|
| 59 |
+
```bash
|
| 60 |
+
git clone <repo-link>
|
| 61 |
+
cd stock-forecasting
|
| 62 |
+
```
|
| 63 |
+
|
| 64 |
+
2. Run the Jupyter Notebook:
|
| 65 |
+
```bash
|
| 66 |
+
jupyter notebook "Time_Series_Forecasting_β_Stock_Prices.ipynb"
|
| 67 |
+
```
|
| 68 |
+
|
| 69 |
+
3. Inside the notebook:
|
| 70 |
+
- Change the stock ticker (`ticker_symbol = 'AAPL'`) to forecast other stocks.
|
| 71 |
+
- Choose between **ARIMA / SARIMAX / LSTM** sections.
|
| 72 |
+
- Run evaluation cells to compare results.
|
| 73 |
+
|
| 74 |
+
---
|
| 75 |
+
|
| 76 |
+
## π Results
|
| 77 |
+
|
| 78 |
+
- **ARIMA** works well for short-term stationary series.
|
| 79 |
+
- **SARIMAX** captures seasonality but is computationally heavier.
|
| 80 |
+
- **LSTM** adapts to nonlinear patterns, showing better performance for long-term forecasts.
|
| 81 |
+
- Rolling window evaluation provides realistic performance assessment compared to a single train-test split.
|
| 82 |
+
|
| 83 |
+
---
|
| 84 |
+
|
| 85 |
+
## π Key Files
|
| 86 |
+
|
| 87 |
+
- `Time_Series_Forecasting_β_Stock_Prices.ipynb` β Main notebook with full workflow
|
| 88 |
+
- `world_stock_prices_2_years.csv` β Example filtered dataset for a single stock
|
| 89 |
+
|
| 90 |
+
---
|
| 91 |
+
|
| 92 |
+
## β¨ Future Improvements
|
| 93 |
+
|
| 94 |
+
- Add Prophet model for easier seasonality handling.
|
| 95 |
+
- Incorporate financial indicators (RSI, MACD) as exogenous features.
|
| 96 |
+
- Deploy as a web dashboard with live forecasts.
|
| 97 |
+
|
| 98 |
+
---
|
| 99 |
+
|
| 100 |
+
## π License
|
| 101 |
+
|
| 102 |
+
This project is for educational and research purposes only. Not financial advice.
|