Class: RubyTechnicalAnalysis::BollingerBands

Inherits:
Indicator
  • Object
show all
Defined in:
lib/ruby_technical_analysis/indicators/bollinger_bands.rb

Overview

Instance Attribute Summary collapse

Attributes inherited from Indicator

#series

Instance Method Summary collapse

Methods inherited from Indicator

call

Constructor Details

#initialize(series: [], period: 20, standard_deviations: 2) ⇒ BollingerBands

Returns a new instance of BollingerBands.

Parameters:

  • series (Array) (defaults to: [])

    An array of prices, typically closing prices

  • period (Integer) (defaults to: 20)

    The number of periods to use in the calculation

  • standard_deviations (Integer) (defaults to: 2)

    The number of standard deviations to use in the calculation



11
12
13
14
15
16
# File 'lib/ruby_technical_analysis/indicators/bollinger_bands.rb', line 11

def initialize(series: [], period: 20, standard_deviations: 2)
  @period = period
  @standard_deviations = standard_deviations

  super(series: series)
end

Instance Attribute Details

#periodObject (readonly)

Returns the value of attribute period.



6
7
8
# File 'lib/ruby_technical_analysis/indicators/bollinger_bands.rb', line 6

def period
  @period
end

#standard_deviationsObject (readonly)

Returns the value of attribute standard_deviations.



6
7
8
# File 'lib/ruby_technical_analysis/indicators/bollinger_bands.rb', line 6

def standard_deviations
  @standard_deviations
end

Instance Method Details

#callArray

Returns An array containing the current upper, middle, and lower bands of the series.

Returns:

  • (Array)

    An array containing the current upper, middle, and lower bands of the series



19
20
21
# File 'lib/ruby_technical_analysis/indicators/bollinger_bands.rb', line 19

def call
  calculate_bollinger_bands
end

#valid?Boolean

Returns Whether or not the object is valid.

Returns:

  • (Boolean)

    Whether or not the object is valid



24
25
26
# File 'lib/ruby_technical_analysis/indicators/bollinger_bands.rb', line 24

def valid?
  period <= series.length && standard_deviations > 0
end