Class: TechnicalAnalysis::Uo
- Defined in:
- lib/technical_analysis/indicators/uo.rb
Overview
Ultimate Oscillator
Class Method Summary collapse
-
.calculate(data, short_period: 7, medium_period: 14, long_period: 28, short_weight: 4, medium_weight: 2, long_weight: 1) ⇒ Array<UoValue>
Calculates the ultimate oscillator (UO) for the data over the given period en.wikipedia.org/wiki/Ultimate_oscillator.
-
.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: 28, **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: 7, medium_period: 14, long_period: 28, short_weight: 4, medium_weight: 2, long_weight: 1) ⇒ Array<UoValue>
Calculates the ultimate oscillator (UO) for the data over the given period en.wikipedia.org/wiki/Ultimate_oscillator
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 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/technical_analysis/indicators/uo.rb', line 57 def self.calculate(data, short_period: 7, medium_period: 14, long_period: 28, short_weight: 4, medium_weight: 2, long_weight: 1) short_period = short_period.to_i medium_period = medium_period.to_i long_period = long_period.to_i short_weight = short_weight.to_f medium_weight = medium_weight.to_f long_weight = long_weight.to_f Validation.validate_numeric_data(data, :high, :low, :close) 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] } output = [] period_values = [] prior_close = data.shift[:close] sum_of_weights = ArrayHelper.sum([short_weight, medium_weight, long_weight]) data.each do |v| min_low_p_close = [v[:low], prior_close].min max_high_p_close = [v[:high], prior_close].max = v[:close] - min_low_p_close true_range = max_high_p_close - min_low_p_close period_values << { buying_pressure: , true_range: true_range } if period_values.size == long_period short_average = calculate_average(short_period, period_values) medium_average = calculate_average(medium_period, period_values) long_average = calculate_average(long_period, period_values) uo = 100 * (((short_weight * short_average) + (medium_weight * medium_average) + (long_weight * long_average)) / (sum_of_weights)) output << UoValue.new(date_time: v[:date_time], uo: uo) period_values.shift end prior_close = v[:close] 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/uo.rb', line 15 def self.indicator_name "Ultimate Oscillator" end |
.indicator_symbol ⇒ String
Returns the symbol of the technical indicator
8 9 10 |
# File 'lib/technical_analysis/indicators/uo.rb', line 8 def self.indicator_symbol "uo" end |
.min_data_size(long_period: 28, **params) ⇒ Integer
Calculates the minimum number of observations needed to calculate the technical indicator
41 42 43 |
# File 'lib/technical_analysis/indicators/uo.rb', line 41 def self.min_data_size(long_period: 28, **params) long_period.to_i + 1 end |
.valid_options ⇒ Array
Returns an array of valid keys for options for this technical indicator
22 23 24 |
# File 'lib/technical_analysis/indicators/uo.rb', line 22 def self. %i(short_period medium_period long_period short_weight medium_weight long_weight) end |
.validate_options(options) ⇒ Boolean
Validates the provided options for this technical indicator
31 32 33 |
# File 'lib/technical_analysis/indicators/uo.rb', line 31 def self.() Validation.(, ) end |