pub struct Sma { /* private fields */ }Expand description
Simple Moving Average indicator.
Computes the arithmetic mean of closing prices over the specified period.
§Formula
SMA = (P1 + P2 + … + Pn) / n
where P is the closing price and n is the period.
§Example
use quant_indicators::{Indicator, Sma};
use quant_primitives::Candle;
use chrono::Utc;
use rust_decimal_macros::dec;
let ts = Utc::now();
let candles: Vec<Candle> = (0..20).map(|i| {
Candle::new(dec!(100), dec!(110), dec!(90), dec!(100) + rust_decimal::Decimal::from(i), dec!(1000), ts).unwrap()
}).collect();
let sma = Sma::new(20).unwrap();
let series = sma.compute(&candles).unwrap();Implementations§
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Sma
impl RefUnwindSafe for Sma
impl Send for Sma
impl Sync for Sma
impl Unpin for Sma
impl UnsafeUnpin for Sma
impl UnwindSafe for Sma
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