pub struct DepthSlope { /* private fields */ }Expand description
Depth Slope — the average rate at which cumulative resting size grows with distance from the mid, across the bid and ask sides of the book.
For each side the indicator runs an ordinary-least-squares regression of cumulative size (walking outward from the touch) on the level’s distance from the mid, then reports the mean of the two slopes:
slope_side = OLS slope of (|priceᵢ − mid|, Σ_{j≤i} sizeⱼ)
depthSlope = (slope_bid + slope_ask) / 2Because the response is cumulative size it never decreases with distance, so the slope is non-negative: it is a magnitude, not a direction. A large slope means cumulative liquidity builds quickly away from the touch — a deep book that absorbs large orders with little walking; a small slope is a thin, shallow book. A book whose size is concentrated at the touch and thins out behind it (a fragile book) reads a smaller slope than one of equal total depth that thickens with distance.
A side with fewer than two levels carries no slope, so the indicator returns
0.0 whenever either side has fewer than two levels (including an empty
book).
Input = OrderBook, Output = f64. Stateless; ready after the first
snapshot.
§Example
use wickra_core::{DepthSlope, Indicator, Level, OrderBook};
// Both sides thicken linearly away from the mid (sizes 1, 2, 3 …).
let book = OrderBook::new(
vec![Level::new(99.0, 1.0).unwrap(), Level::new(98.0, 2.0).unwrap()],
vec![Level::new(101.0, 1.0).unwrap(), Level::new(102.0, 2.0).unwrap()],
)
.unwrap();
let mut ds = DepthSlope::new();
assert!(ds.update(book).unwrap() > 0.0);Implementations§
Source§impl DepthSlope
impl DepthSlope
Trait Implementations§
Source§impl Clone for DepthSlope
impl Clone for DepthSlope
Source§fn clone(&self) -> DepthSlope
fn clone(&self) -> DepthSlope
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 DepthSlope
impl Debug for DepthSlope
Source§impl Default for DepthSlope
impl Default for DepthSlope
Source§fn default() -> DepthSlope
fn default() -> DepthSlope
Source§impl Indicator for DepthSlope
impl Indicator for DepthSlope
Source§type Input = OrderBook
type Input = OrderBook
f64 for a price, or Candle / Tick).Source§fn update(&mut self, book: OrderBook) -> Option<f64>
fn update(&mut self, book: OrderBook) -> 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 DepthSlope
impl RefUnwindSafe for DepthSlope
impl Send for DepthSlope
impl Sync for DepthSlope
impl Unpin for DepthSlope
impl UnsafeUnpin for DepthSlope
impl UnwindSafe for DepthSlope
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