Skip to main content

OrderImbalance

Struct OrderImbalance 

Source
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

Source

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

Constructs an OrderImbalance tracker.

§Errors

Returns FinError if window == 0.

Source

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.

Source

pub fn get(&self) -> Option<f64>

Returns the rolling mean order imbalance ratio, or None until ready.

Source

pub fn is_ready(&self) -> bool

Returns true when the window is full.

Source

pub fn window(&self) -> usize

Returns the configured window size.

Source

pub fn sample_count(&self) -> usize

Returns the number of samples buffered.

Source

pub fn reset(&mut self)

Resets the tracker.

Trait Implementations§

Source§

impl Debug for OrderImbalance

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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.