pub struct CorrelationTrendIndicator { /* private fields */ }Expand description
Ehlers’ Correlation Trend Indicator (CTI) — the Pearson correlation coefficient between price and a perfectly straight ramp over the lookback.
CTI = corr( price over the window , [0, 1, …, period−1] )John Ehlers’ CTI asks “how closely does recent price track a straight line?”
by correlating the windowed price against the time index itself. A reading near
+1 means price is rising in a near-perfect line (strong uptrend); near −1
means a clean downtrend; near 0 means no linear trend (a range or choppy
market). Because correlation is scale- and offset-invariant, the slope’s
steepness does not matter — only how linear the move is — which makes CTI an
unusually clean trend/range classifier. It differs from
Autocorrelation, which correlates price with a
lagged copy of itself rather than with time.
The output is in [−1, +1]; a flat window (zero price variance) returns 0.
The first value lands after period inputs; each update recomputes the
correlation over the window in O(period).
§Example
use wickra_core::{Indicator, CorrelationTrendIndicator};
let mut indicator = CorrelationTrendIndicator::new(20).unwrap();
let mut last = None;
for i in 0..40 {
last = indicator.update(100.0 + f64::from(i)); // a clean uptrend
}
assert!((last.unwrap() - 1.0).abs() < 1e-9);Implementations§
Source§impl CorrelationTrendIndicator
impl CorrelationTrendIndicator
Trait Implementations§
Source§impl Clone for CorrelationTrendIndicator
impl Clone for CorrelationTrendIndicator
Source§fn clone(&self) -> CorrelationTrendIndicator
fn clone(&self) -> CorrelationTrendIndicator
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 CorrelationTrendIndicator
impl Debug for CorrelationTrendIndicator
Source§impl Indicator for CorrelationTrendIndicator
impl Indicator for CorrelationTrendIndicator
Source§fn update(&mut self, input: f64) -> Option<f64>
fn update(&mut self, input: 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 CorrelationTrendIndicator
impl RefUnwindSafe for CorrelationTrendIndicator
impl Send for CorrelationTrendIndicator
impl Sync for CorrelationTrendIndicator
impl Unpin for CorrelationTrendIndicator
impl UnsafeUnpin for CorrelationTrendIndicator
impl UnwindSafe for CorrelationTrendIndicator
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