Skip to main content

RegimeConditionalSignal

Struct RegimeConditionalSignal 

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

A wrapper that selects different RSI periods depending on the active regime.

This is the canonical implementation of regime-conditional signal adaptation:

  • In Trending markets: short-period RSI is more responsive
  • In MeanReverting markets: longer-period RSI reduces noise
  • In HighVolatility or Crisis: signal is suppressed (returns None)
  • In other regimes: uses the neutral period

§Example

use fin_primitives::regime::{RegimeConditionalSignal, MarketRegime};
use fin_primitives::signals::BarInput;
use rust_decimal_macros::dec;

let mut signal = RegimeConditionalSignal::new(14, 21, 14).unwrap();
let bar = BarInput::new(dec!(100), dec!(102), dec!(98), dec!(100), dec!(1000));
// During warm-up, regime is Unknown → signal suppressed
let val = signal.update(&bar, MarketRegime::Unknown);
assert!(val.is_none());

Implementations§

Source§

impl RegimeConditionalSignal

Source

pub fn new( trending_period: usize, mean_reverting_period: usize, neutral_period: usize, ) -> Result<Self, FinError>

Constructs a new RegimeConditionalSignal.

  • trending_period: RSI period for trending regime (e.g. 14).
  • mean_reverting_period: RSI period for mean-reverting regime (e.g. 21).
  • neutral_period: RSI period for all other regimes (e.g. 14).
§Errors

Returns FinError::InvalidPeriod if any period is zero.

Source

pub fn update( &mut self, bar: &BarInput, regime: MarketRegime, ) -> Option<Result<f64, FinError>>

Updates the appropriate RSI indicator for the given regime and returns the current RSI value, or None if the signal is suppressed.

Suppressed in: Crisis, Unknown (risk-off regimes).

§Errors

Propagates any FinError from RSI computation.

Source

pub fn is_ready(&self) -> bool

Returns true when all internal RSI indicators are warmed up.

Source

pub fn reset(&mut self)

Resets all internal indicators.

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.