Indicado.Bollinger (Indicado v0.0.4) View Source

This is the Bollinger module used for calculating Bollinger Bands.

Link to this section Summary

Functions

Calculates BB for the list.

Calculates BB for the list. Raises exceptions when argument does not satisfy needed conditions to calculate Bollinger Bands.

Link to this section Functions

Link to this function

eval(list, period, devation)

View Source

Specs

eval(list(), pos_integer(), pos_integer()) ::
  {:ok, [map(), ...]} | {:error, atom()}

Calculates BB for the list.

Returns list of map [{lower: x, mean: y, upper: z}] or {:error, reason}

  • lower represents low band of bollinger band
  • mean represents mean value
  • upper represents upper value of bollinger band

Examples

iex> Indicado.Bollinger.eval([1, 2, 3, 4, 5], 2, 2)
{:ok, [%{lower: 0.5, mean: 1.5, upper: 2.5},
        %{lower: 1.5, mean: 2.5, upper: 3.5},
        %{lower: 2.5, mean: 3.5, upper: 4.5},
        %{lower: 3.5, mean: 4.5, upper: 5.5}]}

iex> Indicado.Bollinger.eval([1, 2, 3, 4, 5], 2, 3)
{:ok, [%{lower: 0.0, mean: 1.5, upper: 3.0},
        %{lower: 1.0, mean: 2.5, upper: 4.0},
        %{lower: 2.0, mean: 3.5, upper: 5.0},
        %{lower: 3.0, mean: 4.5, upper: 6.0}]}

iex> Indicado.Bollinger.eval([1, 2, 3, 4, 5], 0, 3)
{:error, :bad_period}

iex> Indicado.Bollinger.eval([1, 2, 3, 4, 5], 5, 0)
{:error, :bad_deviation}
Link to this function

eval!(list, period, deviation)

View Source

Specs

eval!(list(), pos_integer(), pos_integer()) :: [map(), ...] | no_return()

Calculates BB for the list. Raises exceptions when argument does not satisfy needed conditions to calculate Bollinger Bands.

Returns list of map [{lower: x, mean: y, upper: z}] or {:error, reason}

  • lower represents low band of bollinger band
  • mean represents mean value
  • upper represents upper value of bollinger band

Raises NotEnoughDataError if the given list is not longh enough for calculating SMA. Raises BadPeriodError if period is an unacceptable number. Raises BadDeviationError if deviation is an unacceptable number.

Examples

iex> Indicado.Bollinger.eval!([1, 2, 3, 4, 5], 2, 2)
[%{lower: 0.5, mean: 1.5, upper: 2.5},
  %{lower: 1.5, mean: 2.5, upper: 3.5},
  %{lower: 2.5, mean: 3.5, upper: 4.5},
  %{lower: 3.5, mean: 4.5, upper: 5.5}]

iex> Indicado.Bollinger.eval!([1, 2, 3, 4, 5], 2, 3)
[%{lower: 0.0, mean: 1.5, upper: 3.0},
  %{lower: 1.0, mean: 2.5, upper: 4.0},
  %{lower: 2.0, mean: 3.5, upper: 5.0},
  %{lower: 3.0, mean: 4.5, upper: 6.0}]

iex> Indicado.Bollinger.eval!([], 2, 3)
** (NotEnoughDataError) not enough data

iex> Indicado.Bollinger.eval!([1, 2, 3, 4, 5], 0, 3)
** (BadPeriodError) bad period

iex> Indicado.Bollinger.eval!([1, 2, 3, 4, 5], 5, 0)
** (BadDeviationError) bad deviation