Class: TechnicalAnalysis::Ichimoku
- Defined in:
- lib/technical_analysis/indicators/ichimoku.rb
Overview
Ichimoku Kinko Hyo
Class Method Summary collapse
-
.calculate(data, low_period: 9, medium_period: 26, high_period: 52) ⇒ Array<IchimokuValue>
Calculates the 5 points of Ichimoku Kinko Hyo (Ichimoku) for the data over the given period 1.
-
.indicator_name ⇒ String
Returns the name of the technical indicator.
-
.indicator_symbol ⇒ String
Returns the symbol of the technical indicator.
-
.min_data_size(medium_period: 26, high_period: 52, **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, low_period: 9, medium_period: 26, high_period: 52) ⇒ Array<IchimokuValue>
Calculates the 5 points of Ichimoku Kinko Hyo (Ichimoku) for the data over the given period
- tenkan_sen (Conversion Line)
- kijun_sen (Base Line)
- senkou_span_a (Leading Span A)
- senkou_span_b (Leading Span B)
- chickou_span (Lagging Span) https://en.wikipedia.org/wiki/Ichimoku_Kink%C5%8D_Hy%C5%8D
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 |
# File 'lib/technical_analysis/indicators/ichimoku.rb', line 59 def self.calculate(data, low_period: 9, medium_period: 26, high_period: 52) low_period = low_period.to_i medium_period = medium_period.to_i high_period = high_period.to_i Validation.validate_numeric_data(data, :high, :low, :close) Validation.validate_length(data, min_data_size(high_period: high_period, medium_period: medium_period)) Validation.validate_date_time_key(data) data = data.sort_by { |row| row[:date_time] } index = high_period + medium_period - 2 output = [] while index < data.size date_time = data[index][:date_time] tenkan_sen = calculate_midpoint(index, low_period, data) kinjun_sen = calculate_midpoint(index, medium_period, data) senkou_span_a = calculate_senkou_span_a(index, low_period, medium_period, data) senkou_span_b = calculate_senkou_span_b(index, medium_period, high_period, data) chikou_span = calculate_chikou_span(index, medium_period, data) output << IchimokuValue.new( date_time: date_time, tenkan_sen: tenkan_sen, kijun_sen: kinjun_sen, senkou_span_a: senkou_span_a, senkou_span_b: senkou_span_b, chikou_span: chikou_span ) index += 1 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/ichimoku.rb', line 15 def self.indicator_name "Ichimoku Kinko Hyo" end |
.indicator_symbol ⇒ String
Returns the symbol of the technical indicator
8 9 10 |
# File 'lib/technical_analysis/indicators/ichimoku.rb', line 8 def self.indicator_symbol "ichimoku" end |
.min_data_size(medium_period: 26, high_period: 52, **params) ⇒ Integer
Calculates the minimum number of observations needed to calculate the technical indicator
41 42 43 |
# File 'lib/technical_analysis/indicators/ichimoku.rb', line 41 def self.min_data_size(medium_period: 26, high_period: 52, **params) high_period.to_i + medium_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/ichimoku.rb', line 22 def self. %i(low_period medium_period high_period) end |
.validate_options(options) ⇒ Boolean
Validates the provided options for this technical indicator
31 32 33 |
# File 'lib/technical_analysis/indicators/ichimoku.rb', line 31 def self.() Validation.(, ) end |