pub struct MacdIndicator { /* private fields */ }Expand description
MACD = EMA(fast) − EMA(slow), with a signal EMA on top.
Standard parameters are fast = 12, slow = 26, signal = 9. The signal EMA
is seeded from the first signal raw MACD values, so the first full
MacdOutput is emitted after slow + signal − 1 inputs (assuming the
slow EMA seeded by then).
§Example
use wickra_core::{Indicator, MacdIndicator};
let mut indicator = MacdIndicator::new(3, 6, 3).unwrap();
let mut last = None;
for i in 0..80 {
last = indicator.update(100.0 + f64::from(i));
}
assert!(last.is_some());Implementations§
Source§impl MacdIndicator
impl MacdIndicator
Sourcepub fn new(fast: usize, slow: usize, signal: usize) -> Result<Self>
pub fn new(fast: usize, slow: usize, signal: usize) -> Result<Self>
Construct a MACD with the given periods.
§Errors
Returns Error::PeriodZero if any period is zero, and
Error::InvalidPeriod if fast >= slow.
Sourcepub fn classic() -> Self
pub fn classic() -> Self
Default (12, 26, 9) configuration, matching every classical chart package.
Sourcepub const fn periods(&self) -> (usize, usize, usize)
pub const fn periods(&self) -> (usize, usize, usize)
Configured periods as (fast, slow, signal).
Sourcepub const fn value(&self) -> Option<MacdOutput>
pub const fn value(&self) -> Option<MacdOutput>
Most recent fully-computed output if available.
Trait Implementations§
Source§impl Clone for MacdIndicator
impl Clone for MacdIndicator
Source§fn clone(&self) -> MacdIndicator
fn clone(&self) -> MacdIndicator
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · 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 MacdIndicator
impl Debug for MacdIndicator
Source§impl Indicator for MacdIndicator
impl Indicator for MacdIndicator
Source§type Output = MacdOutput
type Output = MacdOutput
Type of one output value.
Source§fn update(&mut self, input: f64) -> Option<MacdOutput>
fn update(&mut self, input: f64) -> Option<MacdOutput>
Feed one new data point into the indicator and return the freshly computed
output, or
None if the indicator is still warming up.Source§fn reset(&mut self)
fn reset(&mut self)
Reset all internal state, leaving the indicator equivalent to a freshly
constructed instance with the same parameters.
Source§fn warmup_period(&self) -> usize
fn warmup_period(&self) -> usize
Number of inputs required before the first non-
None output can be produced.Auto Trait Implementations§
impl Freeze for MacdIndicator
impl RefUnwindSafe for MacdIndicator
impl Send for MacdIndicator
impl Sync for MacdIndicator
impl Unpin for MacdIndicator
impl UnsafeUnpin for MacdIndicator
impl UnwindSafe for MacdIndicator
Blanket Implementations§
Source§impl<T> BatchExt for Twhere
T: Indicator,
impl<T> BatchExt for Twhere
T: Indicator,
Source§fn batch(&mut self, inputs: &[Self::Input]) -> Vec<Option<Self::Output>>
fn batch(&mut self, inputs: &[Self::Input]) -> Vec<Option<Self::Output>>
Run the indicator over a slice of inputs in order, returning one output (or
None during warmup) per input.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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more