pub struct DemandIndex { /* private fields */ }Expand description
James Sibbet’s Demand Index — the ratio of buying pressure to selling
pressure, bounded in [−100, +100].
Each bar’s volume (relative to its period average) is assigned in full to
the side the weighted close moved towards, and the other side receives that
volume damped exponentially by the size of the move against the market’s
typical range. Both pressures are exponentially smoothed and compared. This is
Sibbet’s construction as published in the TradeStation DemandIndex
function:
WC = (high + low + 2·close) / 4
ratio = (WC_t − WC_{t−1}) / min(WC_t, WC_{t−1})
vol = volume / SMA(volume, period)
K = 3·WC / SMA(max(high, high_{t−1}) − min(low, low_{t−1}), period)
damped = vol / exp(min(K · |ratio|, 88))
ratio > 0: BP = vol, SP = damped
otherwise: BP = damped, SP = vol
B, S = EMA(BP, period), EMA(SP, period) (seeded with the first value)
DI = +100 · (1 − S / B) if B > S
−100 · (1 − B / S) if B < S
0 if B = SPositive readings mean buying pressure dominates, negative selling pressure;
the magnitude says by how much. A bar whose averages or weighted closes are
zero carries no measurable pressure and repeats the previous reading. The
first value lands once the two-bar range average is full, on bar period + 1.
§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§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 there is no value for this input. Read moreSource§fn reset(&mut self)
fn reset(&mut self)
Source§fn warmup_period(&self) -> usize
fn warmup_period(&self) -> usize
None output can be produced.Source§fn is_ready(&self) -> bool
fn is_ready(&self) -> bool
Source§fn name(&self) -> &'static str
fn name(&self) -> &'static str
Source§fn batch_nan_into(&mut self, inputs: &[Self::Input], out: &mut [f64])
fn batch_nan_into(&mut self, inputs: &[Self::Input], out: &mut [f64])
Source§fn batch_fast_into(&mut self, inputs: &[Self::Input], out: &mut [f64])
fn batch_fast_into(&mut self, inputs: &[Self::Input], out: &mut [f64])
batch_nan_into, but
an indicator with a vectorised kernel may reassociate its arithmetic to
run it in SIMD lanes. Each value then agrees with the exact batch to within
the tolerance the indicator documents (a few units in the last place), not
bit for bit; warmup positions, NaN placement and the output length are
identical. The kernels are deterministic: the same input produces the same
bits on every platform, with or without SIMD hardware. Read moreAuto 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