pub struct RateOfChange { /* private fields */ }
Expand description
Rate of Change (ROC)
§Formula
ROC = (Pricet - Pricet-n) / Pricet-n * 100
Where:
- ROC - current value of Rate of Change indicator
- Pt - price at the moment
- Pt-n - price n periods ago
§Parameters
- length - number of periods (n), integer greater than 0
§Example
use ta::indicators::RateOfChange;
use ta::{Calculate, Next};
let mut roc = RateOfChange::new(2).unwrap();
assert_eq!(roc.calc(10.0), 0.0); // 0
assert_eq!(roc.calc(9.7).round(), -3.0); // (9.7 - 10) / 10 * 100 = -3
assert_eq!(roc.calc(20.0).round(), 100.0); // (20 - 10) / 10 * 100 = 100
assert_eq!(roc.calc(20.0).round(), 106.0); // (20 - 9.7) / 9.7 * 100 = 106
§Links
Implementations§
Trait Implementations§
Source§impl Clone for RateOfChange
impl Clone for RateOfChange
Source§fn clone(&self) -> RateOfChange
fn clone(&self) -> RateOfChange
Returns a copy of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl Debug for RateOfChange
impl Debug for RateOfChange
Source§impl Default for RateOfChange
impl Default for RateOfChange
Source§impl Display for RateOfChange
impl Display for RateOfChange
Auto Trait Implementations§
impl Freeze for RateOfChange
impl RefUnwindSafe for RateOfChange
impl Send for RateOfChange
impl Sync for RateOfChange
impl Unpin for RateOfChange
impl UnwindSafe for RateOfChange
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