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
impl MicrostructureMetrics
Sourcepub fn new(window: usize) -> Result<Self, FinError>
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.
Sourcepub fn update_volume_imbalance(
&mut self,
buy_volume: Decimal,
sell_volume: Decimal,
) -> Result<(), FinError>
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.
Sourcepub fn update_price_impact(
&mut self,
price_change: Decimal,
signed_volume: Decimal,
) -> Result<(), FinError>
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.
Sourcepub fn update_amihud(
&mut self,
prev_close: Decimal,
close: Decimal,
volume: Decimal,
) -> Result<(), FinError>
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.
Sourcepub fn update_roll(&mut self, price_change: Decimal) -> Result<(), FinError>
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.
Sourcepub fn snapshot(&self) -> MicrostructureSnapshot
pub fn snapshot(&self) -> MicrostructureSnapshot
Produce a snapshot of all currently available metrics.
Fields are None until the underlying rolling window is full.