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
Skrypt chroniony
Ten skrypt został opublikowany jako zamknięty kod źródłowy. Można z tego korzystać swobodnie i bez żadnych ograniczeń — więcej informacji znajduje się tutaj.
Institutional-grade diagnostics: GARCH, HMM Regimes, Cointegration, Microstructure, Fractal Analysis | Research only
Wyłączenie odpowiedzialności
Informacje i publikacje nie stanowią i nie powinny być traktowane jako porady finansowe, inwestycyjne, tradingowe ani jakiekolwiek inne rekomendacje dostarczane lub zatwierdzone przez TradingView. Więcej informacji znajduje się w Warunkach użytkowania.
Skrypt chroniony
Ten skrypt został opublikowany jako zamknięty kod źródłowy. Można z tego korzystać swobodnie i bez żadnych ograniczeń — więcej informacji znajduje się tutaj.
Institutional-grade diagnostics: GARCH, HMM Regimes, Cointegration, Microstructure, Fractal Analysis | Research only
Wyłączenie odpowiedzialności
Informacje i publikacje nie stanowią i nie powinny być traktowane jako porady finansowe, inwestycyjne, tradingowe ani jakiekolwiek inne rekomendacje dostarczane lub zatwierdzone przez TradingView. Więcej informacji znajduje się w Warunkach użytkowania.