pub struct Vpin { /* private fields */ }Expand description
VPIN — the Volume-Synchronised Probability of Informed Trading (Easley, López de Prado & O’Hara, 2012).
Trades are bucketed into equal-volume buckets of size bucket_volume. For
each completed bucket the order-flow imbalance is the absolute difference
between buy and sell volume; VPIN is that imbalance averaged over the last
num_buckets buckets and normalised by the bucket size:
VPIN = ( Σ |Vᴮ_τ − Vˢ_τ| ) / (num_buckets · bucket_volume)The aggressor Side of each Trade classifies its volume directly (no
bulk-volume classification needed). A single trade may span several buckets;
its volume is split across bucket boundaries. The result lies in [0, 1]:
values near 1 signal a strongly one-sided, likely-informed flow (a toxic
regime), values near 0 a balanced two-sided flow.
Input = Trade. Because bucket completion is driven by cumulative volume,
readiness is data-dependent; warmup_period
reports num_buckets as the minimum number of trades (one per bucket) and
is_ready reflects the true bucket count.
§Example
use wickra_core::{Indicator, Side, Trade, Vpin};
let mut vpin = Vpin::new(10.0, 2).unwrap();
// Two buckets of pure buying => imbalance == bucket size => VPIN 1.
let mut last = None;
for _ in 0..4 {
last = vpin.update(Trade::new(100.0, 5.0, Side::Buy, 0).unwrap());
}
assert_eq!(last, Some(1.0));Implementations§
Trait Implementations§
Source§impl Indicator for Vpin
impl Indicator for Vpin
Source§type Input = Trade
type Input = Trade
f64 for a price, or Candle / Tick).Source§fn update(&mut self, trade: Trade) -> Option<f64>
fn update(&mut self, trade: Trade) -> 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 Vpin
impl RefUnwindSafe for Vpin
impl Send for Vpin
impl Sync for Vpin
impl Unpin for Vpin
impl UnsafeUnpin for Vpin
impl UnwindSafe for Vpin
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