Method: TechnicalAnalysis::Indicator.calculate

Defined in:
lib/technical_analysis/indicators/indicator.rb

.calculate(indicator_symbol, data, calculation, options = {}) ⇒ Object

Find the applicable indicator and looks up the value

Parameters:

  • indicator_symbol (String)

    Downcased string of the indicator symbol

  • data (Array)

    Array of hashes of price data to perform calcualtion on

  • calculation (Symbol)

    The calculation to be performed on the requested indicator and params

  • options (Hash) (defaults to: {})

    A hash containing options for the requested calculation

Returns:

  • Returns the requested calculation



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/technical_analysis/indicators/indicator.rb', line 78

def self.calculate(indicator_symbol, data, calculation, options={})
  return nil unless CALCULATIONS.include? calculation

  indicator = find(indicator_symbol)
  raise "Indicator not found!" if indicator.nil?

  case calculation
  when :indicator_name; indicator.indicator_name
  when :indicator_symbol; indicator.indicator_symbol
  when :technicals; indicator.calculate(data, options)
  when :min_data_size; indicator.min_data_size(options)
  when :valid_options; indicator.valid_options
  when :validate_options; indicator.validate_options(options)
  else nil
  end
end