Struct ROC

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

A Rate of Change (ROC) indicator.

Implementations§

Source§

impl ROC

Source

pub const DEFAULT_PERIOD: usize = 12usize

The default period for ROC calculation.

Source

pub const SIGNAL_THRESHOLD: f64 = 2f64

The threshold used to generate trading signals.

Source

pub fn new(period: usize) -> Self

Creates a new ROC indicator with the given period.

§Arguments
  • period - The number of periods over which to calculate the ROC.
§Example
use indexes_rs::v1::roc::main::ROC;

let roc = ROC::new(12);
Source

pub fn calculate(&mut self, price: f64) -> Option<ROCResult>

Calculates the current ROC value based on the latest price.

This method updates the sliding window of prices and computes:

  • The ROC value (percentage change between the current price and the price from period periods ago).
  • A normalized momentum value.
  • The acceleration (difference between the current and previous ROC).
  • A trading signal based on the ROC.
§Arguments
  • price - The latest price.
§Returns
  • Some(ROCResult) if there is enough data; otherwise, None.

Auto Trait Implementations§

§

impl Freeze for ROC

§

impl RefUnwindSafe for ROC

§

impl Send for ROC

§

impl Sync for ROC

§

impl Unpin for ROC

§

impl UnwindSafe for ROC

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.