pub struct JumpIndicator { /* private fields */ }Expand description
Jump Indicator — a discrete {−1, 0, +1} flag for whether the current log
return is an outlier relative to the trailing volatility of returns.
rₜ = ln(priceₜ / priceₜ₋₁)
μ, σ = sample mean and stddev of the `period` returns *before* rₜ (trailing)
flag = +1 if rₜ − μ > threshold · σ
−1 if rₜ − μ < −threshold · σ
0 otherwiseThe baseline is the trailing return distribution and excludes the current
return, so a genuine jump cannot inflate the band it is tested against.
Measuring the deviation from the trailing mean μ (not the raw return) means
a steady drift is not flagged — only moves that are large relative to the
recent return distribution count. +1 marks an up jump, −1 a down jump,
and 0 an ordinary move. When the trailing window has zero dispersion
(σ = 0, e.g. a perfectly constant drift) there is no defined baseline and
the indicator returns 0 rather than flagging every move.
This is the generic, threshold-tunable detector; downstream models keep any
regime-specific sensitivity by choosing threshold. Non-finite and
non-positive prices are ignored (the log return is undefined): the tick is
dropped and the last value returned.
§Example
use wickra_core::{Indicator, JumpIndicator};
let mut indicator = JumpIndicator::new(20, 3.0).unwrap();
let mut last = None;
for i in 0..40 {
last = indicator.update(100.0 + (f64::from(i) * 0.5).sin());
}
// A calm sinusoid produces no jumps.
assert_eq!(last, Some(0.0));Implementations§
Source§impl JumpIndicator
impl JumpIndicator
Sourcepub fn new(period: usize, threshold: f64) -> Result<Self>
pub fn new(period: usize, threshold: f64) -> Result<Self>
Construct a new Jump Indicator.
threshold is the number of trailing standard deviations a return must
exceed to be flagged.
§Errors
Returns Error::InvalidPeriod if period < 2 (the sample standard
deviation needs at least two returns), or Error::InvalidParameter if
threshold is not finite and positive.
Trait Implementations§
Source§impl Clone for JumpIndicator
impl Clone for JumpIndicator
Source§fn clone(&self) -> JumpIndicator
fn clone(&self) -> JumpIndicator
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 JumpIndicator
impl Debug for JumpIndicator
Source§impl Indicator for JumpIndicator
impl Indicator for JumpIndicator
Source§fn update(&mut self, input: f64) -> Option<f64>
fn update(&mut self, input: 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 JumpIndicator
impl RefUnwindSafe for JumpIndicator
impl Send for JumpIndicator
impl Sync for JumpIndicator
impl Unpin for JumpIndicator
impl UnsafeUnpin for JumpIndicator
impl UnwindSafe for JumpIndicator
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