Module main

Source
Expand description

§Rate of Change (ROC) Module

This module implements a Rate of Change (ROC) indicator. The ROC is calculated as the percentage change between the current price and the price from a specified number of periods ago. Additionally, it calculates a normalized momentum, an acceleration (change in ROC from the previous value), and generates a trading signal.

Typical usage example:

use indexes_rs::v1::roc::main::ROC;
use indexes_rs::v1::types::TradingSignal;

let mut roc = ROC::new(12);
let prices = vec![100.0, 101.0, 102.0, 103.0, 104.0, 105.0, 106.0, 107.0, 108.0, 109.0, 110.0, 111.0, 112.0];
let mut result = None;
for price in prices {
    result = roc.calculate(price);
}
if let Some(res) = result {
    println!("ROC value: {:.2}%", res.value);
    println!("Momentum: {:.2}%", res.momentum);
    println!("Acceleration: {:?}", res.acceleration);
}

Structs§

ROC
A Rate of Change (ROC) indicator.