pub struct RollMeasure { /* private fields */ }Expand description
Roll Measure — the effective bid-ask spread implied by the negative first-order serial covariance of trade-price changes (Roll, 1984).
Δpₜ = priceₜ − priceₜ₋₁
γ = sample lag-1 autocovariance of Δp over the last `period` changes
spread = 2 · √(−γ) if γ < 0, else 0Roll’s insight: in a frictionless market price changes are serially
uncorrelated, but the bid-ask bounce — trades alternating between buying at
the ask and selling at the bid — induces a negative autocovariance whose
magnitude pins the spread. The measure recovers an effective spread from
trade prices alone, with no quote data. When the serial covariance is
non-negative (a trending or frictionless tape) the model implies no spread
and the indicator returns 0.
Input = Trade (only the price is used). Each update is O(period): the
autocovariance is recomputed from the window of price changes.
§Example
use wickra_core::{Indicator, Side, Trade, RollMeasure};
let mut roll = RollMeasure::new(20).unwrap();
let mut last = None;
// A clean bid-ask bounce of ±0.5 around 100 implies a spread near 1.0.
for i in 0..40 {
let price = if i % 2 == 0 { 100.0 } else { 101.0 };
last = roll.update(Trade::new(price, 1.0, Side::Buy, 0).unwrap());
}
assert!(last.unwrap() > 0.0);Implementations§
Source§impl RollMeasure
impl RollMeasure
Trait Implementations§
Source§impl Clone for RollMeasure
impl Clone for RollMeasure
Source§fn clone(&self) -> RollMeasure
fn clone(&self) -> RollMeasure
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for RollMeasure
impl Debug for RollMeasure
Source§impl Indicator for RollMeasure
impl Indicator for RollMeasure
Source§type Input = Trade
type Input = Trade
Type of one input data point (typically
f64 for a price, or Candle / Tick).Source§fn update(&mut self, trade: Trade) -> Option<f64>
fn update(&mut self, trade: Trade) -> Option<f64>
Feed one new data point into the indicator and return the freshly computed
output, or
None if the indicator is still warming up.Source§fn reset(&mut self)
fn reset(&mut self)
Reset all internal state, leaving the indicator equivalent to a freshly
constructed instance with the same parameters.
Source§fn warmup_period(&self) -> usize
fn warmup_period(&self) -> usize
Number of inputs required before the first non-
None output can be produced.Auto Trait Implementations§
impl Freeze for RollMeasure
impl RefUnwindSafe for RollMeasure
impl Send for RollMeasure
impl Sync for RollMeasure
impl Unpin for RollMeasure
impl UnsafeUnpin for RollMeasure
impl UnwindSafe for RollMeasure
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>>
Run the indicator over a slice of inputs in order, returning one output (or
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
Mutably borrows from an owned value. Read more
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>
Converts
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>
Converts
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