pub struct Pin { /* private fields */ }Expand description
PIN — the Probability of Informed Trading, estimated from the buy/sell order imbalance over a rolling window of trades.
over the last `window` trades: B = buys, S = sells (B + S = window)
PIN ≈ |B − S| / (B + S) ∈ [0, 1]The Easley-Kiefer-O’Hara-Paperman (EKOP) model splits order flow into an
uninformed component (balanced buys and sells, rate ε per side) and an
informed component that trades one-directionally when private information
arrives (rate μ, probability α). The probability that any given trade is
information-motivated is PIN = αμ / (αμ + 2ε). Estimated over a single window,
the informed flow shows up as the net imbalance |B − S| and the uninformed
flow as the balanced remainder, giving the moment estimator above. A high PIN
flags a one-sided, likely-informed market; a low PIN flags balanced, uninformed
flow.
This is distinct from Vpin, the volume-synchronised variant
that buckets by volume and uses bulk-volume classification; here trades are
counted in event time and classified by their tagged aggressor side. The full
PIN is fit by maximum likelihood over many periods — this single-window
estimator is the streaming moment approximation. The output is in [0, 1]; the
first value lands after window trades.
§Example
use wickra_core::{Indicator, Pin, Side, Trade};
let mut indicator = Pin::new(20).unwrap();
let mut last = None;
for i in 0..40 {
// All buys -> maximally one-sided -> PIN 1.
last = indicator.update(Trade::new(100.0, 1.0, Side::Buy, i).unwrap());
}
assert!((last.unwrap() - 1.0).abs() < 1e-9);Implementations§
Trait Implementations§
Source§impl Indicator for Pin
impl Indicator for Pin
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 Pin
impl RefUnwindSafe for Pin
impl Send for Pin
impl Sync for Pin
impl Unpin for Pin
impl UnsafeUnpin for Pin
impl UnwindSafe for Pin
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