Class: RubyTechnicalAnalysis::StatisticalMethods

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

Overview

Statistical Methods

Instance Attribute Summary

Attributes inherited from Indicator

#series

Instance Method Summary collapse

Methods inherited from Indicator

call, #initialize

Constructor Details

This class inherits a constructor from RubyTechnicalAnalysis::Indicator

Instance Method Details

#meanFloat

Mean

Returns:

  • (Float)

    The mean of the price series



11
12
13
# File 'lib/ruby_technical_analysis/indicators/statistical_methods.rb', line 11

def mean
  series.reduce(:+) / series.length.to_f
end

#standard_deviationFloat

Standard Deviation

Returns:

  • (Float)

    The standard deviation of the price series



17
18
19
20
21
# File 'lib/ruby_technical_analysis/indicators/statistical_methods.rb', line 17

def standard_deviation
  return 0 if series.uniq.length == 1

  Math.sqrt(variance)
end

#valid?Boolean

Returns Whether or not the object is valid.

Returns:

  • (Boolean)

    Whether or not the object is valid



30
31
32
# File 'lib/ruby_technical_analysis/indicators/statistical_methods.rb', line 30

def valid?
  series.length > 0
end

#varianceFloat

Variance

Returns:

  • (Float)

    The variance of the price series



25
26
27
# File 'lib/ruby_technical_analysis/indicators/statistical_methods.rb', line 25

def variance
  squared_differences.reduce(:+) / series.length.to_f
end