pub struct RegimeDetector { /* private fields */ }Expand description
Main indicator-based regime detection engine.
Feeds OHLC bars through ADX, ATR, Bollinger Bands, and dual-EMA indicators, then scores each regime possibility to produce a classification with confidence.
Includes a stability filter to prevent regime whipsawing.
§Example
use indicators::{RegimeDetector, RegimeConfig, MarketRegime};
let mut detector = RegimeDetector::crypto_optimized();
// Feed OHLC bars
for i in 0..300 {
let price = 100.0 + i as f64 * 0.5;
let result = detector.update(price + 1.0, price - 1.0, price);
if detector.is_ready() {
println!("Regime: {} (conf: {:.0}%)", result.regime, result.confidence * 100.0);
}
}Implementations§
Source§impl RegimeDetector
impl RegimeDetector
Sourcepub fn new(config: RegimeConfig) -> Self
pub fn new(config: RegimeConfig) -> Self
Create a new detector with the given configuration
Sourcepub fn default_config() -> Self
pub fn default_config() -> Self
Create with default config
Sourcepub fn crypto_optimized() -> Self
pub fn crypto_optimized() -> Self
Create optimized for crypto markets
Sourcepub fn conservative() -> Self
pub fn conservative() -> Self
Create with conservative config
Sourcepub fn update(&mut self, high: f64, low: f64, close: f64) -> RegimeConfidence
pub fn update(&mut self, high: f64, low: f64, close: f64) -> RegimeConfidence
Update with new OHLC bar and get the regime classification.
Returns a RegimeConfidence with the detected regime, confidence score,
and supporting indicator metrics.
The detector requires a warmup period (determined by the longest indicator
period) before it starts producing meaningful classifications. During
warmup, it returns MarketRegime::Uncertain with zero confidence.
Sourcepub fn is_ready(&self) -> bool
pub fn is_ready(&self) -> bool
Check if detector has enough data to classify regime.
All indicators must be warmed up before the detector can produce meaningful results.
Sourcepub fn current_regime(&self) -> MarketRegime
pub fn current_regime(&self) -> MarketRegime
Get current detected regime
Sourcepub fn recommended_strategy(&self) -> RecommendedStrategy
pub fn recommended_strategy(&self) -> RecommendedStrategy
Get recommended strategy for current regime
Sourcepub fn bars_in_current_regime(&self) -> usize
pub fn bars_in_current_regime(&self) -> usize
Get number of bars in current regime
Sourcepub fn config(&self) -> &RegimeConfig
pub fn config(&self) -> &RegimeConfig
Get current config
Sourcepub fn set_config(&mut self, config: RegimeConfig)
pub fn set_config(&mut self, config: RegimeConfig)
Update config (resets internal state)
Sourcepub fn regime_history(&self) -> &VecDeque<MarketRegime>
pub fn regime_history(&self) -> &VecDeque<MarketRegime>
Get the regime history (most recent at the back)
Sourcepub fn last_close(&self) -> Option<f64>
pub fn last_close(&self) -> Option<f64>
Get the last close price