pub struct BidAskSpread { /* private fields */ }Expand description
Rolling average bid-ask spread tracker, expressed in basis points.
Feed bid/ask prices via update. Once window samples
have been seen, average_spread_bps returns
the rolling average.
Basis points = (ask - bid) / mid * 10_000.
§Example
use fin_primitives::microstructure::BidAskSpread;
use rust_decimal_macros::dec;
let mut tracker = BidAskSpread::new(5).unwrap();
for _ in 0..5 {
tracker.update(dec!(99.90), dec!(100.10)).unwrap();
}
let spread_bps = tracker.average_spread_bps().unwrap();
// spread = 0.20, mid = 100.0 → 20 bps
assert!((spread_bps - 20.0).abs() < 0.01);Implementations§
Source§impl BidAskSpread
impl BidAskSpread
Sourcepub fn average_spread_bps(&self) -> Option<f64>
pub fn average_spread_bps(&self) -> Option<f64>
Returns the rolling average spread in basis points, or None if not yet ready.
Sourcepub fn sample_count(&self) -> usize
pub fn sample_count(&self) -> usize
Returns the number of samples buffered.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for BidAskSpread
impl RefUnwindSafe for BidAskSpread
impl Send for BidAskSpread
impl Sync for BidAskSpread
impl Unpin for BidAskSpread
impl UnsafeUnpin for BidAskSpread
impl UnwindSafe for BidAskSpread
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