Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🇮🇳 India Sector Rotation Intelligence Engine

An end-to-end ML-powered system that reads Indian macroeconomic regimes and predicts optimal Nifty sector allocation — with backtested outperformance vs NIFTY 50.


📊 Backtest Results

Metric Strategy NIFTY 50
CAGR 71.98% 9.48%
Sharpe Ratio 2.72 0.64
Max Drawdown -16.23% -29.62%
Hit Rate 70.9%

🧠 What It Does

  1. Pulls live Indian market data — 8 Nifty sector indices, NIFTY 50, USD/INR, India VIX via yfinance
  2. Engineers macro features — VIX regime, NIFTY momentum, USD/INR trend
  3. Classifies macro regime — Expansion, Slowdown, Contraction, Stagflation using Random Forest (98.3% accuracy)
  4. Ranks sectors per regime — Random Forest regressors predict forward 1-month sector returns
  5. Constructs model portfolio — Equal weight across top 3 ranked sectors, monthly rebalancing
  6. Backtests vs NIFTY 50 — CAGR, Sharpe Ratio, Max Drawdown, Hit Rate
  7. Visualizes everything — Excel dashboard, 6 PNG charts

🗂️ Project Structure


⚙️ How To Run

Step 1 — Install dependencies

pip install pandas numpy matplotlib seaborn scikit-learn yfinance shap openpyxl jupyter

Step 2 — Run the full pipeline

python src/pipeline.py
python src/feature_engineering.py
python src/train_model.py
python src/backtest.py
python src/visualize.py
python src/excel_dashboard.py

📦 Data Sources

Source Data
yfinance 8 Nifty sector indices, NIFTY 50 benchmark
yfinance USD/INR exchange rate, India VIX

🤖 ML Architecture

Model 1 — Regime Classifier

  • Algorithm: Random Forest (multiclass)
  • Features: VIX regime, NIFTY momentum (3M/6M/12M), USD/INR trend
  • Output: Expansion / Slowdown / Contraction / Stagflation
  • Accuracy: 98.3% (cross-validated)

Model 2 — Sector Ranker

  • Algorithm: Random Forest Regressor (per regime)
  • Target: Forward 1-month sector return
  • Output: Ranked list of 8 sectors
  • Portfolio: Equal weight in top 3 sectors, monthly rebalanced

📈 Macro Regime Logic

Regime Conditions Top Sectors
Expansion NIFTY above MA, low VIX, positive momentum Auto, Realty, Metal
Slowdown NIFTY slowing, elevated VIX Pharma, FMCG
Contraction NIFTY below MA, high VIX Pharma, FMCG, Infra
Stagflation NIFTY down, INR weakening Energy, Metal

🛠️ Tech Stack

  • Python — pandas, numpy, scikit-learn, yfinance, shap, matplotlib, openpyxl
  • ML — Random Forest classifier + regressors, SHAP explainability
  • Visualization — matplotlib (dark theme charts), openpyxl (Excel dashboard)
  • Data — yfinance API (NSE indices)

👤 Author

Manav BTech CSE + MBA — Nirma University, Ahmedabad (2029) Targeting Investment Banking & Strategy Consulting


💬 One-Line Pitch

"I built a system that reads Indian macroeconomic regimes using live market data and predicts optimal Nifty sector allocation using machine learning — with a backtested portfolio delivering 71.98% CAGR vs 9.48% for NIFTY 50."

About

ML - powered India sector rotation engine - detects macro regimes using Random Forest and predicts optimal Nifty sector allocation. CAGR 71.98% vs 9.48% NIFTY 50 over 15 years.

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages