pub struct HurstExponent { /* private fields */ }Expand description
Hurst Exponent of the last period values, estimated by rescaled-range
(R/S) analysis.
The classic Hurst-Mandelbrot estimator forms log-log pairs of (n, R(n)/S(n)) for several window lengths n and reports the slope of the
least-squares fit. Wickra uses a streaming-friendly variant that
partitions the trailing window into chunks of equal size,
computes (R/S) for each chunk length, and fits a log-log line to the
resulting points:
for each chunk size m ∈ {n/2, n/3, …, n/chunks}:
mean_m = (1/m) · Σ x_i over the chunk
dev_m_i = (Σ_{j ≤ i} (x_j − mean_m)) // cumulative deviation
R_m = max(dev_m) − min(dev_m)
S_m = population_stddev(chunk)
pair = (log m, log(R_m / S_m))
H = slope of OLS line through the (log m, log(R/S)) pointsThe interpretation is unchanged from the textbook:
H ≈ 0.5→ random walk; recent moves carry no information about future direction (the efficient-markets baseline).H > 0.5→ persistent / trending; up moves are likelier to be followed by more up moves.H < 0.5→ anti-persistent / mean-reverting; up moves tend to reverse.
Use it as a regime filter: trend-following strategies prefer
H > 0.55; mean-reversion prefers H < 0.45. The output is clamped
to [0, 1] to absorb degenerate fits on very small windows.
period must be at least 2 · chunks so every chunk has at least two
points (otherwise its stddev is zero). A perfectly flat window has all
R/S = 0 and the indicator returns 0.5 (random-walk baseline) to
avoid divide-by-zero / log-zero failures.
Each update is O(period); the window is stored in a deque and the
chunked R/S computation runs once per emission, not per input.
§Example
use wickra_core::{HurstExponent, Indicator};
let mut indicator = HurstExponent::new(100, 4).unwrap();
let mut last = None;
for i in 0..200 {
last = indicator.update(f64::from(i));
}
assert!(last.is_some());Implementations§
Source§impl HurstExponent
impl HurstExponent
Sourcepub fn new(period: usize, chunks: usize) -> Result<Self>
pub fn new(period: usize, chunks: usize) -> Result<Self>
Construct a new Hurst Exponent over a window of period inputs,
fitted across chunks log-log points.
chunks controls the number of R/S pairs that go into the slope
fit; the typical value is 4 (the original Hurst paper used 5 — 9
points; smaller windows constrain the choice).
§Errors
Returns Error::InvalidPeriod if chunks < 2 or
period < 2 · chunks.
Trait Implementations§
Source§impl Clone for HurstExponent
impl Clone for HurstExponent
Source§impl Debug for HurstExponent
impl Debug for HurstExponent
Source§impl Indicator for HurstExponent
impl Indicator for HurstExponent
Source§fn update(&mut self, value: f64) -> Option<f64>
fn update(&mut self, value: f64) -> Option<f64>
None if there is no value for this input. Read moreSource§fn reset(&mut self)
fn reset(&mut self)
Source§fn warmup_period(&self) -> usize
fn warmup_period(&self) -> usize
None output can be produced.Source§fn is_ready(&self) -> bool
fn is_ready(&self) -> bool
Source§fn name(&self) -> &'static str
fn name(&self) -> &'static str
Source§fn batch_nan_into(&mut self, inputs: &[Self::Input], out: &mut [f64])
fn batch_nan_into(&mut self, inputs: &[Self::Input], out: &mut [f64])
Source§fn batch_fast_into(&mut self, inputs: &[Self::Input], out: &mut [f64])
fn batch_fast_into(&mut self, inputs: &[Self::Input], out: &mut [f64])
batch_nan_into, but
an indicator with a vectorised kernel may reassociate its arithmetic to
run it in SIMD lanes. Each value then agrees with the exact batch to within
the tolerance the indicator documents (a few units in the last place), not
bit for bit; warmup positions, NaN placement and the output length are
identical. The kernels are deterministic: the same input produces the same
bits on every platform, with or without SIMD hardware. Read moreAuto Trait Implementations§
impl Freeze for HurstExponent
impl RefUnwindSafe for HurstExponent
impl Send for HurstExponent
impl Sync for HurstExponent
impl Unpin for HurstExponent
impl UnsafeUnpin for HurstExponent
impl UnwindSafe for HurstExponent
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> BatchNanExt for T
impl<T> BatchNanExt for T
Source§fn batch_nan(&mut self, inputs: &[f64]) -> Vec<f64>
fn batch_nan(&mut self, inputs: &[f64]) -> Vec<f64>
f64 per input, warmup positions filled with NaN, bit-for-bit equal
to replaying update.Source§fn batch_fast(&mut self, inputs: &[f64]) -> Vec<f64>
fn batch_fast(&mut self, inputs: &[f64]) -> Vec<f64>
Indicator::batch_fast_into) into a fresh
vector: within the indicator’s documented tolerance of
batch_nan, deterministic across platforms.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