pub struct HighpassFilter { /* private fields */ }Expand description
Ehlers’ two-pole Highpass Filter — strips the low-frequency trend from a price series, leaving the higher-frequency cyclic and noise content.
From John Ehlers’ Cycle Analytics for Traders (2013):
a = 0.707 · 2π / period
alpha1 = (cos(a) + sin(a) − 1) / cos(a)
HP_t = (1 − alpha1/2)² · (price_t − 2·price_{t−1} + price_{t−2})
+ 2·(1 − alpha1)·HP_{t−1} − (1 − alpha1)²·HP_{t−2}A highpass filter is the complement of a smoother: where a lowpass keeps the
trend, the highpass keeps everything faster than the cutoff period. The
two-pole design gives a steep roll-off so frequencies below the cutoff are
firmly removed, detrending the series into a zero-mean wave. This differs from
the Decycler, which is price − highpass (the trend that
remains); the highpass is the cyclic part that the decycler discards.
The recursion needs two prior prices and two prior outputs; until then it emits
0, so warmup_period is 1. Each update is O(1).
§Example
use wickra_core::{Indicator, HighpassFilter};
let mut indicator = HighpassFilter::new(48).unwrap();
let mut last = None;
for i in 0..120 {
last = indicator.update(100.0 + f64::from(i) + (f64::from(i) * 0.5).sin() * 3.0);
}
assert!(last.is_some());Implementations§
Source§impl HighpassFilter
impl HighpassFilter
Sourcepub fn new(period: usize) -> Result<HighpassFilter, Error>
pub fn new(period: usize) -> Result<HighpassFilter, Error>
Construct a two-pole highpass filter with the given cutoff period.
§Errors
Returns Error::PeriodZero if period == 0.
Trait Implementations§
Source§impl Clone for HighpassFilter
impl Clone for HighpassFilter
Source§fn clone(&self) -> HighpassFilter
fn clone(&self) -> HighpassFilter
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 HighpassFilter
impl Debug for HighpassFilter
Source§impl Indicator for HighpassFilter
impl Indicator for HighpassFilter
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 HighpassFilter
impl RefUnwindSafe for HighpassFilter
impl Send for HighpassFilter
impl Sync for HighpassFilter
impl Unpin for HighpassFilter
impl UnsafeUnpin for HighpassFilter
impl UnwindSafe for HighpassFilter
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