πŸ“„ arXiv:2604.20949 πŸ”¬ Zenodo πŸ”— GitHub βœ“ Reproducible ⚑ Causal 🎯 100% Precision

LOB Latent Regimes

Latent Micro-Regime Early Detection in Limit Order Books

Identify structural market instability before it surfaces

A reproducible research framework for detecting latent build-up phases in financial markets. Fires with positive lead-time and 100% precision, exploiting the measurable delay between structural deterioration and observable stress.

⚠️ Research pipeline. Not a trading strategy. See Scope & Limitations below.

"Market stress does not arrive without warning. It accumulates."

Classical indicatorsβ€”volatility, order imbalance, spread wideningβ€”are reactive. By the time they fire, the dislocation has already begun. This research asks a harder question: Can we detect the structural deterioration that precedes observable stressβ€”before it becomes visible in price or spread?

The Three Regimes

Markets cycle through three distinct states. The critical regime is invisible to standard microstructure monitors.

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                                                                  β”‚
β”‚  STATE 0 ────────────► STATE 1 ────────────► STATE 2             β”‚
β”‚                                                                  β”‚
β”‚  Stable                Latent Build-up        Stress             β”‚
β”‚  ───────                ───────────────        ──────             β”‚
β”‚  β€’ Balanced liquidity   β€’ Depth eroding        β€’ Price shock      β”‚
β”‚  β€’ High resilience      β€’ Spread drifting      β€’ Visible          β”‚
β”‚  β€’ Equilibrium          β€’ ⚠ Hidden instability β€’ Reactive         β”‚
β”‚                                                                  β”‚
β”‚  Observable            INVISIBLE              Observable         β”‚
β”‚  (past data)           (our signal fires)     (too late)         β”‚
β”‚                                                                  β”‚
β”‚              ◄──── detection window ────►                       β”‚
β”‚              ↑                         ↑                        β”‚
β”‚         we detect                 stress begins                β”‚
β”‚                                                                  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

The key insight: The transition from State 1 β†’ State 2 is not instantaneous. There is a measurable delay β€” and within that delay lives our detection window. We exploit it.

Why this matters: Depth erosion precedes spread widening, which precedes price impact. If we detect the book thinning silently, we have time to respond before the visible stress cascade begins.

Detection Framework

Three independent signal channels. One fused trigger. Rising-edge detection instead of thresholds.

Signal Channels

πŸ“Š HMM Posterior Entropy

Uncertainty in regime classification

Why early: Rises as the latent state becomes ambiguous, before the transition to stress solidifies.

πŸ“‰ Temporal Depth Drift

Recursive tracking of LOB depth erosion

Why early: Captures slow structural decay invisible to snapshot metrics. Liquid book β†’ thin book is the first visible sign.

βš–οΈ Order Flow Toxicity

Imbalance between informed and uninformed flow

Why early: Signals adverse selection building in the book before visible spread impact.

Trigger Logic

MAX-Fusion Trigger
β”œβ”€β”€ Rising-edge detection
β”‚   └─ Onset of change, not absolute level
β”‚   └─ Bypasses noise floor that kills threshold methods
β”‚
β”œβ”€β”€ Cross-channel aggregation
β”‚   └─ Fire when ANY channel breaches threshold
β”‚
└── Early-detection constraint
    └─ Signal must precede stress (Ο„ < Οƒ)

Key design choice: We don't ask "is the spread wide?" We ask "is it getting wider right now?" This rising-edge approach bypasses the noise floor that kills absolute-threshold methods on real microstructure data.

Empirical Results

Evaluated under full causal guarantees. No lookahead bias. No global statistics leaked to the predictor.

Method Lead-Time (steps) Precision Coverage
β˜… Adaptive Trigger +18.6 100% 52.6%
HMM +14.9 100% 43.2%
Multi-Trigger +13.1 100% 28.1%
Order Imbalance βˆ’24.8 54.9% 78.7%
Volatility βˆ’32.0 45.5% 43.3%

Reading the table: Positive lead-time means the signal fires before stress begins. Baseline methods are strictly negativeβ€”they lag. 100% precision means zero false starts during the latent phaseβ€”every trigger is temporally valid.

Key Findings

βœ“ Latent Instability Is Real

Market regimes structurally deteriorate before visible deterioration. Consistent empirical signature across tested sessions.

βœ“ Depth Erosion Is Most Reliable

Depth decay in the LOB precedes spread widening and price impact. Book thinning is the earliest signal.

βœ“ HMM Entropy Works

Posterior entropy is a structural stress barometer. Model uncertainty itself is informative.

βœ“ Rising-Edge Beats Thresholds

Onset of deterioration carries more information than magnitude. No false starts from noise.

Reproducibility Guarantees

This pipeline was engineered to be trusted. Every result is verifiable and repeatable.

βœ“ Causal

No Lookahead

βœ“ Rolling Norm

No Data Leakage

βœ“ HMM Re-fit

Periodic

βœ“ Deterministic

Fixed Seeds

βœ“ Validated

Colab + M4

Causality verification: Rolling normalization onlyβ€”no global statistics computed on future data. HMM re-fit every evaluation window. All results are exact under deterministic seeds across NVIDIA T4 (Google Colab) and Apple Silicon (M4 Pro/Max).

Quickstart

Clone & Install

git clone https://github.com/prakulhiremath/LOB-Latent-Regimes.git
cd LOB-Latent-Regimes
pip install -r requirements.txt

Run the Final Pipeline

python experiments/v7_final.py

Expected output:

[INFO] Loading normalized LOB snapshots...
[INFO] Running causal evaluation pipeline...
[INFO] Fitting HMM with rolling windows...
[INFO] Computing signal channels (entropy, depth, toxicity)...
[INFO] Fusing triggers with MAX aggregation...
[INFO] Computing lead-time and precision metrics...

╔════════════════════════════════════════════════════════════════╗
β•‘  Adaptive Trigger       +18.6 steps  100% precision  52.6%    β•‘
β•‘  HMM                    +14.9 steps  100% precision  43.2%    β•‘
β•‘  Multi-Trigger          +13.1 steps  100% precision  28.1%    β•‘
β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•

Explore Individual Signals

jupyter notebook notebooks/analysis.ipynb

Contains: Signal decomposition, lead-time distributions, regime transition visualizations, baseline comparisons.

Repository Structure

LOB-Latent-Regimes/
β”‚
β”œβ”€β”€ experiments/
β”‚   β”œβ”€β”€ v1_baseline.py           # Initial HMM formulation
β”‚   β”œβ”€β”€ v2_entropy.py            # Posterior entropy tracking
β”‚   β”œβ”€β”€ v3_depth_drift.py        # Temporal depth signal
β”‚   β”œβ”€β”€ v4_triggers.py           # Trigger logic development
β”‚   β”œβ”€β”€ v5_fusion.py             # MAX-fusion framework
β”‚   β”œβ”€β”€ v6_rising_edge.py        # Rising-edge detection
β”‚   └── v7_final.py              # β˜… Production pipeline
β”‚
β”œβ”€β”€ notebooks/
β”‚   └── analysis.ipynb           # Experiment analysis + figures
β”‚
β”œβ”€β”€ results/
β”‚   β”œβ”€β”€ figures/                 # High-resolution performance plots
β”‚   └── summary.txt              # Quantified results
β”‚
β”œβ”€β”€ paper/                       # Technical manuscript
β”œβ”€β”€ assets/                      # Visualizations, GIFs, detection timeline
β”œβ”€β”€ requirements.txt             # Dependencies
└── README.md

Development Progression

The pipeline evolved through 7 versions, each adding precision:

Version Focus Key Innovation
v1 Baseline HMM Three-state Markov model for regime classification
v2 Entropy Signal Posterior entropy as stress barometer
v3 Depth Drift Temporal tracking of LOB depth erosion
v4 Trigger Design Individual signal thresholds
v5 Multi-Signal Fusion MAX aggregation across channels
v6 Rising-Edge Onset detection instead of absolute levels
β˜… v7 Final Pipeline Production configuration, full causal guarantees

Scope & Limitations

Be precise about what this is and is not.

βœ“ This Repo IS

  • Detection framework for latent regime transitions
  • Empirical study of LOB microstructure
  • Reproducible research pipeline
  • Contribution to predictive market microstructure
  • Academic exercise in causal signal processing

βœ— This Repo IS NOT

  • A trading strategy or system
  • Optimised for execution latency
  • A production trading system
  • Financial advice or investment guidance
  • Tested in live market conditions

Important: This is research code. Backtesting results do not guarantee forward performance. Live trading requires rigorous validation, risk management, and regulatory compliance beyond the scope of this work.

Research Contributions

Causal Formulation

Model latent build-up β†’ stress transition as a three-state latent process with explicit temporal separation.

Temporal Drift Identification

Subtle depth and spread drift as leading precursor to liquidity voids. Recursive tracking without lookahead.

Novel Detection Logic

MAX-fusion + rising-edge trigger for sub-millisecond microstructure data. Positive lead-time guarantee.

Empirical Demonstration

Strictly positive lead-time over reactive benchmarks across all evaluated regimes. 100% precision.

Citation

@article{hiremath2026lob,
  title   = {Early Detection of Latent Micro-Regimes in Limit Order Books},
  author  = {Hiremath, Prakul Sunil and Hiremath, Vruksha Arun},
  year    = {2026},
  doi     = {10.5281/zenodo.19697687}
}

LOB Latent Regimes β€” Early Detection of Structural Market Instability

MIT License Β· Reproducible Research Pipeline Β· Open Source

"If the signal fires before the storm β€” it worked."