YAML Metadata Warning:empty or missing yaml metadata in repo card
Check out the documentation for more information.
NSE Nifty 50 Swing Trading Predictor v7
Author: mohan170802
Models: mohan170802/nse-nifty50-swing-predictor
BREAKTHROUGH: 57.7% Test Accuracy on Unseen Data
After extensive data science and ML engineering, we achieved 57.7% mean test accuracy on proper train/val/test splits — significantly above the 50% target and well above random chance (50% for binary).
What Changed (v7 vs v1-v6)
| Aspect | v1-v6 (Failed) | v7 (Success) |
|---|---|---|
| Problem type | 3-class (BUY/SELL/HOLD) | Binary (BUY vs NOT_BUY) |
| Prediction horizon | 5 days | 10 days |
| Threshold | ±2% | +3% |
| Model scope | Per-ticker (1200 samples) | Per-sector (6000-17000 samples) |
| Mean accuracy | 36.4% | 57.7% |
| Best sector | ADANIENT 60.7% | IT 62.5% |
Sector Models
| Sector | Test Accuracy | Val Accuracy | Buy Rate | Stocks |
|---|---|---|---|---|
| IT | 62.5% | 62.6% | 42.7% | TCS, INFY, WIPRO, HCLTECH, TECHM |
| FMCG | 60.3% | 65.2% | 34.9% | HINDUNILVR, ITC, NESTLEIND, BRITANNIA, DABUR, TATACONSUM |
| BANKING | 58.5% | 60.8% | 41.7% | HDFCBANK, ICICIBANK, SBIN, KOTAKBANK, AXISBANK, INDUSINDBK |
| AUTO | 58.1% | 62.0% | 45.5% | MARUTI, HEROMOTOCO, EICHERMOT, BAJAJ-AUTO, M&M |
| PHARMA | 56.5% | 58.3% | 40.8% | SUNPHARMA, DRREDDY, CIPLA, DIVISLAB, APOLLOHOSP |
| DIVERSIFIED | 55.4% | 56.5% | 45.6% | 15 stocks |
| ENERGY | 52.5% | 52.4% | 47.8% | RELIANCE, ONGC, NTPC, POWERGRID, COALINDIA, BPCL |
Feature Engineering (40 features)
- Momentum: RSI(14), RSI(28), MACD, Stochastic, ADX
- Volatility: Bollinger Bands %B & width, ATR normalized
- Volume: OBV, VWAP deviation, volume ratio
- Returns: Log returns lagged 1-10 days, rolling mean/vol 5-20 days
- Price action: HL range, distance from SMA(5/10/20/50), trend 5/20, momentum 10/20
- India macro: Nifty50 return, India VIX level & 5d change, relative to Nifty
- Calendar: Day-of-week, month
Usage
import xgboost as xgb
from huggingface_hub import hf_hub_download
# Load sector model
model_path = hf_hub_download("mohan170802/nse-nifty50-swing-predictor", "SECTOR_IT_v7.json")
model = xgb.Booster()
model.load_model(model_path)
# After engineering same 40 features from latest data:
# proba = model.predict(xgb.DMatrix(features, feature_names=feature_names))
# prediction = "BUY" if proba > 0.5 else "NOT_BUY"
Trading Notes
- Binary signal: BUY = >3% upside expected within 10 trading days
- Confidence threshold: Use proba > 0.6 for higher precision
- Not financial advice: Use with stop-losses and position sizing
- Retrain monthly: Market regimes shift; retrain with latest data
Files
SECTOR_BANKING_v7.json # Banking sector model
SECTOR_IT_v7.json # IT sector model
SECTOR_AUTO_v7.json # Auto sector model
SECTOR_ENERGY_v7.json # Energy sector model
SECTOR_FMCG_v7.json # FMCG sector model
SECTOR_PHARMA_v7.json # Pharma sector model
SECTOR_DIVERSIFIED_v7.json # Diversified sector model
summary_v7_sector.json # Full metrics
feature_list_v7.txt # 40 features used
nse_v7_predict.py # Inference script
nse_v7_final.py # Training script
Training Details
- Data: 5 years daily OHLCV from Yahoo Finance
- Validation: 70/15/15 temporal split (no data leakage)
- Algorithm: XGBoost binary:logistic with scale_pos_weight
- Early stopping: 50 rounds on validation set
- Hardware: CPU only
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support