Skip to main content

MicrostructureMetrics

Struct MicrostructureMetrics 

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

Feeds real-time market data into all microstructure estimators and produces aggregate MicrostructureSnapshots on demand.

§Example

use fin_primitives::microstructure::MicrostructureMetrics;
use rust_decimal_macros::dec;

let mut m = MicrostructureMetrics::new(5).unwrap();
for _ in 0..5 {
    m.update_spread(dec!(99.90), dec!(100.10)).unwrap();
    m.update_volume_imbalance(dec!(600), dec!(400)).unwrap();
    m.update_price_impact(dec!(0.05), dec!(100)).unwrap();
    m.update_amihud(dec!(100), dec!(102), dec!(1000)).unwrap();
    m.update_roll(dec!(0.05)).unwrap();
}
let snap = m.snapshot();
assert!(snap.avg_spread_bps.is_some());

Implementations§

Source§

impl MicrostructureMetrics

Source

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

Create a new aggregator with the given rolling window for all sub-trackers.

KyleLambda and RollImpliedSpread require window >= 2.

§Errors

Returns FinError::InvalidPeriod if window < 2.

Source

pub fn update_spread( &mut self, bid: Decimal, ask: Decimal, ) -> Result<(), FinError>

Feed a bid/ask quote into the spread tracker.

§Errors

Propagates errors from BidAskSpread::update.

Source

pub fn update_volume_imbalance( &mut self, buy_volume: Decimal, sell_volume: Decimal, ) -> Result<(), FinError>

Feed a buy/sell volume observation into the order imbalance tracker.

§Errors

Propagates errors from OrderImbalance::update.

Source

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

Feed a price-change / signed-volume pair into the Kyle’s lambda estimator.

§Errors

Propagates errors from KyleLambda::update.

Source

pub fn update_amihud( &mut self, prev_close: Decimal, close: Decimal, volume: Decimal, ) -> Result<(), FinError>

Feed a prev/current close and volume into the Amihud illiquidity estimator.

§Errors

Propagates errors from AmihudIlliquidity::update.

Source

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

Feed a price change into the Roll spread estimator.

§Errors

Propagates errors from RollImpliedSpread::update.

Source

pub fn snapshot(&self) -> MicrostructureSnapshot

Produce a snapshot of all currently available metrics.

Fields are None until the underlying rolling window is full.

Source

pub fn reset(&mut self)

Reset all sub-trackers.

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.