Class: FinModeling::ArrayWithStats

Inherits:
Array
  • Object
show all
Defined in:
lib/finmodeling/array_with_stats.rb

Instance Method Summary collapse

Instance Method Details

#linear_regressionObject



15
16
17
18
19
# File 'lib/finmodeling/array_with_stats.rb', line 15

def linear_regression
  x = Array(0..(self.length-1)).to_scale
  y = self.to_scale
  Statsample::Regression.simple(x,y)
end

#meanObject



4
5
6
7
# File 'lib/finmodeling/array_with_stats.rb', line 4

def mean
  return nil if empty?
  self.inject(:+) / self.length
end

#varianceObject



9
10
11
12
13
# File 'lib/finmodeling/array_with_stats.rb', line 9

def variance
  x_sqrd = self.map{ |x| x*x }
  x_sqrd_mean = (ArrayWithStats.new(x_sqrd).mean)
  x_sqrd_mean - (mean**2)
end