pub struct EffectiveSpread { /* private fields */ }Expand description
Effective Spread — twice the signed deviation of an executed trade price from the prevailing mid, expressed in basis points of the mid.
effectiveSpread = 2 · D · (tradePrice − mid) / mid · 10_000 (bps)where D is the aggressor sign (+1 for a buy, −1 for a sell). The
factor of two scales the one-sided deviation up to a full round-trip cost so
it is directly comparable to the quoted spread: a marketable order that
fills exactly at the touch of an otherwise quoted-spread book pays an
effective spread equal to the quoted spread. Trades that fill inside the
spread (price improvement) read below the quoted spread; trades that walk
the book read above it.
A buy printed above the mid (tradePrice > mid) and a sell printed below it
both yield a positive effective spread — the conventional sign, since the
aggressor pays in both cases. A trade printed on the wrong side of the mid
for its aggressor flag (a buy below the mid) reads negative, the signature of
price improvement or a stale/mislabelled quote.
Input = TradeQuote, Output = f64. Stateless; ready after the first
trade-quote.
§Example
use wickra_core::{EffectiveSpread, Indicator, Side, Trade, TradeQuote};
let mut es = EffectiveSpread::new();
// Buy filled at 100.05 against a mid of 100.0:
// 2 · (+1) · (100.05 − 100.0) / 100.0 · 10_000 = 10 bps.
let trade = Trade::new(100.05, 1.0, Side::Buy, 0).unwrap();
let quote = TradeQuote::new(trade, 100.0).unwrap();
assert!((es.update(quote).unwrap() - 10.0).abs() < 1e-9);Implementations§
Trait Implementations§
Source§impl Clone for EffectiveSpread
impl Clone for EffectiveSpread
Source§fn clone(&self) -> EffectiveSpread
fn clone(&self) -> EffectiveSpread
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for EffectiveSpread
impl Debug for EffectiveSpread
Source§impl Default for EffectiveSpread
impl Default for EffectiveSpread
Source§fn default() -> EffectiveSpread
fn default() -> EffectiveSpread
Source§impl Indicator for EffectiveSpread
impl Indicator for EffectiveSpread
Source§type Input = TradeQuote
type Input = TradeQuote
f64 for a price, or Candle / Tick).Source§fn update(&mut self, quote: TradeQuote) -> Option<f64>
fn update(&mut self, quote: TradeQuote) -> Option<f64>
None if the indicator is still warming up.Source§fn reset(&mut self)
fn reset(&mut self)
Source§fn warmup_period(&self) -> usize
fn warmup_period(&self) -> usize
None output can be produced.Auto Trait Implementations§
impl Freeze for EffectiveSpread
impl RefUnwindSafe for EffectiveSpread
impl Send for EffectiveSpread
impl Sync for EffectiveSpread
impl Unpin for EffectiveSpread
impl UnsafeUnpin for EffectiveSpread
impl UnwindSafe for EffectiveSpread
Blanket Implementations§
Source§impl<T> BatchExt for Twhere
T: Indicator,
impl<T> BatchExt for Twhere
T: Indicator,
Source§fn batch(&mut self, inputs: &[Self::Input]) -> Vec<Option<Self::Output>>
fn batch(&mut self, inputs: &[Self::Input]) -> Vec<Option<Self::Output>>
None during warmup) per input.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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more