pub struct UniversalOscillator { /* private fields */ }Expand description
Ehlers’ Universal Oscillator — a cycle oscillator that whitens the price
series, SuperSmooths it, then normalises with an automatic gain control (AGC)
to swing in [−1, +1].
From John Ehlers’ Cycle Analytics for Traders (2013):
WhiteNoise = (price_t − price_{t−2}) / 2 (flat-spectrum prewhitening)
Filt = SuperSmoother(WhiteNoise, period)
Peak = max(|Filt|, 0.991 · Peak_{t−1}) (decaying peak / AGC)
Universal = Filt / Peak (0 if Peak == 0)“Whitening” the input (a two-bar difference) flattens its power spectrum so the
SuperSmoother responds equally to all cycles rather than being dominated by the
trend. The automatic gain control divides by a slowly-decaying running peak, so
the output is amplitude-normalised to [−1, +1] and behaves consistently
across instruments and volatility regimes — hence “universal”. Read it like any
bounded oscillator: turns near the rails flag cycle extremes, zero-crossings
flag cycle direction changes.
The first value lands once a two-bar difference exists (warmup_period == 3).
Each update is O(1).
§Example
use wickra_core::{Indicator, UniversalOscillator};
let mut indicator = UniversalOscillator::new(20).unwrap();
let mut last = None;
for i in 0..80 {
last = indicator.update(100.0 + (f64::from(i) * 0.3).sin() * 5.0);
}
assert!(last.is_some());Implementations§
Source§impl UniversalOscillator
impl UniversalOscillator
Trait Implementations§
Source§impl Clone for UniversalOscillator
impl Clone for UniversalOscillator
Source§fn clone(&self) -> UniversalOscillator
fn clone(&self) -> UniversalOscillator
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 UniversalOscillator
impl Debug for UniversalOscillator
Source§impl Indicator for UniversalOscillator
impl Indicator for UniversalOscillator
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 UniversalOscillator
impl RefUnwindSafe for UniversalOscillator
impl Send for UniversalOscillator
impl Sync for UniversalOscillator
impl Unpin for UniversalOscillator
impl UnsafeUnpin for UniversalOscillator
impl UnwindSafe for UniversalOscillator
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