Skip to content

Releases: kratu/wess_hmm

V2

V2

Choose a tag to compare

@kratu kratu released this 26 Feb 11:27

v2.1 Release — Hybrid Wasserstein + HMM Regime Detector

This release fixes several core issues that were causing systematic
misclassification across trending and choppy sessions.

What's improved

Regime labelling is now reliable. The previous version assigned HMM state
labels using cosine similarity, which broke down when states had similar ADX
profiles — causing a strong downtrend to be labelled Choppy and vice versa.
Labels are now assigned through a decision tree that uses volatility and R²
(how well price fits a straight line) as the primary signals. Low R² means
erratic, non-linear movement — genuine chop. This mapping is deterministic and
stable across retrains.

The model now works correctly at current NIFTY price levels. Slope was
previously computed as raw price points per bar. Since training data covered
NIFTY at ~11,000 (2015–2022) and live inference runs at ~25,800, the same
absolute slope value was 2.3× smaller in relative terms at live prices. Quiet
2026 afternoons were matching the "gentle trend" emission distribution from
training data, giving the wrong label with high confidence. Slope is now
normalised by the rolling price mean, making it consistent across all price
levels. This is applied identically in both trainer and inference.

The HMM now uses temporal context correctly. Previously, posteriors were
computed bar-by-bar, which discards the transition matrix entirely — each bar
was treated as if it existed in isolation. Posteriors are now computed on the
full session sequence in a single pass, letting the forward-backward algorithm
integrate transition probabilities as intended. Regimes are now temporally
coherent rather than flickering.

Faster regime transitions after a trend ends. The multi-scale voting window
was previously 24 bars (2 hours) at its longest. A morning downtrend would keep
influencing labels well into the afternoon even after price had clearly
stabilised. The window is now capped at 12 bars (1 hour), giving the model
faster response to genuine regime changes.

New: annotation toolchain

annotate_regimes.py is a new interactive CLI for labelling historical sessions.
It writes directly to regime_annotations.csv, which the trainer uses to
initialise HMM states in the correct region of feature space — the right approach
for teaching the model regime boundaries that unsupervised training cannot find
on its own.

> 09:15-10:30 Trending-Up
> 11:00-13:45 Choppy medium
> 14:00-15:25 Range

Training data: NIFTY Futures 5-min · 2015–2022 · 106,355 bars

Initial release

Choose a tag to compare

@kratu kratu released this 06 Nov 05:39

v1.0.1

Tested all the code again. Retrained the model for thorough testing.

The integration_example.py code now demonstrates how it can gracefully evaluate market structure even with insufficient data (due to early market session). It switches between 1m and 5m timeframe based on the time. Resumes normally at 5m after 10:30
(Note: 1m data can be noisy and therefore frequent regime switches could occur)