Module: Quant::Mixins::WeightedMovingAverage
- Included in:
- MovingAverages
- Defined in:
- lib/quant/mixins/weighted_moving_average.rb
Instance Method Summary collapse
-
#extended_weighted_moving_average(source) ⇒ Float
(also: #ewma)
Computes the Weighted Moving Average (WMA) of the series, using the seven most recent data points.
-
#weighted_moving_average(source) ⇒ Float
(also: #wma)
Computes the Weighted Moving Average (WMA) of the series, using the four most recent data points.
Instance Method Details
#extended_weighted_moving_average(source) ⇒ Float Also known as: ewma
Computes the Weighted Moving Average (WMA) of the series, using the seven most recent data points.
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/quant/mixins/weighted_moving_average.rb', line 31 def extended_weighted_moving_average(source) raise ArgumentError, "source must be a Symbol" unless source.is_a?(Symbol) [7.0 * p0.send(source), 6.0 * p1.send(source), 5.0 * p2.send(source), 4.0 * p3.send(source), 3.0 * p(4).send(source), 2.0 * p(5).send(source), p(6).send(source)].sum / 28.0 end |
#weighted_moving_average(source) ⇒ Float Also known as: wma
Computes the Weighted Moving Average (WMA) of the series, using the four most recent data points.
14 15 16 17 18 19 20 21 |
# File 'lib/quant/mixins/weighted_moving_average.rb', line 14 def weighted_moving_average(source) raise ArgumentError, "source must be a Symbol" unless source.is_a?(Symbol) [4.0 * p0.send(source), 3.0 * p1.send(source), 2.0 * p2.send(source), p3.send(source)].sum / 10.0 end |