pub struct TradeSignAutocorrelation { /* private fields */ }Expand description
Trade-Sign Autocorrelation — the lag-1 autocorrelation of the trade sign
(+1 buy, −1 sell), measuring how strongly signed order flow persists.
s_t = +1 if the trade is a buy, −1 if a sell
ρ1 = mean over the window of ( s_t · s_{t−1} ) ∈ [−1, +1]In real markets trade signs are strongly positively autocorrelated: a buy tends to be followed by another buy (and a sell by a sell), because large parent orders are split into many child trades and because of order-splitting and herding. A high reading therefore indicates persistent directional pressure — a footprint of informed or algorithmic execution — while a reading near zero signals balanced, uninformed flow and a negative reading signals alternating (bid-ask bounce) flow.
The output is the mean product of consecutive signs, bounded in [−1, +1]. The
first value lands after period trades. Each update is O(period).
§Example
use wickra_core::{Indicator, Side, Trade, TradeSignAutocorrelation};
let mut indicator = TradeSignAutocorrelation::new(20).unwrap();
let mut last = None;
for i in 0..40 {
let side = if i % 2 == 0 { Side::Buy } else { Side::Sell };
last = indicator.update(Trade::new(100.0, 1.0, side, i).unwrap());
}
// Perfectly alternating signs -> autocorrelation -1.
assert!((last.unwrap() + 1.0).abs() < 1e-9);Implementations§
Source§impl TradeSignAutocorrelation
impl TradeSignAutocorrelation
Trait Implementations§
Source§impl Clone for TradeSignAutocorrelation
impl Clone for TradeSignAutocorrelation
Source§fn clone(&self) -> TradeSignAutocorrelation
fn clone(&self) -> TradeSignAutocorrelation
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 TradeSignAutocorrelation
impl Debug for TradeSignAutocorrelation
Source§impl Indicator for TradeSignAutocorrelation
impl Indicator for TradeSignAutocorrelation
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 TradeSignAutocorrelation
impl RefUnwindSafe for TradeSignAutocorrelation
impl Send for TradeSignAutocorrelation
impl Sync for TradeSignAutocorrelation
impl Unpin for TradeSignAutocorrelation
impl UnsafeUnpin for TradeSignAutocorrelation
impl UnwindSafe for TradeSignAutocorrelation
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