Rolling population standard deviation.
See TAlib for the input conventions: prices are always given in
chronological order, oldest first, and the series is returned aligned
with the input. nil is returned when there is not enough data.
Summary
Functions
Warm up streaming standard-deviation state from history.
Advance streaming standard-deviation state by one price, in O(1).
Calculate the population standard deviation of the period newest
prices (two-pass formula, dividing by period).
Calculate the full rolling standard deviation series in a single pass (sliding window sum and sum of squares).
Functions
@spec init([number()], pos_integer()) :: {TAlib.Indicators.StdDev.State.t(), [float() | nil]}
Warm up streaming standard-deviation state from history.
Returns {state, values} with values the full series of history
(identical to std_dev_list/2), and state ready to continue it one
price at a time in O(1) via next/2. History needs at least period
prices.
Examples
iex> {state, values} = TAlib.Indicators.StdDev.init([2, 4, 6, 8], 2)
iex> values
[nil, 1.0, 1.0, 1.0]
iex> {_state, 1.0} = TAlib.Indicators.StdDev.next(state, 10)
@spec next(TAlib.Indicators.StdDev.State.t(), number()) :: {TAlib.Indicators.StdDev.State.t(), float() | nil}
Advance streaming standard-deviation state by one price, in O(1).
iex> {state, _} = TAlib.Indicators.StdDev.init([2, 4, 6, 8], 2)
iex> {_state, value} = TAlib.Indicators.StdDev.next(state, 10)
iex> value
1.0
@spec std_dev([number()], pos_integer()) :: float() | nil
Calculate the population standard deviation of the period newest
prices (two-pass formula, dividing by period).
Parameters
- prices: list of prices, oldest first.
- period: lookback window, a positive integer.
Examples
iex> TAlib.Indicators.StdDev.std_dev([1, 2, 3, 4], 4) |> Float.round(6)
1.118034
iex> TAlib.Indicators.StdDev.std_dev([2, 4, 6, 8], 2)
1.0
@spec std_dev_list([number()], pos_integer()) :: [float() | nil]
Calculate the full rolling standard deviation series in a single pass (sliding window sum and sum of squares).
Returns a list aligned with prices: the first period - 1 entries are
nil, and every later entry is the population standard deviation of the
window ending at that point.
Parameters
- prices: list of prices, oldest first.
- period: lookback window, a positive integer.
Examples
iex> TAlib.Indicators.StdDev.std_dev_list([2, 4, 6, 8], 2)
[nil, 1.0, 1.0, 1.0]