pub struct Roc<const N: usize> { /* private fields */ }Expand description
Rate of Change as a percentage: (close - close[N ago]) / close[N ago] · 100,
where N is the lookback period.
A ring of exactly N slots holds the last N values; the slot about to be
overwritten is the value from N steps ago, so no N + 1 buffer is needed.
Non-finite inputs are ignored (the last value is returned, state untouched),
matching wickra_core::Roc. The first output appears after N + 1 inputs.
§Example
use wickra_embed_core::{Indicator, Roc};
// ROC(3): prev = 100 three steps back, now = 110 -> 10%.
let mut roc = Roc::<3>::new();
assert_eq!(roc.update(100.0), None);
assert_eq!(roc.update(105.0), None);
assert_eq!(roc.update(108.0), None);
assert_eq!(roc.update(110.0), Some(10.0));Implementations§
Trait Implementations§
Source§impl<const N: usize> Indicator for Roc<N>
impl<const N: usize> Indicator for Roc<N>
Source§fn update(&mut self, input: f64) -> Option<f64>
fn update(&mut self, input: f64) -> Option<f64>
Feed one new data point in and return the freshly computed value, or
None while still warming up.Source§fn reset(&mut self)
fn reset(&mut self)
Reset all internal state, leaving the indicator equivalent to a freshly
constructed instance with the same parameters.
Source§fn warmup_period(&self) -> usize
fn warmup_period(&self) -> usize
Number of inputs required before the first non-
None output.Auto Trait Implementations§
impl<const N: usize> Freeze for Roc<N>
impl<const N: usize> RefUnwindSafe for Roc<N>
impl<const N: usize> Send for Roc<N>
impl<const N: usize> Sync for Roc<N>
impl<const N: usize> Unpin for Roc<N>
impl<const N: usize> UnsafeUnpin for Roc<N>
impl<const N: usize> UnwindSafe for Roc<N>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more