Class: TechnicalAnalysis::ArrayHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/technical_analysis/helpers/array_helper.rb

Class Method Summary collapse

Class Method Details

.average(data) ⇒ Object



12
13
14
# File 'lib/technical_analysis/helpers/array_helper.rb', line 12

def self.average(data)
  sum(data) / data.size.to_f
end

.mean(data) ⇒ Object



8
9
10
# File 'lib/technical_analysis/helpers/array_helper.rb', line 8

def self.mean(data)
  sum(data) / data.size.to_f
end

.sample_variance(data) ⇒ Object



16
17
18
19
20
# File 'lib/technical_analysis/helpers/array_helper.rb', line 16

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

.standard_deviation(data) ⇒ Object



22
23
24
# File 'lib/technical_analysis/helpers/array_helper.rb', line 22

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

.sum(data) ⇒ Object



4
5
6
# File 'lib/technical_analysis/helpers/array_helper.rb', line 4

def self.sum(data)
  data.inject(0, :+)
end