--- license: mit tags: - finance - machine-learning - mlops - xgboost - market-prediction - trading - risk-management - time-series library_name: xgboost pipeline_tag: tabular-classification --- # 🚀 Market Regime Classifier - XGBoost Model This is a production-ready XGBoost model for predicting market regimes (RISK_ON/RISK_OFF) in Indian financial markets (NIFTY 50). Part of a complete **MLOps pipeline** with experiment tracking, data versioning, and automated deployment. ## 🎯 Model Description **Task:** Binary Classification **Algorithm:** XGBoost (Extreme Gradient Boosting) **Target:** Market Regime Prediction (RISK_ON vs RISK_OFF) **Framework:** MLflow for experiment tracking and model registry ### What are Market Regimes? - **🟢 RISK_ON**: Favorable market conditions - lower volatility, bullish momentum, suitable for aggressive trading - **🔴 RISK_OFF**: Cautious conditions - higher volatility, defensive positioning advised ## 📊 Model Performance ### ML Metrics ### Finance Metrics (Backtesting) ### Production Thresholds - ✅ F1 Score ≥ 0.65 - ✅ Sharpe Ratio ≥ 0.5 ## 🔧 Features Used The model uses four key technical indicators: 1. **India VIX** - Volatility index (market fear/greed indicator) 2. **RSI (14-day)** - Relative Strength Index (momentum) 3. **50-Day MA** - Short-term moving average (trend) 4. **200-Day MA** - Long-term moving average (trend) ## 💻 Usage ### Using with MLflow ```python import mlflow import pandas as pd # Load the model model_uri = "models:/market_regime_classifier/Production" model = mlflow.xgboost.load_model(model_uri) # Prepare features features = pd.DataFrame([{ 'india_vix': 15.5, 'rsi_14': 55.3, 'ma_50': 18500.25, 'ma_200': 18200.75 }]) # Predict prediction = model.predict(features)[0] proba = model.predict_proba(features)[0] regime = "RISK_ON" if prediction == 1 else "RISK_OFF" confidence = proba[prediction] print(f"Regime: {regime} (confidence: {confidence:.2%})") ``` ### Using via REST API The model is deployed on Hugging Face Spaces with a FastAPI endpoint: ```bash curl -X POST "https://AAdevloper-mlops-finance-pipeline.hf.space/predict_regime" \ -H "Content-Type: application/json" \ -d '{ "india_vix": 15.5, "rsi_14": 55.3, "ma_50": 18500.25, "ma_200": 18200.75 }' ``` ## 🏗️ MLOps Pipeline This model is part of a complete MLOps system: ### Components - ✅ **MLflow**: Experiment tracking and model registry - ✅ **DVC**: Data version control - ✅ **GitHub Actions**: Automated CI/CD pipeline - ✅ **FastAPI**: REST API for model serving - ✅ **Docker**: Containerized deployment - ✅ **Hugging Face Spaces**: Cloud deployment ### Training Pipeline 1. Data preprocessing and feature engineering 2. Train/test split with stratification 3. XGBoost training with hyperparameters 4. Model evaluation (ML + Finance metrics) 5. Backtesting on historical data 6. Model registration in MLflow 7. Promotion to production if thresholds met ### Automated Retraining - Scheduled weekly retraining (GitHub Actions) - Automatic model promotion based on performance - Version control for models and data ## 📈 Training Configuration ```yaml model: type: xgboost params: max_depth: 6 learning_rate: 0.1 n_estimators: 100 objective: binary:logistic eval_metric: logloss ``` ## 📊 Dataset - **Source**: Synthetic market data for NIFTY 50 - **Features**: India VIX, RSI-14, MA-50, MA-200 - **Target**: Market regime (binary classification) - **Split**: 80/20 train/test ## 🎓 Skills Demonstrated - MLOps pipeline architecture - Experiment tracking (MLflow) - Model registry management - Data versioning (DVC) - CI/CD automation (GitHub Actions) - Model serving (FastAPI) - Financial metrics & backtesting - Docker containerization - Cloud deployment (Hugging Face) ## 📚 Project Links - **GitHub Repository**: [mlops-finance-pipeline](https://github.com/AAdevloper/mlops-finance-pipeline) - **Live API Demo**: [Hugging Face Space](https://huggingface.co/spaces/AAdevloper/mlops-finance-pipeline) - **Documentation**: Full README with setup instructions ## 🔄 Model Versioning This model is version-controlled using MLflow Model Registry: - **Model Name**: market_regime_classifier - **Version**: 1 - **Stage**: Production - **Run ID**: 43544e1ed8eb4c2a9268948b6795bdf5 ## 🤝 Contributing This is a portfolio project demonstrating MLOps best practices. Feel free to: - Fork and experiment - Submit issues or suggestions - Use as reference for your own MLOps projects ## 📄 License MIT License - free to use for learning and projects --- **Built with ❤️ to showcase MLOps skills in Finance** *For questions or collaboration, visit the [GitHub repository](https://github.com/AAdevloper/mlops-finance-pipeline)*