Module: VolumeRateOfChange
- Included in:
- Array
- Defined in:
- lib/ruby-technical-analysis/indicators/volume_rate_of_change.rb
Overview
Volume Rate of Change indicator Returns a single value
Instance Method Summary collapse
Instance Method Details
#volume_rate_of_change(period) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/ruby-technical-analysis/indicators/volume_rate_of_change.rb', line 6 def volume_rate_of_change(period) if size < (period + 1) raise ArgumentError, "Volumes array passed to Volume Rate of Change cannot be less than period parameter + 1." end delta_volume = [] vol_shifted = [] (0..(length - period - 1)).each do vol_shifted << at(length - period - 1) delta_volume << at(-1) - vol_shifted[-1] end ((delta_volume[-1].to_f / vol_shifted[-1]) * 100).round(4) end |