PROTECTED SOURCE SCRIPT

QUANTA - LAB HMM REGIME DETECTION

22
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

Thông báo miễn trừ trách nhiệm

Thông tin và các ấn phẩm này không nhằm mục đích, và không cấu thành, lời khuyên hoặc khuyến nghị về tài chính, đầu tư, giao dịch hay các loại khác do TradingView cung cấp hoặc xác nhận. Đọc thêm tại Điều khoản Sử dụng.