statsample-timeseries 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile +0 -1
- data/VERSION +1 -1
- data/lib/statsample-timeseries/arima.rb +6 -2
- data/lib/statsample-timeseries/arima/kalman.rb +1 -1
- data/test/test_arima_ks.rb +39 -35
- metadata +2 -18
data/Gemfile
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.3
|
@@ -36,8 +36,12 @@ module Statsample
|
|
36
36
|
if i > 0
|
37
37
|
ts = ts.diff(i).reject { |x| x.nil? }.to_ts
|
38
38
|
end
|
39
|
-
|
40
|
-
|
39
|
+
if Statsample.has_gsl?
|
40
|
+
filter = Arima::KalmanFilter.new(ts, p, i, q)
|
41
|
+
filter
|
42
|
+
else
|
43
|
+
raise("GSL not available. Install GSL and rb-gsl first")
|
44
|
+
end
|
41
45
|
end
|
42
46
|
|
43
47
|
def ar(p)
|
data/test/test_arima_ks.rb
CHANGED
@@ -7,24 +7,26 @@ class StatsampleArimaKSTestCase < MiniTest::Unit::TestCase
|
|
7
7
|
setup do
|
8
8
|
@s = [-1.16025577,0.64758021,0.77158601,0.14989543,2.31358162,3.49213868,1.14826956,0.58169457,-0.30813868,-0.34741084,-1.41175595,0.06040081, -0.78230232,0.86734837,0.95015787,-0.49781397,0.53247330,1.56495187,0.30936619,0.09750217,1.09698829,-0.81315490,-0.79425607,-0.64568547,-1.06460320,1.24647894,0.66695937,1.50284551,1.17631218,1.64082872,1.61462736,0.06443761,-0.17583741,0.83918339,0.46610988,-0.54915270,-0.56417108,-1.27696654,0.89460084,1.49970338,0.24520493,0.26249138,-1.33744834,-0.57725961,1.55819543,1.62143157,0.44421891,-0.74000084 ,0.57866347,3.51189333,2.39135077,1.73046244,1.81783890,0.21454040,0.43520890,-1.42443856,-2.72124685,-2.51313877,-1.20243091,-1.44268002 ,-0.16777305,0.05780661,2.03533992,0.39187242,0.54987983,0.57865693,-0.96592469,-0.93278473,-0.75962671,-0.63216906,1.06776183, 0.17476059 ,0.06635860,0.94906227,2.44498583,-1.04990407,-0.88440073,-1.99838258,-1.12955558,-0.62654882,-1.36589161,-2.67456821,-0.97187696, -0.84431782 ,-0.10051809,0.54239549,1.34622861,1.25598105,0.19707759,3.29286114,3.52423499,1.69146333,-0.10150024,0.45222903,-0.01730516, -0.49828727, -1.18484684,-1.09531773,-1.17190808,0.30207662].to_ts
|
9
9
|
end
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
10
|
+
if Statsample.has_gsl?
|
11
|
+
context "passed through the Kalman Filter" do
|
12
|
+
setup do
|
13
|
+
@kf=Statsample::TimeSeries::ARIMA.ks(@s,1,0,0)
|
14
|
+
end
|
15
|
+
should "return correct object" do
|
16
|
+
assert_instance_of Statsample::TimeSeries::Arima::KalmanFilter, @kf
|
17
|
+
end
|
18
|
+
should "return correct parameters" do
|
19
|
+
assert_equal @kf.p,1
|
20
|
+
assert_equal @kf.q,0
|
21
|
+
assert_equal @kf.i,0
|
22
|
+
end
|
23
|
+
should "return correct ar estimators" do
|
24
|
+
assert_equal @kf.ar.length,1
|
25
|
+
assert_in_delta @kf.ar[0], 0.700 #0.564
|
26
|
+
end
|
27
|
+
should "return correct ma estimators" do
|
28
|
+
assert_equal @kf.ma.length,0
|
29
|
+
end
|
28
30
|
end
|
29
31
|
end
|
30
32
|
context "passed through the Kalman Filter with AR(0.564)" do
|
@@ -66,24 +68,26 @@ class StatsampleArimaKSTestCase < MiniTest::Unit::TestCase
|
|
66
68
|
setup do
|
67
69
|
@s = [-1.16025577,0.64758021,0.77158601,0.14989543,2.31358162,3.49213868,1.14826956,0.58169457,-0.30813868,-0.34741084,-1.41175595,0.06040081, -0.78230232,0.86734837,0.95015787,-0.49781397,0.53247330,1.56495187,0.30936619,0.09750217,1.09698829,-0.81315490,-0.79425607,-0.64568547,-1.06460320,1.24647894,0.66695937,1.50284551,1.17631218,1.64082872,1.61462736,0.06443761,-0.17583741,0.83918339,0.46610988,-0.54915270,-0.56417108,-1.27696654,0.89460084,1.49970338,0.24520493,0.26249138,-1.33744834,-0.57725961,1.55819543,1.62143157,0.44421891,-0.74000084 ,0.57866347,3.51189333,2.39135077,1.73046244,1.81783890,0.21454040,0.43520890,-1.42443856,-2.72124685,-2.51313877,-1.20243091,-1.44268002 ,-0.16777305,0.05780661,2.03533992,0.39187242,0.54987983,0.57865693,-0.96592469,-0.93278473,-0.75962671,-0.63216906,1.06776183, 0.17476059 ,0.06635860,0.94906227,2.44498583,-1.04990407,-0.88440073,-1.99838258,-1.12955558,-0.62654882,-1.36589161,-2.67456821,-0.97187696, -0.84431782 ,-0.10051809,0.54239549,1.34622861,1.25598105,0.19707759,3.29286114,3.52423499,1.69146333,-0.10150024,0.45222903,-0.01730516, -0.49828727, -1.18484684,-1.09531773,-1.17190808,0.30207662].to_ts
|
68
70
|
end
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
71
|
+
if Statsample.has_gsl?
|
72
|
+
context "passed through the Kalman Filter" do
|
73
|
+
setup do
|
74
|
+
@kf = Statsample::TimeSeries::ARIMA.ks(@s, 2, 0, 1)
|
75
|
+
end
|
73
76
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
77
|
+
should "return correct parameters" do
|
78
|
+
assert_equal @kf.p, 2
|
79
|
+
assert_equal @kf.q, 1
|
80
|
+
assert_equal @kf.i, 0
|
81
|
+
end
|
82
|
+
should "return correct AR estimators" do
|
83
|
+
assert_equal @kf.ar.length, 2
|
84
|
+
assert_in_delta @kf.ar[0], 0.45, 0.01
|
85
|
+
assert_in_delta @kf.ar[1], 0.016, 0.01
|
86
|
+
end
|
87
|
+
should "return correct ma estimators" do
|
88
|
+
assert_equal @kf.ma.length, 1
|
89
|
+
assert_in_delta @kf.ma[0], 0.18, 0.01
|
90
|
+
end
|
87
91
|
end
|
88
92
|
end
|
89
93
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: statsample-timeseries
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -188,22 +188,6 @@ dependencies:
|
|
188
188
|
- - ~>
|
189
189
|
- !ruby/object:Gem::Version
|
190
190
|
version: 0.14.0
|
191
|
-
- !ruby/object:Gem::Dependency
|
192
|
-
name: gsl
|
193
|
-
requirement: !ruby/object:Gem::Requirement
|
194
|
-
none: false
|
195
|
-
requirements:
|
196
|
-
- - ! '>='
|
197
|
-
- !ruby/object:Gem::Version
|
198
|
-
version: '0'
|
199
|
-
type: :development
|
200
|
-
prerelease: false
|
201
|
-
version_requirements: !ruby/object:Gem::Requirement
|
202
|
-
none: false
|
203
|
-
requirements:
|
204
|
-
- - ! '>='
|
205
|
-
- !ruby/object:Gem::Version
|
206
|
-
version: '0'
|
207
191
|
description: Statsample-timeseries is an extension to Statsample. It incorporates
|
208
192
|
helpful timeseries functions and modules like ARMA, ARIMA, acf, pacf, lags etc.
|
209
193
|
email: ankurgel@gmail.com
|
@@ -257,7 +241,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
257
241
|
version: '0'
|
258
242
|
segments:
|
259
243
|
- 0
|
260
|
-
hash:
|
244
|
+
hash: 903118733
|
261
245
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
262
246
|
none: false
|
263
247
|
requirements:
|