Module: Enumerable

Defined in:
lib/indicators/calculations/helper.rb

Overview

Extra methods for mathematical calculations.

Instance Method Summary collapse

Instance Method Details

#meanObject



72
73
74
# File 'lib/indicators/calculations/helper.rb', line 72

def mean
  return self.sum / self.length.to_f
end

#sample_varianceObject



76
77
78
79
80
# File 'lib/indicators/calculations/helper.rb', line 76

def sample_variance
  m = self.mean
  sum = self.inject(0){|accum, i| accum + (i - m) ** 2 }
  return sum / (self.length - 1).to_f
end

#standard_deviationObject



82
83
84
# File 'lib/indicators/calculations/helper.rb', line 82

def standard_deviation
  return Math.sqrt(self.sample_variance)
end

#sumObject



68
69
70
# File 'lib/indicators/calculations/helper.rb', line 68

def sum
  return self.inject(0){|accum, i| accum + i }
end