quantonex v0.1.2 Quantonex.Indicators View Source
Contains technical indicators.
Link to this section Summary
Functions
Calculates a list of exponential moving averages (EMAs) for a given dataset and period.
Calculates a single exponential moving average (EMA) for a given price, period and another EMA.
Calculates a list of relative strength indexes (RSIs) for a given dataset.
Calculates a simple moving average (SMA) for a given dataset.
Calculates a list of volume weighted average prices (VWAPs) for a given dataset.
Calculates a single volume weighted average price (VWAP).
Link to this section Types
Represents a smoothing method.
:ema
- exponential moving average:sma
- simple moving average
volume_weighted_average_price()
View Sourcevolume_weighted_average_price() :: %{ cumulative_volume: non_neg_integer(), cumulative_volume_price: Decimal.t(), value: Decimal.t() }
Represents a volume weighted average price.
value
- the volume weighted average pricecumulative_volume
- the previous volume plus the current volumecumulative_volume_price
- the previous volume price plus the current volume price
Link to this section Functions
ema(dataset, period)
View Sourceema(dataset :: [price :: String.t() | number(), ...], period :: pos_integer()) :: {:error, reason :: String.t()} | {:ok, [values :: Decimal.t(), ...]}
Calculates a list of exponential moving averages (EMAs) for a given dataset and period.
The first n
elements (n == period
) are used to calculate the initial EMA using a SMA.
Each successive value is calculated using an EMA.
Possible return values are:
{:error, reason}
{:ok, values}
The returned list of EMA values has the same length as the input dataset, so they can be joined again.
Examples
dataset = 1..11 |> Enum.map(fn x -> x end)
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
{:ok, emas} = Quantonex.Indicators.ema(dataset, 10)
{:ok,
[#Decimal<0>, #Decimal<0>, #Decimal<0>, #Decimal<0>, #Decimal<0>, #Decimal<0>,
#Decimal<0>, #Decimal<0>, #Decimal<0>, #Decimal<5.5>,
#Decimal<6.500000000000000000000000000>]}
Enum.zip(dataset, emas)
[
{1, #Decimal<0>},
{2, #Decimal<0>},
{3, #Decimal<0>},
{4, #Decimal<0>},
{5, #Decimal<0>},
{6, #Decimal<0>},
{7, #Decimal<0>},
{8, #Decimal<0>},
{9, #Decimal<0>},
{10, #Decimal<5.5>},
{11, #Decimal<6.500000000000000000000000000>}
]
Calculates a single exponential moving average (EMA) for a given price, period and another EMA.
This is a convenience function to avoid calculation using a complete dataset.
See Quantonex.Indicators.ema/2
for how to calculate an initial EMA.
Possible return values are:
{:error, reason}
{:ok, value}
Examples
previous_ema = Decimal.from_float(5.5)
#Decimal<5.5>
{:ok, value} = Quantonex.Indicators.ema(11, 10, previous_ema)
{:ok, #Decimal<6.500000000000000000000000000>}
rsi(dataset, period)
View Sourcersi( dataset :: [price :: String.t() | number(), ...], period :: non_neg_integer() ) :: {:error, reason :: String.t()} | {:ok, values :: [Decimal.t(), ...]}
Calculates a list of relative strength indexes (RSIs) for a given dataset.
Calculates a simple moving average (SMA) for a given dataset.
The period of the SMA is fixed and equal to the length of the dataset.
Possible return values are:
{:error, reason}
{:ok, value}
Examples
iex> Quantonex.Indicators.sma([1, 2, 3])
{:ok, Decimal.new(2)}
vwap(dataset)
View Sourcevwap(dataset :: [Quantonex.DataPoint.t(), ...]) :: {:error, reason :: String.t()} | {:ok, values :: [volume_weighted_average_price(), ...]}
Calculates a list of volume weighted average prices (VWAPs) for a given dataset.
The following data point properties are used to calculate a VWAP value.
high
low
close
volume
Possible return values are:
{:error, reason}
{:ok, values}
The returned list of VWAP values has the same length as the input dataset, so they can be joined again.
Examples
dataset = [%Quantonex.DataPoint{
close: #Decimal<127.28>,
high: #Decimal<127.36>,
low: #Decimal<126.99>,
volume: 89329
},...]
{:ok, vwaps} = Quantonex.Indicators.vwap(dataset)
{:ok,
[%{
cumulative_volume: 89329,
cumulative_volume_price: #Decimal<11363542.09>,
value: #Decimal<127.21>
}, ...]
}
Enum.zip(dataset, vwaps)
[
...
]
vwap(data_point, cumulative_volume \\ 0, cumulative_volume_price \\ %{__struct__: Decimal, coef: 0, exp: 0, sign: 1})
View Sourcevwap( data_point :: Quantonex.DataPoint.t(), cumulative_volume :: non_neg_integer(), cumulative_volume_price :: Decimal.t() ) :: {:error, reason :: String.t()} | {:ok, value :: volume_weighted_average_price()}
Calculates a single volume weighted average price (VWAP).
The following data point properties are used to calculate a VWAP value.
high
low
close
volume
Possible return values are:
{:error, reason}
{:ok, values}
Examples
data_point = %Quantonex.DataPoint{
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)
Successive calculations can be done by passing previously calculated cumulative values to the function.
next_data_point = %Quantonex.DataPoint{
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)