Class: FinModeling::TimeSeriesEstimator
- Inherits:
-
Object
- Object
- FinModeling::TimeSeriesEstimator
- Defined in:
- lib/finmodeling/time_series_estimator.rb
Instance Attribute Summary collapse
-
#a ⇒ Object
readonly
Returns the value of attribute a.
-
#b ⇒ Object
readonly
Returns the value of attribute b.
Class Method Summary collapse
Instance Method Summary collapse
- #estimate_on(date) ⇒ Object
-
#initialize(a, b) ⇒ TimeSeriesEstimator
constructor
A new instance of TimeSeriesEstimator.
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
#a ⇒ Object (readonly)
Returns the value of attribute a.
3 4 5 |
# File 'lib/finmodeling/time_series_estimator.rb', line 3 def a @a end |
#b ⇒ Object (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 |