pub struct AutocorrelationPeriodogram { /* private fields */ }Expand description
Ehlers’ Autocorrelation Periodogram — measures the dominant cycle period of the market by correlating a roofing-filtered price with lagged copies of itself and reading off the spectral peak.
From John Ehlers’ Cycle Analytics for Traders (2013, ch. 8):
Filt = RoofingFilter(price) (detrend + denoise)
Corr[lag] = Pearson( Filt[0..AvgLength], Filt[lag..lag+AvgLength] ) for lag = 0..max_period
for each candidate period:
power[period] = (Σ Corr[N]·cos(2πN/period))² + (Σ Corr[N]·sin(2πN/period))²
R[period] = 0.2·power[period] + 0.8·R[period]_{t−1} (EMA across time)
normalise by a decaying max, then
DominantCycle = centre-of-gravity of periods whose normalised power ≥ 0.5The autocorrelation function emphasises whatever cycle is actually present and
suppresses noise; transforming it into a periodogram and taking the
power-weighted centre of gravity gives a smooth, robust estimate of the
dominant cycle length. That cycle is the key input for every adaptive
indicator (adaptive RSI/CCI/stochastic) — set their lookback from it. The
output is a period in bars within [min_period, max_period].
The first value lands after max_period + AvgLength inputs. Each update is
O(max_period²).
§Example
use wickra_core::{Indicator, AutocorrelationPeriodogram};
use std::f64::consts::TAU;
let mut indicator = AutocorrelationPeriodogram::new(10, 48).unwrap();
let mut last = None;
for i in 0..200 {
last = indicator.update(100.0 + (TAU * f64::from(i) / 20.0).sin() * 5.0);
}
assert!(last.is_some());Implementations§
Source§impl AutocorrelationPeriodogram
impl AutocorrelationPeriodogram
Sourcepub fn new(min_period: usize, max_period: usize) -> Result<Self>
pub fn new(min_period: usize, max_period: usize) -> Result<Self>
Construct an autocorrelation periodogram searching cycles in
[min_period, max_period].
§Errors
Returns Error::PeriodZero if either period is 0, or
Error::InvalidPeriod if min_period < AvgLength + 1 or
max_period <= min_period.
Trait Implementations§
Source§impl Clone for AutocorrelationPeriodogram
impl Clone for AutocorrelationPeriodogram
Source§fn clone(&self) -> AutocorrelationPeriodogram
fn clone(&self) -> AutocorrelationPeriodogram
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 AutocorrelationPeriodogram
impl Debug for AutocorrelationPeriodogram
Source§impl Indicator for AutocorrelationPeriodogram
impl Indicator for AutocorrelationPeriodogram
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 AutocorrelationPeriodogram
impl RefUnwindSafe for AutocorrelationPeriodogram
impl Send for AutocorrelationPeriodogram
impl Sync for AutocorrelationPeriodogram
impl Unpin for AutocorrelationPeriodogram
impl UnsafeUnpin for AutocorrelationPeriodogram
impl UnwindSafe for AutocorrelationPeriodogram
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