Indicado.SMA (Indicado v0.0.4) View Source
This is the SMA module used for calculating Simple Moving Average.
Link to this section Summary
Functions
Calculates SMA for the list.
Calculates SMA for the list. Raises exceptions when arguments does not satisfy needed conditions to calculate SMA.
Link to this section Functions
Specs
eval([list(), ...], pos_integer()) :: {:ok, [float(), ...]} | {:error, atom()}
Calculates SMA for the list.
Returns {:ok, sma_list}
or {:error, reason}
Examples
iex> Indicado.SMA.eval([1, 3, 5, 7], 2)
{:ok, [2.0, 4.0, 6.0]}
iex> Indicado.SMA.eval([1, 3], 3)
{:error, :not_enough_data}
iex> Indicado.SMA.eval([1, 3, 4], 0)
{:error, :bad_period}
Specs
eval!([list(), ...], pos_integer()) :: [float(), ...] | no_return()
Calculates SMA for the list. Raises exceptions when arguments does not satisfy needed conditions to calculate SMA.
Raises NotEnoughDataError
if the given list is not longh enough for calculating SMA.
Raises BadPeriodError
if period is an unacceptable number.
Examples
iex> Indicado.SMA.eval!([1, 3, 5, 7], 2)
[2.0, 4.0, 6.0]
iex> Indicado.SMA.eval!([1, 3], 3)
** (NotEnoughDataError) not enough data
iex> Indicado.SMA.eval!([1, 3, 4], 0)
** (BadPeriodError) bad period