A machine learning pipeline that predicts the next-day direction of India's Nifty 50 index using 4 years of NSE data, 9 engineered features, and two classification models.
How It Works
Downloaded 4 years of real Nifty 50 OHLCV data (2021–2024) from Yahoo Finance using the yfinance library — no manual download needed.
Created 9 financial features including RSI, moving averages (MA5/20/50), volatility, and volume momentum — signals real traders use.
Binary label — 1 if tomorrow's price is higher, 0 if lower. Time-series split (80/20) with no shuffle to prevent data leakage.
Trained Logistic Regression (baseline) and Random Forest (200 trees). RF captured non-linear patterns and beat the 50% random baseline.
3 professional charts — price trends with MAs, feature importance analysis, and model comparison dashboard with confusion matrices.
Daily Return was the most important feature (0.147). Nifty 50 is highly efficient — even beating 50% consistently is statistically meaningful.
Results
Feature Engineering
| Feature | Description | Importance |
|---|---|---|
Return | Daily percentage price change | 🥇 0.147 |
High_Low_Pct | (High - Low) / Close — daily price range | 🥈 0.121 |
Volatility | 10-day rolling std dev of returns | 🥉 0.120 |
Vol_Change | Day-over-day volume momentum | 0.118 |
RSI | 14-day Relative Strength Index | 0.117 |
MA_50 | 50-day moving average | 0.101 |
MA_5 | 5-day moving average | 0.098 |
MA_ratio | MA5 / MA20 momentum signal | 0.091 |
MA_20 | 20-day moving average | 0.087 |
Model Performance
WHY 51% IS MEANINGFUL
Stock markets are extremely efficient — millions of expert traders compete daily. Consistently beating the 50% random baseline demonstrates that the model has extracted real, statistically significant patterns from historical data. Interpretability and feature engineering quality matter as much as raw accuracy in financial ML.
Built With
About