Gaussian Hidden Markov Model for South African Rand currency crisis regime detection | Python, hmmlearn, scikit-learn | UCL COMP0040
# ZAR Currency Crisis Regime Detection — Gaussian HMM
> Unsupervised two-state Gaussian Hidden Markov Model for South African Rand structural stress detection
> Built with Python · hmmlearn · scikit-learn · NumPy · pandas
## Research Summary
**Individual coursework, COMP0040 Machine Learning for Financial Markets, UCL MSc Financial Technology (2026)**
This project applies a two-state Gaussian Hidden Markov Model (GHMM) to detect latent stress regimes in the South African Rand (ZAR) without using crisis labels during estimation. The GHMM is evaluated against a supervised Logistic Regression baseline and an Exchange Market Pressure (EMP) index, revealing a fundamental difference in the *timescale* of stress being detected rather than model failure.
**Key finding:** The GHMM identifies structural vulnerability episodes averaging **29 months**, anchored in South Africa's external balance dynamics (current-account-to-GDP ratio), whereas the EMP threshold captures acute 3–5 month crises driven by high-frequency FX movements.
## Technical Contributions
- **Self-contained GHMM derivation** — Forward-Backward algorithm, Baum-Welch M-step updates, Viterbi decoder, connected to the Kalman Filter via discrete-state analogy
- **EM degeneracy diagnosis and fix** — Absorbing-state pathology on imbalanced data (24% crisis months); Brier-score restart selection reduces mean FAR from 95.3% to 59.4% and raises median AUC from 0.517 to 0.608
- **Synthetic data validation** — 50 Monte Carlo replicates (T=300) confirm parameter recovery within 3.6% of true values; F1 gap of 0.149 quantifies the identification contribution of Markov temporal persistence over a GMM baseline
- **Statistical significance** — DeLong nonparametric AUC test, HLN-corrected Diebold-Mariano test, stationary bootstrap (B=10,000, block length b=12 months)
- **Emission parameter analysis** — PC2 (current-account/GDP loading +0.639) is the dominant state separator at 1.77σ, outranking VIX (1.35σ) and INR/ZAR (1 …