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
impl RollImpliedSpread
Sourcepub fn update(&mut self, price_change: Decimal) -> Result<(), FinError>
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.
Sourcepub fn get(&self) -> Option<f64>
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).
Sourcepub fn sample_count(&self) -> usize
pub fn sample_count(&self) -> usize
Returns the number of price changes buffered.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for RollImpliedSpread
impl RefUnwindSafe for RollImpliedSpread
impl Send for RollImpliedSpread
impl Sync for RollImpliedSpread
impl Unpin for RollImpliedSpread
impl UnsafeUnpin for RollImpliedSpread
impl UnwindSafe for RollImpliedSpread
Blanket Implementations§
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