pub struct DistanceSsd { /* private fields */ }Expand description
Sum of squared deviations between two price series, normalised to a common start — the classic Gatev et al. pairs-selection distance.
Each update takes one (a, b) price pair. Over the trailing window of
period pairs each series is rebased to 1 at the window’s first bar and
the squared gap between the two normalised paths is summed:
ãᵢ = aᵢ / a_first b̃ᵢ = bᵢ / b_first
SSD = Σ (ãᵢ − b̃ᵢ)²Rebasing puts the two series on the same scale (both start at 1), so the
distance measures how far their relative paths drift apart. A small
SSD means the two assets track each other tightly — the screen Gatev,
Goetzmann and Rouwenhorst use to pick tradeable pairs; a large SSD means
they have decoupled. The output is always ≥ 0. If either series is 0 at
the start of the window the normalisation is undefined and the indicator
returns 0.
Each update is O(period), bounded by the fixed window.
§Example
use wickra_core::{DistanceSsd, Indicator};
let mut d = DistanceSsd::new(20).unwrap();
let mut last = None;
for t in 0..40 {
let base = 100.0 + f64::from(t);
// Two near-identical paths ⇒ tiny distance.
last = d.update((base, base * 1.0001));
}
assert!(last.unwrap() < 1e-3);Implementations§
Trait Implementations§
Source§impl Clone for DistanceSsd
impl Clone for DistanceSsd
Source§fn clone(&self) -> DistanceSsd
fn clone(&self) -> DistanceSsd
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 DistanceSsd
impl Debug for DistanceSsd
Source§impl Indicator for DistanceSsd
impl Indicator for DistanceSsd
Source§type Input = (f64, f64)
type Input = (f64, f64)
f64 for a price, or Candle / Tick).Source§fn update(&mut self, input: (f64, f64)) -> Option<f64>
fn update(&mut self, input: (f64, f64)) -> 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 DistanceSsd
impl RefUnwindSafe for DistanceSsd
impl Send for DistanceSsd
impl Sync for DistanceSsd
impl Unpin for DistanceSsd
impl UnsafeUnpin for DistanceSsd
impl UnwindSafe for DistanceSsd
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