Module: Quant::Mixins::SimpleMovingAverage
- Included in:
- MovingAverages
- Defined in:
- lib/quant/mixins/simple_moving_average.rb
Instance Method Summary collapse
-
#simple_moving_average(source, period:) ⇒ Float
(also: #sma)
Computes the Simple Moving Average (SMA) of the given period.
Instance Method Details
#simple_moving_average(source, period:) ⇒ Float Also known as: sma
Computes the Simple Moving Average (SMA) of the given period.
13 14 15 16 17 |
# File 'lib/quant/mixins/simple_moving_average.rb', line 13 def simple_moving_average(source, period:) raise ArgumentError, "source must be a Symbol" unless source.is_a?(Symbol) values.last(period).map { |value| value.send(source) }.mean end |