An end-to-end MLOps pipeline for intraday realized-volatility forecasting — synthetic data → feature engineering → walk-forward training with MLflow tracking → conformalised FastAPI inference → Prometheus/Grafana monitoring → drift detection → Rust backtester. The repository is structured to demonstrate the full machine-learning engineering lifecycle on a stock-market problem: turning streaming OHLCV bars into calibrated, uncertainty-aware variance forecasts that a trading service could actually consume.
┌──────────────────────────────────────────────────────┐
│ intraday-vol-mlops pipeline │
└──────────────────────────────────────────────────────┘
┌─────────────┐ ┌───────────────┐ ┌────────────────┐ ┌─────────────────┐
│ Synthetic │───▶│ Feature │───▶│ Walk-forward │───▶│ Model Registry │
│ OHLCV gen │ │ pipeline │ │ training │ │ (joblib bundle)│
│ (GBM+GARCH+ │ │ (sklearn) │ │ + conformal │ │ + MLflow runs │
│ regimes) │ │ │ │ + metrics │ │ │
└─────────────┘ └───────────────┘ └────────────────┘ └─────────────────┘
│ │ │ │
│ │ │ ▼
│ │ │ ┌──────────────────┐
│ │ │ │ FastAPI service │
│ │ │ │ /score /healthz │
│ │ │ │ /metrics (Prom) │
│ │ │ └──────────────────┘
│ │ │ │
│ │ ▼ ▼
│ │ ┌──────────────────┐ ┌──────────────────┐
│ └──────────▶│ Drift detector │ │ Rust backtester │
│ │ (PSI + KS CLI) │ │ POSTs /score, │
└──────────────────────────────▶│ │ │ vol-targets, │
└──────────────────┘ │ PnL vs B&H │
└──────────────────┘
│
▼
┌────────────────────┐
│ Prometheus + │
│ Grafana dashboard │
└────────────────────┘
# 1. Install (editable, with dev extras)
pip install -e ".[dev]"
# 2. Generate synthetic bars + labels
intraday-vol generate-data --output data/raw/synth.parquet --n-bars 6500
# 3. Train (writes model + conformal bundles to models/latest/)
intraday-vol train --model lightgbm --data-path data/raw/synth.parquet
# 4. Run the inference service locally
intraday-vol serve --port 8000
# 5. In another terminal: probe it
curl -s localhost:8000/healthz
curl -s -X POST localhost:8000/score \
-H 'content-type: application/json' \
--data @examples/sample_score_request.json | jq
# 6. Full stack (API + Prometheus + Grafana) via Docker
docker compose up --build
# Grafana: http://localhost:3000 (anonymous Viewer enabled)| Name | Family | Features | Calibrated [0,1] head | Interval |
|---|---|---|---|---|
lightgbm |
Gradient boosting | 27 tabular features | Platt-scaled logistic on ŷ | Conformal |
xgboost |
Gradient boosting | 27 tabular features | Platt-scaled logistic on ŷ | Conformal |
lstm |
PyTorch 1-layer LSTM | 11-feature sequence | Platt-scaled logistic on ŷ | Conformal |
All three implement the same BaseModel interface (fit, predict,
predict_proba_high_vol, save, load), share the joblib bundle format
({model, scaler, feature_order, calibrator, metadata}), and are
swappable via the --model flag in the training CLI.
| Layer | Lives in | Notes |
|---|---|---|
| Schemas | src/intraday_vol/schemas.py |
Pydantic v2; OHLC + payload validation; shared with the Rust client. |
| Data | src/intraday_vol/data/ |
GBM + GARCH(1,1) + Markov regimes + Poisson jumps + diurnal U-shape. |
| Features | src/intraday_vol/features/ |
Sklearn transformers; tabular + sequence feature columns. |
| Models | src/intraday_vol/models/ |
LightGBM, XGBoost, PyTorch LSTM behind a single interface. |
| Training | src/intraday_vol/training/ |
Chrono splits, walk-forward, metrics, split-conformal. |
| Inference | src/intraday_vol/inference/ |
FastAPI + Prometheus instrumentation. |
| Drift | src/intraday_vol/drift/ |
PSI + two-sample KS, with a CLI for baseline-vs-current comparisons. |
| CLI | src/intraday_vol/cli.py |
`generate-data |
| Observability | prometheus/, grafana/ |
Provisioned datasource + dashboard JSON. |
| Rust backtester | rust-backtester/ |
Vol-targeted backtest replaying bars through /score. |
| Tests | tests/ |
≥20 pytest tests covering data, features, models, drift, API, CLI. |
| CI | .github/workflows/ci.yml |
Ruff + AST parse + pytest + cargo build/test + docker build. |
- Point forecast: MAE and RMSE on log-variance, QLIKE on raw variance.
- High-vol classifier head: PR-AUC, ROC-AUC, precision@K (top-decile threshold).
- Intervals: coverage at 90% nominal, mean interval width (log scale).
See docs/MODEL_CARD.md for intended use, out-of-scope claims, and known limitations.
See docs/ARCHITECTURE.md for the deeper system design write-up.
MIT.