Sha256: e2c50f25e17893b16dfbaacb8686dddcc31f418b9e638bc8ff39fde6c3ebc119
Contents?: true
Size: 886 Bytes
Versions: 20
Compression:
Stored size: 886 Bytes
Contents
# lib/sqa/indicator/bollinger_bands.rb class SQA::Indicator; class << self def bollinger_bands( prices, # Array of prices period, # Integer number of entries to consider num_std_devs=2 # Integer number of standard deviations ) moving_averages = simple_moving_average(prices, period) standard_deviations = [] prices.each_cons(period) do |window| standard_deviation = Math.sqrt(window.map { |price| (price - moving_averages.last) ** 2 }.sum / period) standard_deviations << standard_deviation end upper_band = moving_averages.last + (num_std_devs * standard_deviations.last) lower_band = moving_averages.last - (num_std_devs * standard_deviations.last) { upper_band: upper_band, # Array lower_band: lower_band # Array } end alias_method :bb, :bollinger_bands end; end
Version data entries
20 entries across 20 versions & 1 rubygems