pub struct MacdFix { /* private fields */ }Expand description
MACD Fix (MACDFIX): the classic MACD with the fast and slow EMAs fixed at
12 and 26, leaving only the signal period configurable.
This is TA-Lib’s MACDFIX: the 12- and 26-bar EMAs smooth with Gerald
Appel’s rounded constants 0.15 and 0.075 instead of 2 / 13 and
2 / 27 (both still seeded with their simple means), so it differs slightly
from MacdIndicator::new(12, 26, signal). The signal
line is an ordinary signal-period EMA of the MACD line. The output is the
usual MacdOutput triple { macd, signal, histogram }.
fast = EMA(close; seed SMA(12), α = 0.15)
slow = EMA(close; seed SMA(26), α = 0.075)
macd = fast − slow, signal = EMA(macd, signal), histogram = macd − signal§Example
use wickra_core::{Indicator, MacdFix};
let mut indicator = MacdFix::new(9).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 MacdFix
impl MacdFix
Sourcepub fn new(signal: usize) -> Result<Self>
pub fn new(signal: usize) -> Result<Self>
Construct a MACDFIX with fast = 12, slow = 26 and the given signal period.
§Errors
Returns Error::PeriodZero if signal == 0.
Sourcepub fn signal_period(&self) -> usize
pub fn signal_period(&self) -> usize
Configured signal period.
Sourcepub fn batch_macd_into(&mut self, inputs: &[f64], out: &mut [f64])
pub fn batch_macd_into(&mut self, inputs: &[f64], out: &mut [f64])
Exact flat batch, [macd, signal, histogram] per input row, warmup rows
NaN — the fused path of MacdIndicator::batch_macd_into.
§Panics
Panics if out.len() != inputs.len() * 3.
Sourcepub fn batch_macd(&mut self, inputs: &[f64]) -> Vec<f64>
pub fn batch_macd(&mut self, inputs: &[f64]) -> Vec<f64>
batch_macd_into into a fresh vector.
Sourcepub fn batch_macd_fast_into(&mut self, inputs: &[f64], out: &mut [f64])
pub fn batch_macd_fast_into(&mut self, inputs: &[f64], out: &mut [f64])
The opt-in SIMD batch of MacdIndicator::batch_macd_fast_into.
§Panics
Panics if out.len() != inputs.len() * 3.
Sourcepub fn batch_macd_fast(&mut self, inputs: &[f64]) -> Vec<f64>
pub fn batch_macd_fast(&mut self, inputs: &[f64]) -> Vec<f64>
batch_macd_fast_into into a fresh vector.
Trait Implementations§
Source§impl Indicator for MacdFix
impl Indicator for MacdFix
Source§type Output = MacdOutput
type Output = MacdOutput
Source§fn update(&mut self, value: f64) -> Option<MacdOutput>
fn update(&mut self, value: f64) -> Option<MacdOutput>
None if there is no value for this input. Read moreSource§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 MacdFix
impl RefUnwindSafe for MacdFix
impl Send for MacdFix
impl Sync for MacdFix
impl Unpin for MacdFix
impl UnsafeUnpin for MacdFix
impl UnwindSafe for MacdFix
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