Skip to main content

indicators/regime/
mod.rs

1//! Statistical market regime detection.
2//!
3//! Three detection approaches, from fastest to most robust:
4//!
5//! | Detector | Module | Description |
6//! |----------|--------|-------------|
7//! | Indicator-based | [`detector`] | ADX + Bollinger Bands + ATR — immediate, rule-based |
8//! | HMM | [`hmm`] | Hidden Markov Model — learns regime distributions from returns |
9//! | Ensemble | [`ensemble`] | Combines both — recommended for production use |
10//!
11//! The [`router`] module routes to strategies based on the detected regime.
12//!
13//! Internal indicator primitives (EMA, ATR, ADX, Bollinger Bands) used by the
14//! detectors live in [`primitives`]. These are intentionally separate from the
15//! batch `Indicator` implementations in `crate::volatility` — they are
16//! incremental accumulators optimised for the regime detection loop.
17
18pub mod detector;
19pub mod ensemble;
20pub mod hmm;
21pub mod primitives;
22pub mod router;
23/// Re-exports of crate-level types consumed by regime detector internals.
24pub(crate) mod types;
25
26pub use detector::{DetectorIndicator, RegimeDetector};
27pub use ensemble::{
28    EnsembleConfig, EnsembleIndicator, EnsembleRegimeDetector, EnsembleResult, EnsembleStatus,
29};
30pub use hmm::{HMMConfig, HMMRegimeDetector, HmmIndicator};
31pub use primitives::{
32    ADX, AdxIndicator, AtrPrimIndicator, BbPrimIndicator, BollingerBands, BollingerBandsValues,
33    EmaPrimIndicator, RSI, RsiPrimIndicator,
34};
35pub use router::{
36    ActiveStrategy, AssetSummary, DetectionMethod, EnhancedRouter, EnhancedRouterConfig,
37    RoutedSignal, RouterIndicator,
38};
39
40use crate::registry::IndicatorRegistry;
41
42pub fn register_all(reg: &IndicatorRegistry) {
43    reg.register("detector", detector::factory);
44    reg.register("ensemble", ensemble::factory);
45    reg.register("hmm", hmm::factory);
46    reg.register("primitives", primitives::factory);
47    reg.register("router", router::factory);
48}