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.
Sourcepub fn batch_macd(&mut self, inputs: &[f64]) -> Vec<f64>
pub fn batch_macd(&mut self, inputs: &[f64]) -> Vec<f64>
Vectorized flat batch for bindings: n * 3 values laid out as
[macd, signal, histogram] per input row, warmup rows all NaN.
For a fresh, all-finite slice long enough for a full output it runs the
fast EMA, slow EMA and signal EMA as three recurrences fused into a single
pass with one allocation — no Option per tick, no per-EMA intermediate
buffers, identical SMA-mean seeds (division) and mul_add recurrences. The
result is bit-for-bit equal to replaying update. Anything else (not
fresh, non-finite, or too short to emit) defers to the exact update
replay.
Separate from the trait batch, which stays a
bit-identical update replay; only the bindings call this.
Trait Implementations§
Source§impl Clone for MacdIndicator
impl Clone for MacdIndicator
Source§fn clone(&self) -> MacdIndicator
fn clone(&self) -> MacdIndicator
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
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
Source§fn update(&mut self, input: f64) -> Option<MacdOutput>
fn update(&mut self, input: f64) -> Option<MacdOutput>
None if the indicator is still warming up.Source§fn reset(&mut self)
fn reset(&mut self)
Source§fn warmup_period(&self) -> usize
fn warmup_period(&self) -> usize
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>>
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
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>
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>
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