pub struct Hma { /* private fields */ }Expand description
Hull Moving Average: WMA(2 * WMA(n/2) - WMA(n), sqrt(n)).
Designed by Alan Hull as a lag-free moving average that is also responsive. The square root of the period is rounded to the nearest integer (minimum 1).
§Example
use wickra_core::{Indicator, Hma};
let mut indicator = Hma::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§
Trait Implementations§
Source§impl Indicator for Hma
impl Indicator for Hma
Source§fn batch_nan_into(&mut self, inputs: &[f64], out: &mut [f64])
fn batch_nan_into(&mut self, inputs: &[f64], out: &mut [f64])
The exact batch: until all three WMAs are full it replays update, then
runs the three in one loop with their state in locals (Wma::steady).
Per input that is update’s own sequence – skip a non-finite input,
step both windowed WMAs, and step the smoothing one on 2 * half - full
only when that is finite, as its update would skip it – so the same
bits and the same state, with the three independent chains interleaved.
Source§fn batch_fast_into(&mut self, inputs: &[f64], out: &mut [f64])
fn batch_fast_into(&mut self, inputs: &[f64], out: &mut [f64])
SIMD kernel: the half and full WMAs, their 2 · half − full
difference and the smoothing WMA over it, each as the WMA prefix-scan
kernel. Agrees with the exact batch to within a few units in the last
place; warmup NaNs and length are identical. HMA only remembers its
last period + smooth − 1 inputs, so afterwards its state is rebuilt
exactly by replaying them.
Source§fn update(&mut self, input: f64) -> Option<f64>
fn update(&mut self, input: f64) -> Option<f64>
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 Hma
impl RefUnwindSafe for Hma
impl Send for Hma
impl Sync for Hma
impl Unpin for Hma
impl UnsafeUnpin for Hma
impl UnwindSafe for Hma
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> BatchNanExt for T
impl<T> BatchNanExt for T
Source§fn batch_nan(&mut self, inputs: &[f64]) -> Vec<f64>
fn batch_nan(&mut self, inputs: &[f64]) -> Vec<f64>
f64 per input, warmup positions filled with NaN, bit-for-bit equal
to replaying update.Source§fn batch_fast(&mut self, inputs: &[f64]) -> Vec<f64>
fn batch_fast(&mut self, inputs: &[f64]) -> Vec<f64>
Indicator::batch_fast_into) into a fresh
vector: within the indicator’s documented tolerance of
batch_nan, deterministic across platforms.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