Class: RubyTechnicalAnalysis::RelativeStrengthIndex

Inherits:
Indicator
  • Object
show all
Defined in:
lib/ruby_technical_analysis/indicators/relative_strength_index.rb

Overview

Relative Strength Index

Find more information at: www.fidelity.com/viewpoints/active-investor/how-to-use-RSI

Instance Attribute Summary collapse

Attributes inherited from Indicator

#series

Instance Method Summary collapse

Methods inherited from Indicator

call

Constructor Details

#initialize(series: [], period: 14) ⇒ RelativeStrengthIndex

Returns a new instance of RelativeStrengthIndex.

Parameters:

  • series (Array) (defaults to: [])

    An array of prices, typically closing prices

  • period (Integer) (defaults to: 14)

    The number of periods to use in the calculation



10
11
12
13
14
15
16
17
18
# File 'lib/ruby_technical_analysis/indicators/relative_strength_index.rb', line 10

def initialize(series: [], period: 14)
  @period = period
  @rsi = []
  @smooth_up = []
  @smooth_down = []
  @wilders_is_set = false

  super(series: series)
end

Instance Attribute Details

#periodObject (readonly)

Returns the value of attribute period.



6
7
8
# File 'lib/ruby_technical_analysis/indicators/relative_strength_index.rb', line 6

def period
  @period
end

Instance Method Details

#callFloat

Returns The current RSI value.

Returns:

  • (Float)

    The current RSI value



21
22
23
# File 'lib/ruby_technical_analysis/indicators/relative_strength_index.rb', line 21

def call
  calculate_rsi
end

#valid?Boolean

Returns Whether or not the object is valid.

Returns:

  • (Boolean)

    Whether or not the object is valid



26
27
28
# File 'lib/ruby_technical_analysis/indicators/relative_strength_index.rb', line 26

def valid?
  period < series.length
end