π 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:
- India VIX - Volatility index (market fear/greed indicator)
- RSI (14-day) - Relative Strength Index (momentum)
- 50-Day MA - Short-term moving average (trend)
- 200-Day MA - Long-term moving average (trend)
π» Usage
Using with MLflow
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:
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
- Data preprocessing and feature engineering
- Train/test split with stratification
- XGBoost training with hyperparameters
- Model evaluation (ML + Finance metrics)
- Backtesting on historical data
- Model registration in MLflow
- 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
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
- Live API Demo: Hugging Face Space
- 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
- Downloads last month
- 2