Skip to main content

EnsembleRegimeDetector

Struct EnsembleRegimeDetector 

Source
pub struct EnsembleRegimeDetector { /* private fields */ }
Expand description

Ensemble regime detector combining indicator-based and HMM methods.

Feeds the same OHLC data to both detectors simultaneously and combines their outputs using weighted averaging with agreement bonuses/penalties.

§Example

use indicators::{EnsembleRegimeDetector, EnsembleConfig, RegimeConfig, MarketRegime};

let mut ensemble = EnsembleRegimeDetector::default_config();

// Feed OHLC bars
for i in 0..300 {
    let price = 100.0 + i as f64 * 0.5;
    let result = ensemble.update(price + 1.0, price - 1.0, price);
    if ensemble.is_ready() {
        println!("{}", result);
    }
}

Implementations§

Source§

impl EnsembleRegimeDetector

Source

pub fn new( ensemble_config: EnsembleConfig, indicator_config: RegimeConfig, ) -> Self

Create with specific configs for both the ensemble and the indicator detector

Source

pub fn default_config() -> Self

Create with default configs (indicator-weighted, crypto-optimized)

Source

pub fn balanced() -> Self

Create balanced ensemble (equal weighting)

Source

pub fn indicator_focused() -> Self

Create indicator-focused ensemble

Source

pub fn hmm_focused() -> Self

Create HMM-focused ensemble

Source

pub fn update(&mut self, high: f64, low: f64, close: f64) -> EnsembleResult

Update with new OHLC data and get the ensemble result.

Both detectors are updated with the same data. The ensemble then combines their outputs, adjusting confidence based on agreement.

Source

pub fn current_regime(&self) -> MarketRegime

Get current regime

Source

pub fn agreement_rate(&self) -> f64

Get agreement rate over recent history (0.0 to 1.0)

Source

pub fn is_ready(&self) -> bool

Check if both detectors are ready.

When require_hmm_warmup is true, both must be ready. Otherwise, only the indicator detector needs to be ready.

Source

pub fn indicator_ready(&self) -> bool

Check if only the indicator detector is ready (HMM may still be warming up)

Source

pub fn hmm_ready(&self) -> bool

Check if the HMM detector is ready

Source

pub fn hmm_state_probabilities(&self) -> &[f64]

Get HMM state probabilities

Source

pub fn expected_regime_duration(&self) -> f64

Get HMM expected regime duration

Source

pub fn status(&self) -> EnsembleStatus

Get detailed status for monitoring

Source

pub fn indicator_detector(&self) -> &RegimeDetector

Get a reference to the underlying indicator detector

Source

pub fn hmm_detector(&self) -> &HMMRegimeDetector

Get a reference to the underlying HMM detector

Source

pub fn config(&self) -> &EnsembleConfig

Get the ensemble configuration

Trait Implementations§

Source§

impl Debug for EnsembleRegimeDetector

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.