pub struct RollingMoments<T> { /* private fields */ }Expand description
This module provides functionality for calculating rolling statistical moments over a time series.
Rolling moments are essential statistics that help analyze the characteristics of data over a moving window. These include measures like mean, variance, skewness, and kurtosis, which provide insights into the distribution and behavior of financial time series data.
The implementation uses Kahan-Babuska-Neumaier summation algorithm for numerical stability when computing these statistics over potentially large datasets with floating-point values.
Implementations§
Source§impl<T: Float + Default> RollingMoments<T>
impl<T: Float + Default> RollingMoments<T>
Sourcepub fn recompute(&mut self)
pub fn recompute(&mut self)
Recomputes the rolling statistics, could be called to avoid prolonged compounding of floating rounding errors
§Returns
&mut Self- The rolling moments object
Sourcepub const fn popped(&self) -> Option<T>
pub const fn popped(&self) -> Option<T>
Returns the value that was removed from the window
§Returns
Option<T>- The value that was removed from the window
Sourcepub const fn value(&self) -> Option<T>
pub const fn value(&self) -> Option<T>
Returns the value that was added to the window
§Returns
Option<T>- The value that was added to the window
Sourcepub fn iter(&self) -> impl Iterator<Item = &T>
pub fn iter(&self) -> impl Iterator<Item = &T>
Returns an iterator over the elements in the ring buffer
Sourcepub fn sum(&self) -> Option<T>
pub fn sum(&self) -> Option<T>
Returns the sum of all values in the rolling window
§Returns
Option<T>- The sum of all values if the window is ready, None otherwise
Sourcepub fn sum_sq(&self) -> Option<T>
pub fn sum_sq(&self) -> Option<T>
Returns the sum of squares of all values in the rolling window
§Returns
Option<T>- The sum of squares of all values if the window is ready, None otherwise
Sourcepub fn mean(&self) -> Option<T>
pub fn mean(&self) -> Option<T>
Returns the mean of all values in the rolling window
§Returns
Option<T>- The mean of all values if the window is ready, None otherwise
Sourcepub fn mean_sq(&self) -> Option<T>
pub fn mean_sq(&self) -> Option<T>
Returns the mean of squared values in the rolling window
§Returns
Option<T>- The mean of squared values if the window is ready, None otherwise
Sourcepub fn variance(&self) -> Option<T>
pub fn variance(&self) -> Option<T>
Returns the variance of values in the rolling window
Variance quantifies the dispersion of data points around the mean, providing essential volatility measurement for financial time series:
- Serves as the foundation for volatility-based position sizing
- Enables normalization of returns for cross-asset comparison
- Provides critical input for statistical arbitrage models
- Forms the basis for numerous technical indicators like Bollinger Bands
§Returns
Option<T>- The variance, orNoneif the window is not full
Sourcepub fn stddev(&self) -> Option<T>
pub fn stddev(&self) -> Option<T>
Returns the standard deviation of values in the rolling window
Standard deviation quantifies the dispersion of data points around the mean, providing essential volatility measurement for financial time series:
- Serves as the foundation for volatility-based position sizing
- Enables normalization of returns for cross-asset comparison
- Provides critical input for statistical arbitrage models
- Forms the basis for numerous technical indicators like Bollinger Bands
§Returns
Option<T>- The standard deviation, orNoneif the window is not full
Sourcepub fn zscore(&self) -> Option<T>
pub fn zscore(&self) -> Option<T>
Returns the Zscore of the most recent value
Zscore measures the number of standard deviations a value is from the mean.
§Returns
Option<T>- The Zscore if the window is ready and standard deviation is positive, None otherwise
Sourcepub fn skew(&self) -> Option<T>
pub fn skew(&self) -> Option<T>
Returns the skewness of values in the rolling window
Skewness measures the asymmetry of the distribution of values.
- Positive values indicate a right-skewed distribution (long tail on the right)
- Negative values indicate a left-skewed distribution (long tail on the left)
- A normal distribution has a skewness of 0
When ddof is true, applies a bias correction for sample skewness.
§Returns
Option<T>- The skewness if the window is ready and variance is positive, None otherwise
Sourcepub fn kurt(&self) -> Option<T>
pub fn kurt(&self) -> Option<T>
Returns the excess kurtosis of values in the rolling window
Excess kurtosis measures the “tailedness” of a distribution compared to a normal distribution.
- Positive values indicate a distribution with heavier tails (more outliers)
- Negative values indicate a distribution with lighter tails (fewer outliers)
- A normal distribution has an excess kurtosis of 0
When ddof is true, applies a bias correction for sample kurtosis.
§Returns
Option<T>- The excess kurtosis if the window is ready and variance is positive, None otherwise
Trait Implementations§
Source§impl<T: Clone> Clone for RollingMoments<T>
impl<T: Clone> Clone for RollingMoments<T>
Source§fn clone(&self) -> RollingMoments<T>
fn clone(&self) -> RollingMoments<T>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more