Skip to main content

KyleLambda

Struct KyleLambda 

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

Kyle’s Lambda — estimated market impact coefficient.

Estimates how much the price moves per unit of signed order flow (volume imbalance). Computed as OLS slope of price change on signed volume:

λ = Cov(ΔP, ΔQ) / Var(ΔQ)

where ΔQ is signed volume (positive = buy-initiated, negative = sell-initiated).

Returns None until the window is full or if signed volume has zero variance.

§Example

use fin_primitives::microstructure::KyleLambda;
use rust_decimal_macros::dec;

let mut kl = KyleLambda::new(4).unwrap();
kl.update(dec!(0.10), dec!(200)).unwrap();
kl.update(dec!(0.05), dec!(100)).unwrap();
kl.update(dec!(-0.08), dec!(-150)).unwrap();
kl.update(dec!(0.12), dec!(250)).unwrap();
let lambda = kl.get(); // Some(estimated lambda)

Implementations§

Source§

impl KyleLambda

Source

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

Constructs a KyleLambda estimator.

§Errors

Returns FinError::InvalidPeriod if window < 2.

Source

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

Records a price change and signed volume observation.

  • price_change: close_t - close_{t-1} (can be negative).
  • signed_volume: net order flow (positive = buy pressure, negative = sell pressure).
§Errors

Returns FinError::InvalidInput if either value is non-finite.

Source

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

Returns the estimated Kyle’s lambda, 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 estimator.

Trait Implementations§

Source§

impl Debug for KyleLambda

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.