Struct StandardDeviation

Source
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

Source

pub fn new() -> Self

Create a new Standard Deviation calculator with default configuration (period=20, sample=true)

Source

pub fn with_period(period: usize) -> Result<Self, StandardDeviationError>

Create a new Standard Deviation calculator with custom period

Source

pub fn population(period: usize) -> Result<Self, StandardDeviationError>

Create a new Standard Deviation calculator for population standard deviation

Source

pub fn sample(period: usize) -> Result<Self, StandardDeviationError>

Create a new Standard Deviation calculator for sample standard deviation

Source

pub fn with_config(config: StandardDeviationConfig) -> Self

Create a new Standard Deviation calculator with custom configuration

Source

pub fn calculate( &mut self, input: StandardDeviationInput, ) -> Result<StandardDeviationOutput, StandardDeviationError>

Calculate Standard Deviation for the given input

Source

pub fn calculate_batch( &mut self, inputs: &[StandardDeviationInput], ) -> Result<Vec<StandardDeviationOutput>, StandardDeviationError>

Calculate Standard Deviation for a batch of inputs

Source

pub fn reset(&mut self)

Reset the calculator state

Source

pub fn get_state(&self) -> &StandardDeviationState

Get current state (for serialization/debugging)

Source

pub fn set_state(&mut self, state: StandardDeviationState)

Restore state (for deserialization)

Source

pub fn mean(&self) -> f64

Get current mean

Source

pub fn volatility_level(&self) -> VolatilityLevel

Get current volatility level

Source

pub fn is_outlier(&self, value: f64, threshold_std_devs: f64) -> bool

Check if value is outlier (beyond N standard deviations)

Trait Implementations§

Source§

impl Default for StandardDeviation

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.