Expand description
§Momentum Indicator Module
This module implements a Momentum indicator. The Momentum indicator calculates the difference between the current price and the price from a specified number of periods ago. In addition, it computes a momentum ratio, defined as the current price as a percentage of the past price.
§Examples
use indexes_rs::v1::momentum::main::Momentum;
use indexes_rs::v1::momentum::types::MomentumResult;
let mut momentum = Momentum::new(14);
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, 113.0];
// After feeding in at least 14 prices, calculate() returns a result.
if let Some(result) = momentum.calculate(113.0) {
println!("Momentum: {:.2}", result.value);
println!("Momentum Ratio: {:.2}%", result.ratio);
}Structs§
- Momentum
- A Momentum indicator that calculates the change between the current price and the price from a given number of periods ago.