Module: Quant::Mixins::ExponentialMovingAverage
- Included in:
- MovingAverages
- Defined in:
- lib/quant/mixins/exponential_moving_average.rb
Instance Method Summary collapse
-
#exponential_moving_average(source, period:, previous: :ema) ⇒ Float
(also: #ema)
Computes the Exponential Moving Average (EMA) of the given period.
Instance Method Details
#exponential_moving_average(source, period:, previous: :ema) ⇒ Float Also known as: ema
Computes the Exponential Moving Average (EMA) of the given period.
The EMA computation is optimized to compute using just the last two indicator data points and is expected to be called in each indicator’s ‘#compute` method for each iteration on the series.
25 26 27 28 29 30 31 |
# File 'lib/quant/mixins/exponential_moving_average.rb', line 25 def exponential_moving_average(source, period:, previous: :ema) raise ArgumentError, "source must be a Symbol" unless source.is_a?(Symbol) raise ArgumentError, "previous must be a Symbol" unless previous.is_a?(Symbol) alpha = (period) (p0.send(source) * alpha) + (p1.send(previous) * (1.0 - alpha)) end |