Skip to main content

Roc

Struct Roc 

Source
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§

Source§

impl<const N: usize> Roc<N>

Source

pub const fn new() -> Self

Construct a new ROC over a lookback of N.

Source

pub const fn value(&self) -> Option<f64>

Current value if available.

Trait Implementations§

Source§

impl<const N: usize> Clone for Roc<N>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<const N: usize> Debug for Roc<N>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<const N: usize> Default for Roc<N>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<const N: usize> Indicator for Roc<N>

Source§

type Input = f64

Type of one input data point (f64 for a price, Candle for an OHLC bar).
Source§

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)

Reset all internal state, leaving the indicator equivalent to a freshly constructed instance with the same parameters.
Source§

fn warmup_period(&self) -> usize

Number of inputs required before the first non-None output.
Source§

fn is_ready(&self) -> bool

Whether the indicator has produced at least one value since construction or the last reset.
Source§

fn name(&self) -> &'static str

Stable, human-readable indicator name.

Auto Trait Implementations§

§

impl<const N: usize> Freeze for Roc<N>
where [f64; N]: Freeze,

§

impl<const N: usize> RefUnwindSafe for Roc<N>
where [f64; N]: RefUnwindSafe,

§

impl<const N: usize> Send for Roc<N>
where [f64; N]: Send,

§

impl<const N: usize> Sync for Roc<N>
where [f64; N]: Sync,

§

impl<const N: usize> Unpin for Roc<N>
where [f64; N]: Unpin,

§

impl<const N: usize> UnsafeUnpin for Roc<N>
where [f64; N]: UnsafeUnpin,

§

impl<const N: usize> UnwindSafe for Roc<N>
where [f64; N]: UnwindSafe,

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.