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
Sourcepub fn new(period: usize) -> Result<RollMeasure, Error>
pub fn new(period: usize) -> Result<RollMeasure, Error>
Construct a new Roll Measure over the given window of price changes.
§Errors
Returns Error::InvalidPeriod if period < 3 — the lag-1
autocovariance needs at least two consecutive change pairs.
Trait Implementations§
Source§impl Clone for RollMeasure
impl Clone for RollMeasure
Source§fn clone(&self) -> RollMeasure
fn clone(&self) -> RollMeasure
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 RollMeasure
impl Debug for RollMeasure
Source§impl Indicator for RollMeasure
impl Indicator for RollMeasure
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 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>>
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