pub struct DemandIndex { /* private fields */ }Expand description
James Sibbet’s Demand Index — a smoothed ratio of buying pressure to selling pressure, classifying each bar’s volume by whether the close rose or fell relative to the previous close.
Sibbet’s original 1970s formulation runs the raw buying/selling pressure
through several smoothings and yields a number that swings in [−100, 100].
This implementation uses the textbook simplified form that captures the same
signal in a streaming-friendly shape:
pressure_t = volume_t · ((close_t − close_{t−1}) / max(close_{t−1}, ε))
· (1 + (high_t − low_t) / max(close_{t−1}, ε))
DI_t = EMA(pressure, period)_tPositive readings mean the smoothed money flow is leaning to the buy side
(up-day volume dominates), negative to the sell side. The first candle only
establishes the previous close, so the first non-None value lands once the
EMA has accumulated period pressure samples. A previous close of zero
contributes no signal (avoids division by zero). The output is unbounded;
what matters is the sign and the divergence against price.
§Example
use wickra_core::{Candle, DemandIndex, Indicator};
let mut indicator = DemandIndex::new(10).unwrap();
let mut last = None;
for i in 0..120 {
let base = 100.0 + f64::from(i);
let candle =
Candle::new(base, base + 2.0, base - 2.0, base + 1.0, 50.0, i64::from(i)).unwrap();
last = indicator.update(candle);
}
assert!(last.is_some());Implementations§
Trait Implementations§
Source§impl Clone for DemandIndex
impl Clone for DemandIndex
Source§fn clone(&self) -> DemandIndex
fn clone(&self) -> DemandIndex
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 DemandIndex
impl Debug for DemandIndex
Source§impl Indicator for DemandIndex
impl Indicator for DemandIndex
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 DemandIndex
impl RefUnwindSafe for DemandIndex
impl Send for DemandIndex
impl Sync for DemandIndex
impl Unpin for DemandIndex
impl UnsafeUnpin for DemandIndex
impl UnwindSafe for DemandIndex
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