Class: TechnicalAnalysis::Ao
- Defined in:
- lib/technical_analysis/indicators/ao.rb
Overview
Awesome Oscillator
Class Method Summary collapse
-
.calculate(data, short_period: 5, long_period: 34) ⇒ Array<AoValue>
Calculates the awesome oscillator for the data over the given period www.tradingview.com/wiki/Awesome_Oscillator_(AO).
-
.indicator_name ⇒ String
Returns the name of the technical indicator.
-
.indicator_symbol ⇒ String
Returns the symbol of the technical indicator.
-
.min_data_size(long_period: 34, **params) ⇒ Integer
Calculates the minimum number of observations needed to calculate the technical indicator.
-
.valid_options ⇒ Array
Returns an array of valid keys for options for this technical indicator.
-
.validate_options(options) ⇒ Boolean
Validates the provided options for this technical indicator.
Methods inherited from Indicator
Class Method Details
.calculate(data, short_period: 5, long_period: 34) ⇒ Array<AoValue>
Calculates the awesome oscillator for the data over the given period www.tradingview.com/wiki/Awesome_Oscillator_(AO)
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/technical_analysis/indicators/ao.rb', line 53 def self.calculate(data, short_period: 5, long_period: 34) short_period = short_period.to_i long_period = long_period.to_i Validation.validate_numeric_data(data, :high, :low) Validation.validate_length(data, min_data_size(long_period: long_period)) Validation.validate_date_time_key(data) data = data.sort_by { |row| row[:date_time] } midpoint_values = [] output = [] data.each do |v| midpoint = (v[:high] + v[:low]) / 2 midpoint_values << midpoint if midpoint_values.size == long_period short_period_sma = ArrayHelper.average(midpoint_values.last(short_period)) long_period_sma = ArrayHelper.average(midpoint_values) value = short_period_sma - long_period_sma output << AoValue.new(date_time: v[:date_time], ao: value) midpoint_values.shift end end output.sort_by(&:date_time).reverse end |
.indicator_name ⇒ String
Returns the name of the technical indicator
15 16 17 |
# File 'lib/technical_analysis/indicators/ao.rb', line 15 def self.indicator_name "Awesome Oscillator" end |
.indicator_symbol ⇒ String
Returns the symbol of the technical indicator
8 9 10 |
# File 'lib/technical_analysis/indicators/ao.rb', line 8 def self.indicator_symbol "ao" end |
.min_data_size(long_period: 34, **params) ⇒ Integer
Calculates the minimum number of observations needed to calculate the technical indicator
41 42 43 |
# File 'lib/technical_analysis/indicators/ao.rb', line 41 def self.min_data_size(long_period: 34, **params) long_period.to_i end |
.valid_options ⇒ Array
Returns an array of valid keys for options for this technical indicator
22 23 24 |
# File 'lib/technical_analysis/indicators/ao.rb', line 22 def self. %i(short_period long_period) end |
.validate_options(options) ⇒ Boolean
Validates the provided options for this technical indicator
31 32 33 |
# File 'lib/technical_analysis/indicators/ao.rb', line 31 def self.() Validation.(, ) end |