diff --git a/lib/ruby_technical_analysis/indicators/moving_averages.rb b/lib/ruby_technical_analysis/indicators/moving_averages.rb index 33df1c9..f9bd8fa 100644 --- a/lib/ruby_technical_analysis/indicators/moving_averages.rb +++ b/lib/ruby_technical_analysis/indicators/moving_averages.rb @@ -30,7 +30,7 @@ def sma def ema return series.last if period == 1 - series.last(period).each_with_object([]) do |num, result| + series.each_with_object([]) do |num, result| result << if result.empty? num else @@ -59,8 +59,8 @@ def valid? def _ema_percentages @_ema_percentages ||= case period - when 12 then [0.846154, 0.153846] - when 26 then [0.925926, 0.074074] + when 12 then [0.153846, 0.846154] + when 26 then [0.074074, 0.925926] else last_obs_pct = 2.0 / (period + 1) diff --git a/lib/ruby_technical_analysis/indicators/relative_strength_index.rb b/lib/ruby_technical_analysis/indicators/relative_strength_index.rb index d4f0491..7c70f1e 100644 --- a/lib/ruby_technical_analysis/indicators/relative_strength_index.rb +++ b/lib/ruby_technical_analysis/indicators/relative_strength_index.rb @@ -30,7 +30,7 @@ def valid? private def _smooth_coef_one - @_smooth_coef_one ||= (1.0 / period).round(4) + @_smooth_coef_one ||= (1.0 / period) end def _smooth_coef_two @@ -39,7 +39,7 @@ def _smooth_coef_two def calculate_channels(cla) period.times.map do |index| - diff = (cla.at(index) - cla.at(index + 1)).round(4) + diff = (cla.at(index) - cla.at(index + 1)) [diff.negative? ? diff.abs : 0, diff.positive? ? diff : 0] end.transpose @@ -53,8 +53,8 @@ def calculate_initial_smoothing(up_ch, down_ch) end def calculate_subsequent_smoothing(up_ch, down_ch) - @smooth_up << (_smooth_coef_one * up_ch.last + _smooth_coef_two * @smooth_up.last).round(4) - @smooth_down << (_smooth_coef_one * down_ch.last + _smooth_coef_two * @smooth_down.last).round(4) + @smooth_up << (_smooth_coef_one * up_ch.last + _smooth_coef_two * @smooth_up.last) + @smooth_down << (_smooth_coef_one * down_ch.last + _smooth_coef_two * @smooth_down.last) end def calculate_smoothing(up_ch, down_ch) @@ -67,7 +67,7 @@ def calculate_rsi up_ch, down_ch = calculate_channels(cla) calculate_smoothing(up_ch, down_ch) - @rsi << (100.00 - (100.00 / ((@smooth_up.last.to_f / @smooth_down.last) + 1))).round(4) + @rsi << (100.00 - (100.00 / ((@smooth_up.last.to_f / @smooth_down.last) + 1))) end.last end end