File size: 3,082 Bytes
4414d79
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# πŸ“ˆ Time Series Forecasting – Stock Prices

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**.

---

## πŸ“‚ Project Overview

The notebook walks through the end-to-end pipeline of forecasting stock prices:

1. **Dataset Acquisition**  
   - Uses the Kaggle dataset: *World Stock Prices – Daily Updating*  
   - Downloaded via `kagglehub`  

2. **Preprocessing**  
   - Convert `Date` column to datetime and set as index.  
   - Sort data by date.  
   - Filter for a single stock (default: **AAPL**).  
   - Handle missing values using forward-fill / interpolation.  

3. **Exploratory Data Analysis (EDA)**  
   - Visualize stock closing prices over time.  
   - Check for stationarity (ADF test).  
   - Plot ACF/PACF to guide ARIMA orders.  

4. **Modeling Approaches**  
   - **ARIMA**: Baseline forecasting with manually selected parameters.  
   - **Auto-ARIMA**: Automated parameter tuning using AIC/BIC.  
   - **SARIMAX**: Seasonal ARIMA with exogenous variables (optional).  
   - **LSTM**: Deep learning model for sequence prediction.  

5. **Forecast Evaluation**  
   - Implement **rolling window forecasting**:  
     - Train on initial window β†’ Forecast one step ahead β†’ Update with true value β†’ Repeat.  
   - Evaluate models using metrics:  
     - RMSE, MAE, MAPE  

---

## βš™οΈ Installation & Requirements

Install dependencies:

```bash
pip install pandas numpy matplotlib seaborn scikit-learn statsmodels pmdarima tensorflow kagglehub
```

If running in **Google Colab**, you may also need:

```bash
pip install kagglehub
```

---

## πŸš€ Usage

1. Clone or download the notebook:
   ```bash
   git clone <repo-link>
   cd stock-forecasting
   ```

2. Run the Jupyter Notebook:
   ```bash
   jupyter notebook "Time_Series_Forecasting_–_Stock_Prices.ipynb"
   ```

3. Inside the notebook:
   - Change the stock ticker (`ticker_symbol = 'AAPL'`) to forecast other stocks.  
   - Choose between **ARIMA / SARIMAX / LSTM** sections.  
   - Run evaluation cells to compare results.  

---

## πŸ“Š Results

- **ARIMA** works well for short-term stationary series.  
- **SARIMAX** captures seasonality but is computationally heavier.  
- **LSTM** adapts to nonlinear patterns, showing better performance for long-term forecasts.  
- Rolling window evaluation provides realistic performance assessment compared to a single train-test split.  

---

## πŸ“Œ Key Files

- `Time_Series_Forecasting_–_Stock_Prices.ipynb` β†’ Main notebook with full workflow  
- `world_stock_prices_2_years.csv` β†’ Example filtered dataset for a single stock  

---

## ✨ Future Improvements

- Add Prophet model for easier seasonality handling.  
- Incorporate financial indicators (RSI, MACD) as exogenous features.  
- Deploy as a web dashboard with live forecasts.  

---

## πŸ“œ License

This project is for educational and research purposes only. Not financial advice.