pub struct OrderImbalance { /* private fields */ }Expand description
Rolling buy/sell volume order imbalance measure.
OIR = (V_buy - V_sell) / (V_buy + V_sell) for each bar.
Rolling mean over the configured window.
Range: [-1.0, 1.0]. Positive values indicate buy-side pressure.
§Example
use fin_primitives::microstructure::OrderImbalance;
use rust_decimal_macros::dec;
let mut oi = OrderImbalance::new(3).unwrap();
oi.update(dec!(600), dec!(400)).unwrap(); // OIR = 0.2
oi.update(dec!(700), dec!(300)).unwrap(); // OIR = 0.4
oi.update(dec!(800), dec!(200)).unwrap(); // OIR = 0.6
let imbalance = oi.get().unwrap();
assert!(imbalance > 0.0, "positive buy pressure: {imbalance}");Implementations§
Source§impl OrderImbalance
impl OrderImbalance
Sourcepub fn update(
&mut self,
buy_volume: Decimal,
sell_volume: Decimal,
) -> Result<(), FinError>
pub fn update( &mut self, buy_volume: Decimal, sell_volume: Decimal, ) -> Result<(), FinError>
Records a volume observation.
buy_volume: aggressive buy volume for the bar (must be >= 0).sell_volume: aggressive sell volume for the bar (must be >= 0).
§Errors
Returns FinError::InvalidInput if both volumes are zero or either is negative.
Sourcepub fn get(&self) -> Option<f64>
pub fn get(&self) -> Option<f64>
Returns the rolling mean order imbalance ratio, or None until 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 OrderImbalance
impl RefUnwindSafe for OrderImbalance
impl Send for OrderImbalance
impl Sync for OrderImbalance
impl Unpin for OrderImbalance
impl UnsafeUnpin for OrderImbalance
impl UnwindSafe for OrderImbalance
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