pub struct Kvo { /* private fields */ }Expand description
Stephen J. Klinger’s Volume Oscillator — a long/short-term volume-force MACD with trend-aware cumulative-money-flow weighting.
Each bar produces a “volume force” (vf) whose sign tracks the daily trend
(+1 on an up day, −1 on a down day, carry-over otherwise) and whose
magnitude scales with how the current bar’s range compares to the range
accumulated since the trend last flipped. The KVO line is the difference of two EMAs of vf:
hlc_t = high_t + low_t + close_t (decides the trend)
trend = sign(hlc_t − hlc_{t−1}) (carried over when equal)
dm_t = high_t − low_t (the "daily measurement")
cm_t = cm_{t−1} + dm_t if trend unchanged
cm_t = dm_{t−1} + dm_t if trend just flipped
vf_t = volume_t · |2·(dm_t/cm_t − 1)| · trend · 100
KVO_t = EMA(vf, fast)_t − EMA(vf, slow)_tKlinger’s textbook configuration is fast = 34, slow = 55 on daily bars.
The first bar only seeds dm_{t−1}, so the very first vf lands at bar 2;
the slow EMA then needs slow raw vf values to seed, putting the first
KVO emission at bar slow + 1. A zero cm_t (only possible when every bar
since the last flip has a zero range) collapses vf to 0.
§Example
use wickra_core::{Candle, Indicator, Kvo};
let mut indicator = Kvo::new(34, 55).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, 10.0, i64::from(i)).unwrap();
last = indicator.update(candle);
}
assert!(last.is_some());Implementations§
Trait Implementations§
Source§impl Indicator for Kvo
impl Indicator for Kvo
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 Kvo
impl RefUnwindSafe for Kvo
impl Send for Kvo
impl Sync for Kvo
impl Unpin for Kvo
impl UnsafeUnpin for Kvo
impl UnwindSafe for Kvo
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