class SignalTools::Technicals::EMA
Constants
- EMA_DEFAULT
Attributes
data[R]
period[R]
type[R]
Public Class Methods
new(data, period, type=:default)
click to toggle source
# File lib/signal_tools/technicals/ema.rb, line 11 def initialize(data, period, type=:default) @data = data @period = period @type = type end
Public Instance Methods
calculate()
click to toggle source
# File lib/signal_tools/technicals/ema.rb, line 17 def calculate ema_points end
Private Instance Methods
calculate_ema(previous, current)
click to toggle source
calculate_wilder_ema(previous, current)
click to toggle source
Uses Wilder’s moving average formula.
# File lib/signal_tools/technicals/ema.rb, line 40 def calculate_wilder_ema(previous, current) (previous * (period - 1) + current) / period end
ema_points()
click to toggle source
TODO: Break Wilder into its own class
# File lib/signal_tools/technicals/ema.rb, line 24 def ema_points emas = [default_simple_average(data, EMA_DEFAULT)] if type == :wilder data.slice(EMA_DEFAULT..-1).each { |current| emas << calculate_wilder_ema(emas.last, current) } else data.slice(EMA_DEFAULT..-1).each { |current| emas << calculate_ema(emas.last, current) } end emas end