The Open-Source MRV Library for Model Risk

Models that classify markets into states like "calm" or "crisis" can produce different labels depending on which features you feed them, and your current validation doesn't catch this.

mrv-lib fixes this.

$ pip install mrv-lib
Quick start

Built for SR 11-7 / Basel IV (FRTB) Model Risk Governance

What is mrv-lib?

mrv-lib (also known as the MRV Library) is an open-source Python library for model risk validation (MRV) in quantitative finance. It tests whether regime-classification models — such as GMM and HMM — produce stable labels when you change the input features, data frequency, or number of states. If you are looking for an MRV lib that automates SR 11-7 / Basel IV (FRTB) model stability checks, mrv-lib is designed for exactly that.

The problem nobody checks for

Most classification models (GMM, HMM) are validated on in-sample fit metrics (BIC, log-likelihood). Nobody asks:
Do the labels survive a change in input representation?

1

You fit a classification model

GMM, HMM, or any clustering method on volatility, drawdown, VaR, CVaR, and other risk factors to identify market states.

2

You get state labels

"Low risk", "Medium risk", "Crisis" — neat categories that drive risk limits, capital allocation, and hedging decisions.

3

But swap one factor...

Replace max drawdown with realized skewness, and the labels change. Same data, same model, different answers.

If downstream decisions depend on model labels, but the labels depend on an arbitrary feature choice, then your decisions are not well-founded. SR 11-7 requires you to document this.

How it works

Fit the same model on multiple factor sets, then measure pairwise label agreement.

Time-series data
Factor sets
GMM / HMM
ARI matrix
Verdict

Two-layer verdict

Partition stability

Adjusted Rand Index (ARI) ≥ 0.65

Are the labels the same?

Ordering stability

Spearman rank correlation ≥ 0.85

Do they at least rank risk consistently?

A model that fails partition but passes ordering means: exact label boundaries shift, but relative risk ranking is preserved. Less severe, but still a material finding for SR 11-7 documentation.

The Model Risk Index

Drag the timeline to explore model stability across 20 years and 9 asset classes.

MRI formula: MRI = ρ_S · ∏(1 − RSS_k) across representation, resolution, and cross-identification dimensions
|
--
Price MRI | Pass Warning Breach
Drag to pan · Scroll to zoom · Dbl-click to reset

Features

Everything you need to validate model stability.

7 built-in risk factors

Volatility, drawdown, max drawdown, VaR, CVaR, realized skewness, stability (vol-of-vol). Extensible registry.

GMM & HMM models

Gaussian Mixture and Hidden Markov built-in. Plug in your own via register_model().

5 comparison metrics

ARI, AMI, NMI, Variation of Information, and Spearman ordering consistency.

PDF report generation

JSON → LaTeX → PDF. Professional reports with dashboards, heatmaps, and remediation plan.

Config-driven pipeline

Single YAML config. 6-step modular pipeline: download → load → factors → fit → validate → report.

IB Gateway integration

Download 5m/15m/1h/1d bars from Interactive Brokers. Incremental updates, multi-asset.

Quick start

Three commands to your first representation invariance report. Or use the Python API for full control. No IB account? Use the example notebook with synthetic data.

CLI
# Install
pip install mrv-lib[all]

# Download data (requires IB Gateway)
python run.py download config.yaml

# Run representation invariance test + PDF report
python run.py run config.yaml rep

# Regenerate PDF from existing results
python run.py report
Python
from mrv.pipeline import run, download

download("config.yaml")      # fetch data from IB
run("config.yaml", "rep")    # validate + PDF report

# Or step by step (full control)
from mrv.pipeline import load_data, compute_factors
from mrv.pipeline import fit_labels, validate, report
from mrv.utils.config import load

cfg = load("config.yaml")
prices = load_data(cfg, "rep")
factors = compute_factors(prices, cfg, factor_sets)
labels = fit_labels(factors, model="gmm")
result = validate(cfg, "rep", labels=labels)
report(result["json_path"], cfg=cfg)

Roadmap

Each release corresponds to a research paper. The library grows with the research.

Representation Invariance

Released v0.1.0

Do model labels change when you use different risk factors?

Zheng, Low & Wang (2026). Regime Labels Are Not Representation-Invariant: Implications for Model Risk Governance. FRL under review. DOI

Resolution Invariance

Released v0.2.0

Do labels agree across 5m / 1h / 1d frequencies?

Zheng, Low & Wang (2026). Regime Labels Are Not Resolution-Invariant: Evidence from the 2026 US–Iran Escalation. FRL under review. DOI

MRI - Model Risk Index

In progress v0.3.0

A single score quantifying how stable model labels are across perturbations. Live dashboard above.

Zheng, Low & Wang (2026). The Model Risk Index: Quantifying Inference Collapse and Ordinal Invariance across Representations and Resolutions. In preparation.

Research

mrv-lib is built on PhD research from Massey University and Bond University.

Regime Labels Are Not Representation-Invariant: Implications for Model Risk Governance

Zheng, K., Low, R. & Wang, R. (2026)

FRL Under Review DOI: 10.2139/ssrn.6460809

Regime Labels Are Not Resolution-Invariant: Evidence from the 2026 US–Iran Escalation

Zheng, K., Low, R. & Wang, R. (2026)

FRL Under Review DOI: 10.2139/ssrn.6531002

The Model Risk Index: Quantifying Inference Collapse and Ordinal Invariance across Representations and Resolutions

Zheng, K., Low, R. & Wang, R. (2026)

In progress

Kai Zheng — Tech Lead, Datacom · PhD candidate, Massey University

A/Prof. Rand Low — Bond Business School, Bond University

Prof. Ruili Wang — School of Mathematical and Computational Sciences, Massey University

FAQ

What is mrv-lib?

mrv-lib is an open-source Python library for model risk validation (MRV). It tests whether regime-classification labels produced by models like GMM and HMM are stable across different feature representations, data resolutions, and perturbations. It is built for SR 11-7 and Basel IV (FRTB) governance workflows.

How do I install mrv-lib?

Install from PyPI with pip install mrv-lib. For the full feature set including PDF report generation and IB Gateway integration, use pip install mrv-lib[all].

What does MRV stand for?

MRV stands for Model Risk Validation. The mrv-lib library (or MRV library) provides automated tools to validate model stability, specifically whether regime labels survive changes in feature choice, data frequency, and model configuration.

What is the Model Risk Index (MRI)?

The Model Risk Index is a single composite score (0–100) produced by mrv-lib that quantifies how stable a model's regime labels are. It combines representation stability, resolution stability, and ordinal robustness into one number. An MRI above 80 means labels are stable; below 60 signals a breach.

Is mrv-lib free?

Yes. mrv-lib is released under the MIT License and is completely free and open-source. The source code is hosted on GitHub under the ModelGuard Lab organisation.