pub struct AdaptiveLaguerreFilter { /* private fields */ }Expand description
John Ehlers’ Adaptive Laguerre Filter — a four-stage Laguerre polynomial
smoother whose damping factor gamma is recomputed every bar from how well
the filter is currently tracking price.
The Laguerre cascade is the same one used by LaguerreRsi,
but instead of a fixed gamma the filter adapts: it measures the recent
absolute error |price − filter|, normalises those errors across a window of
period bars to [0, 1], and takes their median as gamma. When price
is tracking smoothly the errors are small and uniform (low gamma, fast
response); when price jumps, the spread of errors widens and gamma rises,
slowing the filter to reject the noise.
diff_t = |price_t − filter_{t-1}|
over the last `period` diffs:
HH = max(diff), LL = min(diff)
norm_i = (diff_i − LL) / (HH − LL) (0 if HH == LL)
gamma = median(norm)
alpha = 1 − gamma
L0_t = alpha·price_t + gamma·L0_{t-1}
L1_t = −gamma·L0_t + L0_{t-1} + gamma·L1_{t-1}
L2_t = −gamma·L1_t + L1_{t-1} + gamma·L2_{t-1}
L3_t = −gamma·L2_t + L2_{t-1} + gamma·L3_{t-1}
filter_t = (L0_t + 2·L1_t + 2·L2_t + L3_t) / 6The output is a smoothed price on the same scale as the input. The first
emission lands once the error window holds period values.
Reference: John F. Ehlers, “Adaptive Laguerre Filter”, Technical Analysis of Stocks & Commodities, 2007.
§Example
use wickra_core::{Indicator, AdaptiveLaguerreFilter};
let mut indicator = AdaptiveLaguerreFilter::new(13).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 AdaptiveLaguerreFilter
impl AdaptiveLaguerreFilter
Sourcepub fn new(period: usize) -> Result<AdaptiveLaguerreFilter, Error>
pub fn new(period: usize) -> Result<AdaptiveLaguerreFilter, Error>
Construct a new adaptive Laguerre filter with the given error-window length.
§Errors
Returns Error::PeriodZero if period == 0.
Trait Implementations§
Source§impl Clone for AdaptiveLaguerreFilter
impl Clone for AdaptiveLaguerreFilter
Source§fn clone(&self) -> AdaptiveLaguerreFilter
fn clone(&self) -> AdaptiveLaguerreFilter
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 AdaptiveLaguerreFilter
impl Debug for AdaptiveLaguerreFilter
Source§impl Indicator for AdaptiveLaguerreFilter
impl Indicator for AdaptiveLaguerreFilter
Source§fn update(&mut self, price: f64) -> Option<f64>
fn update(&mut self, price: f64) -> Option<f64>
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 AdaptiveLaguerreFilter
impl RefUnwindSafe for AdaptiveLaguerreFilter
impl Send for AdaptiveLaguerreFilter
impl Sync for AdaptiveLaguerreFilter
impl Unpin for AdaptiveLaguerreFilter
impl UnsafeUnpin for AdaptiveLaguerreFilter
impl UnwindSafe for AdaptiveLaguerreFilter
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§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