Class: FinModeling::TimeSeriesEstimator

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(a, b) ⇒ TimeSeriesEstimator

Returns a new instance of TimeSeriesEstimator.



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

def initialize(a, b)
  @a, @b = a, b
end

Instance Attribute Details

#aObject (readonly)

Returns the value of attribute a.



3
4
5
# File 'lib/finmodeling/time_series_estimator.rb', line 3

def a
  @a
end

#bObject (readonly)

Returns the value of attribute b.



3
4
5
# File 'lib/finmodeling/time_series_estimator.rb', line 3

def b
  @b
end

Class Method Details

.from_const(y) ⇒ Object



21
22
23
# File 'lib/finmodeling/time_series_estimator.rb', line 21

def self.from_const(y)
  TimeSeriesEstimator.new(a=y, b=0.0)
end

.from_time_series(dates, ys) ⇒ Object



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

def self.from_time_series(dates, ys)
  xs = dates.map{ |date| date - Date.today }

  simple_regression = Statsample::Regression.simple(xs.to_scale, ys.to_scale)
  TimeSeriesEstimator.new(simple_regression.a, simple_regression.b)
end

Instance Method Details

#estimate_on(date) ⇒ Object



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

def estimate_on(date)
  x = (date - Date.today)
  a + (b*x)
end