quantonex v0.1.0 Quantonex.Indicators View Source
Contains technical indicators.
Link to this section Summary
Functions
Calculates an exponential moving average for a given price and period.
Calculates an exponential moving average for a given price, period and previous exponential moving average.
Calculates a simple moving average for a period that is equal to the length of the dataset.
Calculates a simple moving average for a given dataset and period.
Calculates a volume weighted average price.
Link to this section Types
vwap()
View Sourcevwap() :: %{ cumulative_volume: non_neg_integer(), cumulative_volume_price: Decimal.t(), value: Decimal.t() }
Represents a volume weighted average price.
value
- the volume weighted average price.cumulative_volume
- the previous volume plus the current volume.cumulative_volume_price
- the previous volume price plus the current volume price.
Link to this section Functions
ema(price, period)
View Sourceema(price :: Decimal.t(), period :: pos_integer()) :: {:error, reason :: String.t()} | {:ok, value :: Decimal.t()}
Calculates an exponential moving average for a given price and period.
A simple moving average is calculated based on the price and then used as seed for the calculation of the exponential moving average.
Examples
{:ok, ema_value} = Decimal.from_float(22.81) |> Quantonex.Indicators.ema(9)
{:ok, #Decimal<22.810>}
ema(price, period, previous_ema)
View Sourceema(price :: Decimal.t(), period :: pos_integer(), previous_ema :: Decimal.t()) :: {:error, reason :: String.t()} | {:ok, value :: Decimal.t()}
Calculates an exponential moving average for a given price, period and previous exponential moving average.
Examples
previous_ema = Decimal.from_float(22.91)
{:ok, current_ema} = Decimal.from_float(22.81) |> Quantonex.Indicators.ema(9, previous_ema)
{:ok, #Decimal<22.890>}
Calculates a simple moving average for a period that is equal to the length of the dataset.
Examples
iex> Quantonex.Indicators.sma([1, 2, 3])
{:ok, Decimal.new(2)}
sma(dataset, period)
View Sourcesma(dataset :: [number(), ...], period :: pos_integer()) :: {:error, reason :: String.t()} | {:ok, value :: Decimal.t()}
Calculates a simple moving average for a given dataset and period.
The last n elements of the dataset are used for the calculation.
Examples
iex> Quantonex.Indicators.sma([1, 2, 3], 2)
{:ok, Decimal.from_float(2.5)}
iex> Quantonex.Indicators.sma([1, 2, 3], 4)
{:error, "Period can't be greater than the length of the dataset."}
vwap(data_point, cumulative_volume \\ 0, cumulative_volume_price \\ Decimal.new(0))
View Sourcevwap( data_point :: Quantonex.DataPoint.t(), cumulative_volume :: non_neg_integer(), cumulative_volume_price :: Decimal.t() ) :: {:error, reason :: String.t()} | {:ok, value :: vwap()}
Calculates a volume weighted average price.
To calculate the initial vwap value, both cumulative_volume
and cumulative_volume_price
are set to 0
.
data_point = %Quantonex.DataPoint{
complete: true,
close: Decimal.new(6),
high: Decimal.new(8),
low: Decimal.new(4),
volume: 10
}
{:ok,
%{
"cumulative_volume": cumulative_volume,
"cumulative_volume_price": cumulative_volume_price,
"value": value
}
} = Quantonex.Indicators.vwap(data_point)
Any subsequent calculation can be done by passing the previously calculated cumulative values to the function.
next_data_point = %Quantonex.DataPoint{
complete: false,
close: Decimal.new(8),
high: Decimal.new(10),
low: Decimal.new(6),
volume: 20
}
Quantonex.Indicators.vwap(next_data_point, cumulative_volume, cumulative_volume_price)