pub struct StandardDeviation { /* private fields */ }Expand description
Standard Deviation Indicator
Standard deviation measures the amount of variation or dispersion in a set of values. It’s a fundamental statistical measure used in many other technical indicators.
Formulas:
- Population Standard Deviation: σ = √(Σ(x - μ)² / N)
- Sample Standard Deviation: s = √(Σ(x - μ)² / (N-1))
Where:
- x = individual values
- μ = mean of the values
- N = number of values
Uses:
- Measuring price volatility
- Bollinger Bands calculation
- Risk assessment
- Normalization of other indicators
- Z-score calculations
Implementations§
Source§impl StandardDeviation
impl StandardDeviation
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new Standard Deviation calculator with default configuration (period=20, sample=true)
Sourcepub fn with_period(period: usize) -> Result<Self, StandardDeviationError>
pub fn with_period(period: usize) -> Result<Self, StandardDeviationError>
Create a new Standard Deviation calculator with custom period
Sourcepub fn population(period: usize) -> Result<Self, StandardDeviationError>
pub fn population(period: usize) -> Result<Self, StandardDeviationError>
Create a new Standard Deviation calculator for population standard deviation
Sourcepub fn sample(period: usize) -> Result<Self, StandardDeviationError>
pub fn sample(period: usize) -> Result<Self, StandardDeviationError>
Create a new Standard Deviation calculator for sample standard deviation
Sourcepub fn with_config(config: StandardDeviationConfig) -> Self
pub fn with_config(config: StandardDeviationConfig) -> Self
Create a new Standard Deviation calculator with custom configuration
Sourcepub fn calculate(
&mut self,
input: StandardDeviationInput,
) -> Result<StandardDeviationOutput, StandardDeviationError>
pub fn calculate( &mut self, input: StandardDeviationInput, ) -> Result<StandardDeviationOutput, StandardDeviationError>
Calculate Standard Deviation for the given input
Sourcepub fn calculate_batch(
&mut self,
inputs: &[StandardDeviationInput],
) -> Result<Vec<StandardDeviationOutput>, StandardDeviationError>
pub fn calculate_batch( &mut self, inputs: &[StandardDeviationInput], ) -> Result<Vec<StandardDeviationOutput>, StandardDeviationError>
Calculate Standard Deviation for a batch of inputs
Sourcepub fn get_state(&self) -> &StandardDeviationState
pub fn get_state(&self) -> &StandardDeviationState
Get current state (for serialization/debugging)
Sourcepub fn set_state(&mut self, state: StandardDeviationState)
pub fn set_state(&mut self, state: StandardDeviationState)
Restore state (for deserialization)
Sourcepub fn volatility_level(&self) -> VolatilityLevel
pub fn volatility_level(&self) -> VolatilityLevel
Get current volatility level
Sourcepub fn is_outlier(&self, value: f64, threshold_std_devs: f64) -> bool
pub fn is_outlier(&self, value: f64, threshold_std_devs: f64) -> bool
Check if value is outlier (beyond N standard deviations)