PROTECTED SOURCE SCRIPT
QUANTA - LAB HMM REGIME DETECTION

Two-state Hidden Markov Model for market regime detection based on Hamilton (1989) Markov-Switching framework.
Methodology:
Full Baum-Welch EM algorithm in log-space for numerical stability
Real-time Hamilton filtering (no lookahead) for trading use
Kim smoothing for historical analysis
Multiple random restarts to avoid local optima
Regime Classification:
Mean-based: R1 = Bearish (lower μ), R2 = Bullish (higher μ)
Volatility-based: R1 = Calm (lower σ), R2 = Turbulent (higher σ)
Key Features:
TRADING vs ANALYSIS mode (filtered vs smoothed probabilities)
Gaussian assumption diagnostics (kurtosis, skewness, outliers)
Data Quality Score (0-100)
Regime Certainty Index (RCI)
Mean separation t-statistic
Expected regime duration and ergodic probabilities
Degenerate model detection
Dashboard Includes:
Filtered probabilities (real-time, safe for trading)
Emission parameters (μ₁, μ₂, σ₁, σ₂)
Transition matrix (p₁₁, p₂₂)
Model fit metrics (LogL, AIC, BIC)
Critical Warnings:
Smoothed ≠ Real-time (smoothed uses future info)
Gaussian assumption: fat tails not captured
K=2 regimes only — may oversimplify dynamics
NOT for high-frequency (minimum 1H timeframe)
Validate with Python hmmlearn / R / MATLAB
References: Hamilton (1989) — Econometrica
Methodology:
Full Baum-Welch EM algorithm in log-space for numerical stability
Real-time Hamilton filtering (no lookahead) for trading use
Kim smoothing for historical analysis
Multiple random restarts to avoid local optima
Regime Classification:
Mean-based: R1 = Bearish (lower μ), R2 = Bullish (higher μ)
Volatility-based: R1 = Calm (lower σ), R2 = Turbulent (higher σ)
Key Features:
TRADING vs ANALYSIS mode (filtered vs smoothed probabilities)
Gaussian assumption diagnostics (kurtosis, skewness, outliers)
Data Quality Score (0-100)
Regime Certainty Index (RCI)
Mean separation t-statistic
Expected regime duration and ergodic probabilities
Degenerate model detection
Dashboard Includes:
Filtered probabilities (real-time, safe for trading)
Emission parameters (μ₁, μ₂, σ₁, σ₂)
Transition matrix (p₁₁, p₂₂)
Model fit metrics (LogL, AIC, BIC)
Critical Warnings:
Smoothed ≠ Real-time (smoothed uses future info)
Gaussian assumption: fat tails not captured
K=2 regimes only — may oversimplify dynamics
NOT for high-frequency (minimum 1H timeframe)
Validate with Python hmmlearn / R / MATLAB
References: Hamilton (1989) — Econometrica
Protected script
This script is published as closed-source. However, you can use it freely and without any limitations – learn more here.
Institutional-grade diagnostics: GARCH, HMM Regimes, Cointegration, Microstructure, Fractal Analysis | Research only
Disclaimer
The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.
Protected script
This script is published as closed-source. However, you can use it freely and without any limitations – learn more here.
Institutional-grade diagnostics: GARCH, HMM Regimes, Cointegration, Microstructure, Fractal Analysis | Research only
Disclaimer
The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.