Class: RubyTechnicalAnalysis::RelativeMomentumIndex

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

Overview

Relative Momentum Index

Instance Attribute Summary collapse

Attributes inherited from Indicator

#series

Instance Method Summary collapse

Methods inherited from Indicator

call

Constructor Details

#initialize(series: [], period_mom: 14, period_rmi: 20) ⇒ RelativeMomentumIndex

Returns a new instance of RelativeMomentumIndex.

Parameters:

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

    An array of prices, typically closing prices

  • period_mom (Integer) (defaults to: 14)

    The number of periods to use in the momentum calculation

  • period_rmi (Integer) (defaults to: 20)

    The number of periods to use in the RMI calculation



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

def initialize(series: [], period_mom: 14, period_rmi: 20)
  @period_mom = period_mom
  @period_rmi = period_rmi
  @rmi = []
  @rmi_intermediate = []
  @smooth_up = []
  @smooth_down = []
  @wilders_is_set = false

  super(series: series)
end

Instance Attribute Details

#period_momObject (readonly)

Returns the value of attribute period_mom.



4
5
6
# File 'lib/ruby_technical_analysis/indicators/relative_momentum_index.rb', line 4

def period_mom
  @period_mom
end

#period_rmiObject (readonly)

Returns the value of attribute period_rmi.



4
5
6
# File 'lib/ruby_technical_analysis/indicators/relative_momentum_index.rb', line 4

def period_rmi
  @period_rmi
end

Instance Method Details

#callFloat

Returns The current RMI value.

Returns:

  • (Float)

    The current RMI value



22
23
24
# File 'lib/ruby_technical_analysis/indicators/relative_momentum_index.rb', line 22

def call
  calculate_rmi
end

#valid?Boolean

Returns Whether or not the object is valid.

Returns:

  • (Boolean)

    Whether or not the object is valid



27
28
29
# File 'lib/ruby_technical_analysis/indicators/relative_momentum_index.rb', line 27

def valid?
  period_mom + period_rmi <= series.length
end