Class: RubyTechnicalAnalysis::StatisticalMethods
- Defined in:
- lib/ruby_technical_analysis/indicators/statistical_methods.rb
Overview
Statistical Methods
Instance Attribute Summary
Attributes inherited from Indicator
Instance Method Summary collapse
-
#mean ⇒ Float
Mean.
-
#standard_deviation ⇒ Float
Standard Deviation.
-
#valid? ⇒ Boolean
Whether or not the object is valid.
-
#variance ⇒ Float
Variance.
Methods inherited from Indicator
Constructor Details
This class inherits a constructor from RubyTechnicalAnalysis::Indicator
Instance Method Details
#mean ⇒ Float
Mean
11 12 13 |
# File 'lib/ruby_technical_analysis/indicators/statistical_methods.rb', line 11 def mean series.reduce(:+) / series.length.to_f end |
#standard_deviation ⇒ Float
Standard Deviation
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.
30 31 32 |
# File 'lib/ruby_technical_analysis/indicators/statistical_methods.rb', line 30 def valid? series.length > 0 end |
#variance ⇒ Float
Variance
25 26 27 |
# File 'lib/ruby_technical_analysis/indicators/statistical_methods.rb', line 25 def variance squared_differences.reduce(:+) / series.length.to_f end |