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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: mit
|
| 3 |
+
tags:
|
| 4 |
+
- finance
|
| 5 |
+
- machine-learning
|
| 6 |
+
- mlops
|
| 7 |
+
- xgboost
|
| 8 |
+
- market-prediction
|
| 9 |
+
- trading
|
| 10 |
+
- risk-management
|
| 11 |
+
- time-series
|
| 12 |
+
library_name: xgboost
|
| 13 |
+
pipeline_tag: tabular-classification
|
| 14 |
+
---
|
| 15 |
+
|
| 16 |
+
# π Market Regime Classifier - XGBoost Model
|
| 17 |
+
|
| 18 |
+
This is a production-ready XGBoost model for predicting market regimes (RISK_ON/RISK_OFF) in Indian financial markets (NIFTY 50).
|
| 19 |
+
Part of a complete **MLOps pipeline** with experiment tracking, data versioning, and automated deployment.
|
| 20 |
+
|
| 21 |
+
## π― Model Description
|
| 22 |
+
|
| 23 |
+
**Task:** Binary Classification
|
| 24 |
+
**Algorithm:** XGBoost (Extreme Gradient Boosting)
|
| 25 |
+
**Target:** Market Regime Prediction (RISK_ON vs RISK_OFF)
|
| 26 |
+
**Framework:** MLflow for experiment tracking and model registry
|
| 27 |
+
|
| 28 |
+
### What are Market Regimes?
|
| 29 |
+
|
| 30 |
+
- **π’ RISK_ON**: Favorable market conditions - lower volatility, bullish momentum, suitable for aggressive trading
|
| 31 |
+
- **π΄ RISK_OFF**: Cautious conditions - higher volatility, defensive positioning advised
|
| 32 |
+
|
| 33 |
+
## π Model Performance
|
| 34 |
+
|
| 35 |
+
### ML Metrics
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
### Finance Metrics (Backtesting)
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
### Production Thresholds
|
| 48 |
+
- β
F1 Score β₯ 0.65
|
| 49 |
+
- β
Sharpe Ratio β₯ 0.5
|
| 50 |
+
|
| 51 |
+
## π§ Features Used
|
| 52 |
+
|
| 53 |
+
The model uses four key technical indicators:
|
| 54 |
+
|
| 55 |
+
1. **India VIX** - Volatility index (market fear/greed indicator)
|
| 56 |
+
2. **RSI (14-day)** - Relative Strength Index (momentum)
|
| 57 |
+
3. **50-Day MA** - Short-term moving average (trend)
|
| 58 |
+
4. **200-Day MA** - Long-term moving average (trend)
|
| 59 |
+
|
| 60 |
+
## π» Usage
|
| 61 |
+
|
| 62 |
+
### Using with MLflow
|
| 63 |
+
|
| 64 |
+
```python
|
| 65 |
+
import mlflow
|
| 66 |
+
import pandas as pd
|
| 67 |
+
|
| 68 |
+
# Load the model
|
| 69 |
+
model_uri = "models:/market_regime_classifier/Production"
|
| 70 |
+
model = mlflow.xgboost.load_model(model_uri)
|
| 71 |
+
|
| 72 |
+
# Prepare features
|
| 73 |
+
features = pd.DataFrame([{
|
| 74 |
+
'india_vix': 15.5,
|
| 75 |
+
'rsi_14': 55.3,
|
| 76 |
+
'ma_50': 18500.25,
|
| 77 |
+
'ma_200': 18200.75
|
| 78 |
+
}])
|
| 79 |
+
|
| 80 |
+
# Predict
|
| 81 |
+
prediction = model.predict(features)[0]
|
| 82 |
+
proba = model.predict_proba(features)[0]
|
| 83 |
+
|
| 84 |
+
regime = "RISK_ON" if prediction == 1 else "RISK_OFF"
|
| 85 |
+
confidence = proba[prediction]
|
| 86 |
+
|
| 87 |
+
print(f"Regime: {regime} (confidence: {confidence:.2%})")
|
| 88 |
+
```
|
| 89 |
+
|
| 90 |
+
### Using via REST API
|
| 91 |
+
|
| 92 |
+
The model is deployed on Hugging Face Spaces with a FastAPI endpoint:
|
| 93 |
+
|
| 94 |
+
```bash
|
| 95 |
+
curl -X POST "https://AAdevloper-mlops-finance-pipeline.hf.space/predict_regime" \
|
| 96 |
+
-H "Content-Type: application/json" \
|
| 97 |
+
-d '{
|
| 98 |
+
"india_vix": 15.5,
|
| 99 |
+
"rsi_14": 55.3,
|
| 100 |
+
"ma_50": 18500.25,
|
| 101 |
+
"ma_200": 18200.75
|
| 102 |
+
}'
|
| 103 |
+
```
|
| 104 |
+
|
| 105 |
+
## ποΈ MLOps Pipeline
|
| 106 |
+
|
| 107 |
+
This model is part of a complete MLOps system:
|
| 108 |
+
|
| 109 |
+
### Components
|
| 110 |
+
- β
**MLflow**: Experiment tracking and model registry
|
| 111 |
+
- β
**DVC**: Data version control
|
| 112 |
+
- β
**GitHub Actions**: Automated CI/CD pipeline
|
| 113 |
+
- β
**FastAPI**: REST API for model serving
|
| 114 |
+
- β
**Docker**: Containerized deployment
|
| 115 |
+
- β
**Hugging Face Spaces**: Cloud deployment
|
| 116 |
+
|
| 117 |
+
### Training Pipeline
|
| 118 |
+
1. Data preprocessing and feature engineering
|
| 119 |
+
2. Train/test split with stratification
|
| 120 |
+
3. XGBoost training with hyperparameters
|
| 121 |
+
4. Model evaluation (ML + Finance metrics)
|
| 122 |
+
5. Backtesting on historical data
|
| 123 |
+
6. Model registration in MLflow
|
| 124 |
+
7. Promotion to production if thresholds met
|
| 125 |
+
|
| 126 |
+
### Automated Retraining
|
| 127 |
+
- Scheduled weekly retraining (GitHub Actions)
|
| 128 |
+
- Automatic model promotion based on performance
|
| 129 |
+
- Version control for models and data
|
| 130 |
+
|
| 131 |
+
## π Training Configuration
|
| 132 |
+
|
| 133 |
+
```yaml
|
| 134 |
+
model:
|
| 135 |
+
type: xgboost
|
| 136 |
+
params:
|
| 137 |
+
max_depth: 6
|
| 138 |
+
learning_rate: 0.1
|
| 139 |
+
n_estimators: 100
|
| 140 |
+
objective: binary:logistic
|
| 141 |
+
eval_metric: logloss
|
| 142 |
+
```
|
| 143 |
+
|
| 144 |
+
## π Dataset
|
| 145 |
+
|
| 146 |
+
- **Source**: Synthetic market data for NIFTY 50
|
| 147 |
+
- **Features**: India VIX, RSI-14, MA-50, MA-200
|
| 148 |
+
- **Target**: Market regime (binary classification)
|
| 149 |
+
- **Split**: 80/20 train/test
|
| 150 |
+
|
| 151 |
+
## π Skills Demonstrated
|
| 152 |
+
|
| 153 |
+
- MLOps pipeline architecture
|
| 154 |
+
- Experiment tracking (MLflow)
|
| 155 |
+
- Model registry management
|
| 156 |
+
- Data versioning (DVC)
|
| 157 |
+
- CI/CD automation (GitHub Actions)
|
| 158 |
+
- Model serving (FastAPI)
|
| 159 |
+
- Financial metrics & backtesting
|
| 160 |
+
- Docker containerization
|
| 161 |
+
- Cloud deployment (Hugging Face)
|
| 162 |
+
|
| 163 |
+
## π Project Links
|
| 164 |
+
|
| 165 |
+
- **GitHub Repository**: [mlops-finance-pipeline](https://github.com/AAdevloper/mlops-finance-pipeline)
|
| 166 |
+
- **Live API Demo**: [Hugging Face Space](https://huggingface.co/spaces/AAdevloper/mlops-finance-pipeline)
|
| 167 |
+
- **Documentation**: Full README with setup instructions
|
| 168 |
+
|
| 169 |
+
## π Model Versioning
|
| 170 |
+
|
| 171 |
+
This model is version-controlled using MLflow Model Registry:
|
| 172 |
+
- **Model Name**: market_regime_classifier
|
| 173 |
+
- **Version**: 1
|
| 174 |
+
- **Stage**: Production
|
| 175 |
+
- **Run ID**: 43544e1ed8eb4c2a9268948b6795bdf5
|
| 176 |
+
|
| 177 |
+
## π€ Contributing
|
| 178 |
+
|
| 179 |
+
This is a portfolio project demonstrating MLOps best practices. Feel free to:
|
| 180 |
+
- Fork and experiment
|
| 181 |
+
- Submit issues or suggestions
|
| 182 |
+
- Use as reference for your own MLOps projects
|
| 183 |
+
|
| 184 |
+
## π License
|
| 185 |
+
|
| 186 |
+
MIT License - free to use for learning and projects
|
| 187 |
+
|
| 188 |
+
---
|
| 189 |
+
|
| 190 |
+
**Built with β€οΈ to showcase MLOps skills in Finance**
|
| 191 |
+
|
| 192 |
+
*For questions or collaboration, visit the [GitHub repository](https://github.com/AAdevloper/mlops-finance-pipeline)*
|
config.yaml
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
api:
|
| 2 |
+
host: 0.0.0.0
|
| 3 |
+
port: 7860
|
| 4 |
+
reload: false
|
| 5 |
+
backtest:
|
| 6 |
+
initial_capital: 100000
|
| 7 |
+
position_size: 1.0
|
| 8 |
+
risk_free_rate: 0.05
|
| 9 |
+
data:
|
| 10 |
+
features:
|
| 11 |
+
- india_vix
|
| 12 |
+
- rsi_14
|
| 13 |
+
- ma_50
|
| 14 |
+
- ma_200
|
| 15 |
+
path: data/market_regime_data_nifty50.csv
|
| 16 |
+
random_state: 42
|
| 17 |
+
target: regime
|
| 18 |
+
test_size: 0.2
|
| 19 |
+
mlflow:
|
| 20 |
+
experiment_name: market_regime_prediction
|
| 21 |
+
registered_model_name: market_regime_classifier
|
| 22 |
+
tracking_uri: ./mlruns
|
| 23 |
+
model:
|
| 24 |
+
name: xgboost_market_regime
|
| 25 |
+
params:
|
| 26 |
+
eval_metric: logloss
|
| 27 |
+
learning_rate: 0.1
|
| 28 |
+
max_depth: 6
|
| 29 |
+
n_estimators: 100
|
| 30 |
+
objective: binary:logistic
|
| 31 |
+
random_state: 42
|
| 32 |
+
type: xgboost
|
| 33 |
+
thresholds:
|
| 34 |
+
min_f1_score: 0.65
|
| 35 |
+
min_sharpe_ratio: 0.5
|
metrics.json
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"backtest_max_drawdown": -0.2939306903526135,
|
| 3 |
+
"backtest_sharpe_ratio": 1.0079896816731886,
|
| 4 |
+
"backtest_total_return": 0.6487209877779612,
|
| 5 |
+
"backtest_win_rate": 0.5486284289276808,
|
| 6 |
+
"final_portfolio_value": 164872.0987777961,
|
| 7 |
+
"test_accuracy": 0.5727069351230425,
|
| 8 |
+
"test_f1_score": 0.6924315619967794,
|
| 9 |
+
"test_precision": 0.5361596009975063,
|
| 10 |
+
"test_recall": 0.9772727272727273,
|
| 11 |
+
"train_accuracy": 0.9737136465324385
|
| 12 |
+
}
|