@@ -20,7 +20,7 @@ def self.indicator_name
2020 #
2121 # @return [Array] An array of keys as symbols for valid options for this technical indicator
2222 def self . valid_options
23- %i( period price_key )
23+ %i( period price_key date_time_key )
2424 end
2525
2626 # Validates the provided options for this technical indicator
@@ -48,16 +48,17 @@ def self.min_data_size(period: 14, **params)
4848 # @param data [Array] Array of hashes with keys (:date_time, :value)
4949 # @param period [Integer] The given period to calculate the RSI
5050 # @param price_key [Symbol] The hash key for the price data. Default :value
51+ # @param date_time_key [Symbol] The hash key for the date time data. Default :date_time
5152 #
5253 # @return [Array<RsiValue>] An array of RsiValue instances
53- def self . calculate ( data , period : 14 , price_key : :value )
54+ def self . calculate ( data , period : 14 , price_key : :value , date_time_key : :date_time )
5455 period = period . to_i
5556 price_key = price_key . to_sym
5657 Validation . validate_numeric_data ( data , price_key )
5758 Validation . validate_length ( data , min_data_size ( period : period ) )
58- Validation . validate_date_time_key ( data )
59+ Validation . validate_date_time_key ( data , date_time_key )
5960
60- data = data . sort_by { |row | row [ :date_time ] }
61+ data = data . sort_by { |row | row [ date_time_key ] }
6162
6263 output = [ ]
6364 prev_price = data . shift [ price_key ]
@@ -96,7 +97,7 @@ def self.calculate(data, period: 14, price_key: :value)
9697 rsi = ( 100.00 - ( 100.00 / ( 1.00 + rs ) ) )
9798 end
9899
99- output << RsiValue . new ( date_time : v [ :date_time ] , rsi : rsi )
100+ output << RsiValue . new ( date_time : v [ date_time_key ] , rsi : rsi )
100101
101102 prev_avg = { gain : avg_gain , loss : avg_loss }
102103 price_changes . shift
0 commit comments