Skip to main content

RollImpliedSpread

Struct RollImpliedSpread 

Source
pub struct RollImpliedSpread { /* private fields */ }
Expand description

Roll’s Implied Spread estimator.

Estimates the effective bid-ask spread from serial autocorrelation of price changes:

S = 2 * sqrt(-Cov(ΔP_t, ΔP_{t-1})) when Cov < 0.

When Cov >= 0 (no autocorrelation signal), returns 0.0 (no spread implied).

Returns None until window + 1 price changes have been observed.

§Example

use fin_primitives::microstructure::RollImpliedSpread;
use rust_decimal_macros::dec;

let mut roll = RollImpliedSpread::new(10).unwrap();
// Alternating returns simulate bid-ask bounce
for i in 0..11 {
    let ret = if i % 2 == 0 { dec!(0.05) } else { dec!(-0.05) };
    roll.update(ret).unwrap();
}
let spread = roll.get();
assert!(spread.is_some());

Implementations§

Source§

impl RollImpliedSpread

Source

pub fn new(window: usize) -> Result<Self, FinError>

Constructs a RollImpliedSpread estimator.

§Errors

Returns FinError::InvalidPeriod if window < 2.

Source

pub fn update(&mut self, price_change: Decimal) -> Result<(), FinError>

Records a price change observation.

§Errors

Returns FinError::InvalidInput if the value is non-finite.

Source

pub fn get(&self) -> Option<f64>

Returns the Roll implied spread estimate, or None until ready.

Returns 0.0 when the first-order autocovariance is non-negative (no bounce signal).

Source

pub fn is_ready(&self) -> bool

Returns true when the window is full.

Source

pub fn window(&self) -> usize

Returns the configured window size.

Source

pub fn sample_count(&self) -> usize

Returns the number of price changes buffered.

Source

pub fn reset(&mut self)

Resets the estimator.

Trait Implementations§

Source§

impl Debug for RollImpliedSpread

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.