pub struct AdaptiveCci { /* private fields */ }Expand description
Adaptive CCI — Lambert’s Commodity Channel Index whose centre line is an efficiency-ratio-adaptive moving average of typical price instead of a plain SMA, so it leads in trends and stays calm in chop.
TP = (high + low + close) / 3
ER = |TP_t − TP_oldest| / Σ |ΔTP| over the window (0..1)
sc = ( ER·(2/3 − 2/31) + 2/31 )²
mean += sc·(TP_t − mean) (adaptive centre, seeded with SMA)
MD = mean(|TP_i − mean|) over the window (mean deviation)
CCI = (TP_t − mean) / (0.015 · MD)The classic Cci centres typical price on its simple moving
average; the lag of that SMA delays the oscillator in fast moves. Replacing it
with a KAMA-style adaptive average — driven by Kaufman’s efficiency ratio —
lets the centre line accelerate toward price in a clean trend (so the CCI
reaches its ±100 bands sooner) and slow down in noise (fewer false pokes).
The 0.015 scaling keeps Lambert’s convention that roughly 70–80% of readings
fall in [−100, +100].
The output is unbounded around 0; a flat window (zero mean deviation) returns
0. The first value lands after period inputs; each update is O(period).
§Example
use wickra_core::{Candle, Indicator, AdaptiveCci};
let mut indicator = AdaptiveCci::new(20).unwrap();
let mut last = None;
for i in 0..60 {
let base = 100.0 + (f64::from(i) * 0.3).sin() * 5.0;
let c = Candle::new(base, base + 1.0, base - 1.0, base, 1_000.0, 0).unwrap();
last = indicator.update(c);
}
assert!(last.is_some());Implementations§
Source§impl AdaptiveCci
impl AdaptiveCci
Sourcepub fn new(period: usize) -> Result<Self>
pub fn new(period: usize) -> Result<Self>
Construct an adaptive CCI with the given period.
§Errors
Returns Error::PeriodZero if period == 0 and
Error::InvalidPeriod if period < 2 (the efficiency ratio needs a
path of at least one step).
Trait Implementations§
Source§impl Clone for AdaptiveCci
impl Clone for AdaptiveCci
Source§fn clone(&self) -> AdaptiveCci
fn clone(&self) -> AdaptiveCci
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 AdaptiveCci
impl Debug for AdaptiveCci
Source§impl Indicator for AdaptiveCci
impl Indicator for AdaptiveCci
Source§type Input = Candle
type Input = Candle
f64 for a price, or Candle / Tick).Source§fn update(&mut self, candle: Candle) -> Option<f64>
fn update(&mut self, candle: Candle) -> 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 AdaptiveCci
impl RefUnwindSafe for AdaptiveCci
impl Send for AdaptiveCci
impl Sync for AdaptiveCci
impl Unpin for AdaptiveCci
impl UnsafeUnpin for AdaptiveCci
impl UnwindSafe for AdaptiveCci
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