quant 0.0.0 → 0.0.2

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/.gitignore CHANGED
@@ -15,3 +15,5 @@ spec/reports
15
15
  test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
+ .idea
19
+ .rvmrc
data/CHANGELOG ADDED
@@ -0,0 +1,3 @@
1
+ 0.0.2 (2012-06-18)
2
+
3
+ * Donchian Channels added
data/Gemfile CHANGED
@@ -2,3 +2,5 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in quant.gemspec
4
4
  gemspec
5
+
6
+ gem 'rake'
data/Rakefile CHANGED
@@ -1,2 +1,11 @@
1
1
  #!/usr/bin/env rake
2
2
  require "bundler/gem_tasks"
3
+ require "rake/testtask"
4
+
5
+ Rake::TestTask.new do |t|
6
+ t.libs << "test"
7
+ t.test_files = FileList['test/**/test*.rb']
8
+ t.verbose = true
9
+ end
10
+
11
+ task :default => :test
data/lib/enumerable.rb ADDED
@@ -0,0 +1,6 @@
1
+ module Enumerable
2
+ def inject_with_index(injected)
3
+ each_with_index{ |obj, index| injected = yield(injected, obj, index) }
4
+ injected
5
+ end
6
+ end
data/lib/quant/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Quant
2
- VERSION = "0.0.0"
2
+ VERSION = "0.0.2"
3
3
  end
data/lib/quant.rb CHANGED
@@ -1,5 +1,39 @@
1
1
  require "quant/version"
2
2
 
3
3
  module Quant
4
- # Your code goes here...
4
+
5
+ def self.sma(values, n)
6
+ acc = 0
7
+ values.inject_with_index([]) do |m, e, i|
8
+ acc += e
9
+ if i < (n - 1)
10
+ m << not_a_number
11
+ elsif i == (n - 1)
12
+ m << acc / n
13
+ else
14
+ acc = acc - values[i - n]
15
+ m << acc / n
16
+ end
17
+ end
18
+ end
19
+
20
+ def self.donchian_channel(ohlc, n)
21
+ dc = []
22
+ ohlc.each_with_index do |e, i|
23
+ if i < (n - 1)
24
+ dc << [not_a_number, not_a_number]
25
+ else
26
+ c = ohlc[(i - n + 1)..(i)].flatten
27
+ dc << [c.max, c.min]
28
+ end
29
+ end
30
+ dc
31
+ end
32
+
33
+ private
34
+
35
+ def self.not_a_number
36
+ 0 / 0.0
37
+ end
38
+
5
39
  end
@@ -0,0 +1,125 @@
1
+ require "minitest/autorun"
2
+ require "quant"
3
+ require "enumerable"
4
+
5
+ class TestQuant < MiniTest::Unit::TestCase
6
+
7
+ def test_eurusd_50_sma10
8
+ assert compare_2_arrays_of_floats Quant.sma(eurusd_50_closes, 10), eurusd_50_ttr_sma10
9
+ end
10
+
11
+ def test_usdjpy_150_sma25
12
+ assert compare_2_arrays_of_floats Quant.sma(usdjpy_150_closes, 25), usdjpy_150_ttr_sma25
13
+ end
14
+
15
+ def test_eurusd_50_donchian_channel_20_highs
16
+ c = ohlc(eurusd_50_opens, eurusd_50_highs, eurusd_50_lows, eurusd_50_closes)
17
+ dc20_highs = Quant.donchian_channel(c, 20).inject([]) { |a, e| a << e[0] }
18
+ assert compare_2_arrays_of_floats dc20_highs , eurusd_50_ttr_donchian_channel_20_highs
19
+ end
20
+
21
+ def test_eurusd_50_donchian_channel_20_lows
22
+ c = ohlc(eurusd_50_opens, eurusd_50_highs, eurusd_50_lows, eurusd_50_closes)
23
+ dc20_lows = Quant.donchian_channel(c, 20).inject([]) { |a, e| a << e[1] }
24
+ assert compare_2_arrays_of_floats dc20_lows , eurusd_50_ttr_donchian_channel_20_lows
25
+ end
26
+
27
+ def test_usdjpy_150_donchian_channel_55_highs
28
+ c = ohlc(usdjpy_150_opens, usdjpy_150_highs, usdjpy_150_lows, usdjpy_150_closes)
29
+ dc55_highs = Quant.donchian_channel(c, 55).inject([]) { |a, e| a << e[0] }
30
+ assert compare_2_arrays_of_floats dc55_highs , usdjpy_150_ttr_donchian_channel_55_highs
31
+ end
32
+
33
+ def test_usdjpy_150_donchian_channel_55_lows
34
+ c = ohlc(usdjpy_150_opens, usdjpy_150_highs, usdjpy_150_lows, usdjpy_150_closes)
35
+ dc55_lows = Quant.donchian_channel(c, 55).inject([]) { |a, e| a << e[1] }
36
+ assert compare_2_arrays_of_floats dc55_lows , usdjpy_150_ttr_donchian_channel_55_lows
37
+ end
38
+
39
+ private
40
+
41
+ def eurusd_50_opens
42
+ [1.2306, 1.2207, 1.2244, 1.2159, 1.1944, 1.1916, 1.1962, 1.1983, 1.2105, 1.2119, 1.2211, 1.2323, 1.2299, 1.2377, 1.2429, 1.2313, 1.2308, 1.2325, 1.2377, 1.2278, 1.2186, 1.2232, 1.2514, 1.2553, 1.2535, 1.2623, 1.2629, 1.2691, 1.264, 1.2585, 1.2725, 1.2739, 1.2934, 1.2896, 1.2946, 1.2889, 1.2752, 1.2883, 1.2894, 1.2985, 1.2999, 1.2985, 1.3078, 1.3059, 1.3173, 1.3224, 1.3153, 1.3182, 1.329, 1.3223]
43
+ end
44
+
45
+ def eurusd_50_highs
46
+ [1.235, 1.227, 1.2324, 1.2213, 1.1988, 1.2006, 1.207, 1.2139, 1.2149, 1.2296, 1.2347, 1.235, 1.2408, 1.2414, 1.2464, 1.2351, 1.2384, 1.2392, 1.2395, 1.2287, 1.23, 1.2537, 1.2608, 1.256, 1.2659, 1.2661, 1.2709, 1.272, 1.2645, 1.2736, 1.2774, 1.2952, 1.3004, 1.2989, 1.3026, 1.291, 1.2927, 1.2962, 1.3003, 1.3043, 1.3039, 1.3104, 1.309, 1.3192, 1.3259, 1.3237, 1.3233, 1.3331, 1.3305, 1.3228]
47
+ end
48
+
49
+ def eurusd_50_lows
50
+ [1.211, 1.2174, 1.2151, 1.1954, 1.1875, 1.1901, 1.1923, 1.1955, 1.2044, 1.2114, 1.2167, 1.2254, 1.224, 1.2351, 1.2302, 1.2249, 1.226, 1.2253, 1.2264, 1.215, 1.2165, 1.2192, 1.248, 1.2507, 1.2478, 1.2551, 1.262, 1.2608, 1.255, 1.2522, 1.2681, 1.2708, 1.2888, 1.2869, 1.2838, 1.273, 1.2736, 1.2792, 1.2874, 1.2951, 1.2965, 1.2976, 1.2979, 1.3052, 1.3145, 1.313, 1.3117, 1.3156, 1.3215, 1.3073]
51
+ end
52
+
53
+ def eurusd_50_closes
54
+ # 50 EURUSD closes, from 2010-06-01 to 2010-08-10
55
+ [1.2207, 1.2244, 1.2159, 1.1964, 1.1915, 1.1962, 1.1983, 1.2105, 1.2092, 1.2211, 1.2322, 1.2299, 1.2377, 1.237, 1.2312, 1.2267, 1.2325, 1.2383, 1.2278, 1.2185, 1.2231, 1.2515, 1.2548, 1.2535, 1.2624, 1.263, 1.269, 1.2637, 1.2585, 1.2725, 1.274, 1.2934, 1.2924, 1.2947, 1.2889, 1.2753, 1.2883, 1.2913, 1.2984, 1.2999, 1.2985, 1.3079, 1.3028, 1.3174, 1.3224, 1.3153, 1.3182, 1.329, 1.3222, 1.3175]
56
+ end
57
+
58
+ def eurusd_50_ttr_sma10
59
+ # SMA 10 of eurusd_50_closes generated with the TTR R package
60
+ [not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, 1.2084199999999998, 1.2095699999999998, 1.2101199999999999, 1.2123, 1.2163599999999999, 1.22033, 1.22338, 1.2268, 1.22958, 1.2314399999999999, 1.23118, 1.23027, 1.23243, 1.23414, 1.23579, 1.23891, 1.24254, 1.24619, 1.24873, 1.2517999999999998, 1.2571999999999999, 1.26229, 1.26648, 1.2702399999999998, 1.27436, 1.27701, 1.2782399999999998, 1.28017, 1.28293, 1.2869199999999998, 1.28966, 1.2921099999999999, 1.2935599999999998, 1.2946, 1.29687, 1.30022, 1.30422, 1.30721, 1.31098, 1.3133599999999999, 1.3151199999999998]
61
+ end
62
+
63
+ def eurusd_50_ttr_donchian_channel_20_highs
64
+ [not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, 1.2464, 1.2464, 1.2537, 1.2608, 1.2608, 1.2659, 1.2661, 1.2709, 1.272, 1.272, 1.2736, 1.2774, 1.2952, 1.3004, 1.3004, 1.3026, 1.3026, 1.3026, 1.3026, 1.3026, 1.3043, 1.3043, 1.3104, 1.3104, 1.3192, 1.3259, 1.3259, 1.3259, 1.3331, 1.3331, 1.3331]
65
+ end
66
+
67
+ def eurusd_50_ttr_donchian_channel_20_lows
68
+ [not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, 1.1875, 1.1875, 1.1875, 1.1875, 1.1875, 1.1901, 1.1923, 1.1955, 1.2044, 1.2114, 1.215, 1.215, 1.215, 1.215, 1.215, 1.215, 1.215, 1.215, 1.215, 1.215, 1.2165, 1.2192, 1.2478, 1.2478, 1.2478, 1.2522, 1.2522, 1.2522, 1.2522, 1.2522, 1.2681]
69
+ end
70
+
71
+ def usdjpy_150_opens
72
+ [78.06, 77.71, 77.72, 77.63, 77.18, 77.08, 77.01, 77.0, 76.97, 76.87, 76.89, 76.95, 77.26, 77.11, 77.44, 78.06, 77.92, 77.56, 77.7, 78.08, 77.81, 77.7, 77.63, 77.6, 77.61, 77.92, 77.94, 78.06, 77.87, 77.74, 78.0, 77.8, 78.01, 78.14, 78.06, 77.98, 77.85, 77.91, 77.61, 76.94, 76.88, 76.71, 76.72, 77.09, 76.79, 76.83, 76.81, 76.86, 76.75, 76.88, 76.78, 76.81, 76.76, 77.08, 76.94, 76.95, 77.63, 77.69, 77.43, 76.74, 76.35, 76.28, 76.16, 76.16, 76.53, 76.56, 76.77, 77.02, 77.63, 77.63, 77.55, 78.39, 78.37, 78.87, 79.72, 79.6, 79.71, 80.28, 79.95, 81.58, 80.46, 80.49, 81.27, 81.11, 81.83, 81.49, 80.67, 81.14, 81.51, 82.42, 82.3, 82.95, 83.73, 83.6, 83.48, 83.36, 83.66, 83.4, 82.59, 82.42, 82.86, 83.17, 82.87, 82.38, 82.95, 82.07, 82.79, 82.4, 82.35, 81.53, 81.52, 80.71, 80.85, 80.85, 80.9, 80.41, 80.86, 81.26, 81.58, 81.56, 81.15, 81.31, 81.3, 80.97, 80.29, 79.8, 80.07, 80.11, 80.17, 79.77, 79.87, 79.86, 79.62, 79.88, 79.94, 79.84, 80.21, 80.31, 79.3, 79.2, 79.27, 79.96, 79.43, 79.56, 79.64, 79.46, 79.51, 79.09, 78.35, 78.06]
73
+ end
74
+
75
+ def usdjpy_150_highs
76
+ [78.06, 77.86, 77.85, 77.66, 77.22, 77.46, 77.12, 77.07, 77.01, 76.97, 77.3, 77.56, 77.31, 77.77, 78.21, 78.26, 78.13, 77.78, 78.05, 78.08, 77.83, 77.76, 77.77, 77.76, 77.97, 77.99, 78.13, 78.06, 77.94, 78.14, 78.03, 78.08, 78.18, 78.2, 78.08, 78.0, 78.01, 77.93, 77.72, 76.99, 76.94, 76.81, 77.22, 77.31, 76.98, 76.88, 77.01, 76.96, 76.98, 76.92, 76.85, 76.85, 77.29, 77.28, 77.06, 77.83, 78.26, 77.78, 77.46, 76.75, 76.39, 76.33, 76.22, 76.71, 76.78, 76.94, 77.16, 77.7, 77.78, 77.76, 78.51, 78.64, 78.94, 79.48, 79.86, 79.82, 80.38, 80.33, 80.98, 81.6, 80.76, 81.28, 81.36, 81.85, 81.84, 81.56, 81.2, 81.71, 82.62, 82.49, 83.06, 83.8, 84.15, 83.6, 83.54, 83.81, 84.07, 83.41, 82.92, 82.98, 83.36, 83.17, 82.94, 82.85, 83.28, 82.97, 82.91, 82.45, 82.53, 81.64, 81.84, 81.1, 81.11, 81.17, 80.92, 80.9, 81.54, 81.71, 81.75, 81.64, 81.37, 81.67, 81.4, 81.42, 80.36, 80.28, 80.59, 80.53, 80.36, 79.97, 80.05, 79.92, 79.99, 79.97, 80.16, 80.31, 80.53, 80.37, 79.44, 79.42, 80.12, 80.05, 79.61, 79.8, 79.65, 79.61, 79.54, 79.11, 78.65, 78.39]
77
+ end
78
+
79
+ def usdjpy_150_lows
80
+ [77.58, 77.52, 77.48, 77.03, 76.79, 76.89, 76.83, 76.89, 76.55, 76.74, 76.81, 76.9, 76.99, 77.1, 77.44, 77.6, 77.27, 77.46, 77.69, 77.67, 77.62, 77.6, 77.11, 77.47, 77.56, 77.62, 77.9, 78.06, 77.59, 77.74, 77.69, 77.67, 77.98, 77.98, 77.9, 77.77, 77.54, 77.57, 76.88, 76.85, 76.6, 76.59, 76.64, 76.95, 76.75, 76.75, 76.81, 76.65, 76.64, 76.68, 76.53, 76.63, 76.68, 76.89, 76.84, 76.94, 77.54, 77.27, 76.63, 76.19, 76.14, 76.0, 76.02, 76.12, 76.47, 76.49, 76.69, 77.01, 77.5, 77.37, 77.34, 78.16, 78.34, 78.77, 79.34, 79.53, 79.71, 79.83, 79.91, 80.11, 80.0, 80.23, 80.82, 81.07, 81.13, 80.57, 80.56, 81.07, 81.45, 82.09, 81.95, 82.87, 83.17, 83.6, 83.0, 83.3, 83.27, 83.4, 81.97, 82.41, 82.62, 82.59, 81.9, 81.81, 81.86, 81.53, 82.07, 81.81, 81.3, 81.18, 80.61, 80.56, 80.71, 80.82, 80.9, 80.31, 80.86, 81.15, 81.47, 80.95, 80.83, 81.06, 80.64, 80.33, 79.71, 79.62, 80.03, 80.08, 79.8, 79.62, 79.69, 79.41, 79.58, 79.71, 79.66, 79.79, 80.17, 79.11, 78.99, 79.08, 79.25, 79.19, 79.32, 79.48, 79.31, 79.35, 78.84, 78.19, 77.64, 77.96]
81
+ end
82
+
83
+ def usdjpy_150_closes
84
+ # 150 USDJPY closes, from 2011-11-08 to 2010-06-04
85
+ [77.71, 77.72, 77.62, 77.09, 77.08, 77.01, 77.0, 76.97, 76.89, 76.9, 76.95, 77.26, 77.11, 77.72, 78.06, 77.92, 77.56, 77.7, 77.96, 77.81, 77.7, 77.63, 77.6, 77.5, 77.93, 77.94, 78.06, 78.06, 77.78, 78.0, 77.8, 78.01, 78.13, 78.04, 77.98, 77.85, 77.91, 77.62, 76.94, 76.89, 76.7, 76.73, 77.09, 76.97, 76.83, 76.81, 76.86, 76.76, 76.93, 76.78, 76.81, 76.77, 77.08, 76.95, 76.96, 77.64, 77.69, 77.43, 76.66, 76.36, 76.28, 76.16, 76.16, 76.53, 76.55, 76.78, 77.02, 77.63, 77.6, 77.56, 78.39, 78.37, 78.86, 79.47, 79.6, 79.72, 80.28, 79.95, 80.98, 80.46, 80.49, 81.27, 81.11, 81.78, 81.49, 80.68, 81.15, 81.52, 82.39, 82.3, 82.95, 83.73, 83.6, 83.6, 83.36, 83.66, 83.4, 83.4, 82.32, 82.85, 83.17, 82.87, 82.38, 82.77, 82.06, 82.8, 82.4, 82.35, 81.51, 81.52, 80.72, 80.84, 80.85, 81.0, 80.91, 80.86, 81.26, 81.58, 81.54, 81.15, 81.3, 81.3, 80.97, 80.35, 79.8, 80.07, 80.11, 80.17, 79.82, 79.87, 79.86, 79.62, 79.87, 79.9, 79.84, 80.21, 80.31, 79.29, 79.05, 79.27, 79.96, 79.43, 79.56, 79.64, 79.45, 79.51, 79.09, 78.35, 78.12, 78.32]
86
+ end
87
+
88
+ def usdjpy_150_ttr_donchian_channel_55_highs
89
+ [not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, 78.26, 78.26, 78.26, 78.26, 78.26, 78.26, 78.26, 78.26, 78.26, 78.26, 78.26, 78.26, 78.26, 78.26, 78.26, 78.26, 78.51, 78.64, 78.94, 79.48, 79.86, 79.86, 80.38, 80.38, 80.98, 81.6, 81.6, 81.6, 81.6, 81.85, 81.85, 81.85, 81.85, 81.85, 82.62, 82.62, 83.06, 83.8, 84.15, 84.15, 84.15, 84.15, 84.15, 84.15, 84.15, 84.15, 84.15, 84.15, 84.15, 84.15, 84.15, 84.15, 84.15, 84.15, 84.15, 84.15, 84.15, 84.15, 84.15, 84.15, 84.15, 84.15, 84.15, 84.15, 84.15, 84.15, 84.15, 84.15, 84.15, 84.15, 84.15, 84.15, 84.15, 84.15, 84.15, 84.15, 84.15, 84.15, 84.15, 84.15, 84.15, 84.15, 84.15, 84.15, 84.15, 84.15, 84.15, 84.15, 84.15, 84.15, 84.15, 84.15, 84.15, 84.07, 84.07, 84.07]
90
+ end
91
+
92
+ def usdjpy_150_ttr_donchian_channel_55_lows
93
+ [not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, 76.53, 76.53, 76.53, 76.53, 76.53, 76.19, 76.14, 76.0, 76.0, 76.0, 76.0, 76.0, 76.0, 76.0, 76.0, 76.0, 76.0, 76.0, 76.0, 76.0, 76.0, 76.0, 76.0, 76.0, 76.0, 76.0, 76.0, 76.0, 76.0, 76.0, 76.0, 76.0, 76.0, 76.0, 76.0, 76.0, 76.0, 76.0, 76.0, 76.0, 76.0, 76.0, 76.0, 76.0, 76.0, 76.0, 76.0, 76.0, 76.0, 76.0, 76.0, 76.0, 76.0, 76.0, 76.0, 76.0, 76.0, 76.0, 76.0, 76.0, 76.0, 76.0, 76.02, 76.12, 76.47, 76.49, 76.69, 77.01, 77.34, 77.34, 77.34, 78.16, 78.34, 78.77, 79.34, 79.53, 79.62, 79.41, 79.41, 79.41, 79.41, 79.41, 79.41, 79.11, 78.99, 78.99, 78.99, 78.99, 78.99, 78.99, 78.99, 78.99, 78.84, 78.19, 77.64, 77.64]
94
+ end
95
+
96
+ def usdjpy_150_ttr_sma25
97
+ # SMA 25 of usdjpy_150_closes generated with the TTR R package
98
+ [not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, not_a_number, 77.456, 77.46520000000001, 77.4788, 77.49640000000001, 77.524, 77.5608, 77.59240000000001, 77.6328, 77.6792, 77.7252, 77.7684, 77.8044, 77.8304, 77.85079999999999, 77.8196, 77.7728, 77.724, 77.6908, 77.66640000000001, 77.6268, 77.58760000000001, 77.552, 77.52120000000001, 77.4876, 77.46480000000001, 77.4188, 77.37360000000001, 77.322, 77.28280000000001, 77.2496, 77.208, 77.20160000000001, 77.1888, 77.1608, 77.10560000000001, 77.0408, 76.97800000000001, 76.908, 76.8496, 76.8332, 76.8196, 76.8228, 76.8344, 76.85600000000001, 76.88119999999999, 76.9104, 76.9736, 77.034, 77.118, 77.2196, 77.33239999999999, 77.4488, 77.5892, 77.70400000000001, 77.8652, 78.0052, 78.1192, 78.2624, 78.4096, 78.6144, 78.8196, 78.99560000000001, 79.1952, 79.4096, 79.644, 79.87400000000001, 80.1208, 80.3892, 80.628, 80.868, 81.1, 81.3108, 81.512, 81.6936, 81.80760000000001, 81.9376, 82.0756, 82.1792, 82.2764, 82.348, 82.412, 82.5044, 82.54960000000001, 82.5992, 82.58840000000001, 82.5896, 82.59120000000001, 82.57880000000002, 82.552, 82.4964, 82.4408, 82.35719999999999, 82.2584, 82.1776, 82.0952, 82.0068, 81.9124, 81.8284, 81.7312, 81.6524, 81.5304, 81.4064, 81.296, 81.2076, 81.0896, 81.002, 80.8844, 80.7732, 80.674, 80.6096, 80.5424, 80.522, 80.5008, 80.4384, 80.3604, 80.29480000000001, 80.25880000000001, 80.18560000000001, 80.10480000000001, 80.0288, 79.9608, 79.8892, 79.8008, 79.696, 79.6068, 79.5476]
99
+ end
100
+
101
+ def not_a_number
102
+ 0/0.0
103
+ end
104
+
105
+ def compare_2_arrays_of_floats(a, b)
106
+ delete_nans_and_truncate_floats_to_strings(a) == delete_nans_and_truncate_floats_to_strings(b)
107
+ end
108
+
109
+ def truncate_float_to_string(f)
110
+ "%.10f" % f
111
+ end
112
+
113
+ def delete_nans_and_truncate_floats_to_strings(a)
114
+ a.delete_if{ |e| e.nan? }.map{ |e| truncate_float_to_string(e) }
115
+ end
116
+
117
+ def ohlc(opens, highs, lows, closes)
118
+ o = []
119
+ opens.each_with_index do |e, i|
120
+ o << [opens[i], highs[i], lows[i], closes[i]]
121
+ end
122
+ o
123
+ end
124
+
125
+ end
metadata CHANGED
@@ -1,73 +1,57 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: quant
3
- version: !ruby/object:Gem::Version
4
- hash: 31
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 0
9
- - 0
10
- version: 0.0.0
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Javier Vidal
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2012-06-13 00:00:00 Z
12
+ date: 2012-06-18 00:00:00.000000000 Z
19
13
  dependencies: []
20
-
21
14
  description: Quantitative Trading
22
- email:
15
+ email:
23
16
  - javier.vidal@bolsanova.com
24
17
  executables: []
25
-
26
18
  extensions: []
27
-
28
19
  extra_rdoc_files: []
29
-
30
- files:
20
+ files:
31
21
  - .gitignore
22
+ - CHANGELOG
32
23
  - Gemfile
33
24
  - LICENSE
34
25
  - README.md
35
26
  - Rakefile
27
+ - lib/enumerable.rb
36
28
  - lib/quant.rb
37
29
  - lib/quant/version.rb
38
30
  - quant.gemspec
39
- homepage: ""
31
+ - test/test_quant.rb
32
+ homepage: ''
40
33
  licenses: []
41
-
42
34
  post_install_message:
43
35
  rdoc_options: []
44
-
45
- require_paths:
36
+ require_paths:
46
37
  - lib
47
- required_ruby_version: !ruby/object:Gem::Requirement
38
+ required_ruby_version: !ruby/object:Gem::Requirement
48
39
  none: false
49
- requirements:
50
- - - ">="
51
- - !ruby/object:Gem::Version
52
- hash: 3
53
- segments:
54
- - 0
55
- version: "0"
56
- required_rubygems_version: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ required_rubygems_version: !ruby/object:Gem::Requirement
57
45
  none: false
58
- requirements:
59
- - - ">="
60
- - !ruby/object:Gem::Version
61
- hash: 3
62
- segments:
63
- - 0
64
- version: "0"
46
+ requirements:
47
+ - - ! '>='
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
65
50
  requirements: []
66
-
67
51
  rubyforge_project:
68
- rubygems_version: 1.7.2
52
+ rubygems_version: 1.8.10
69
53
  signing_key:
70
54
  specification_version: 3
71
55
  summary: Quantitative Trading
72
- test_files: []
73
-
56
+ test_files:
57
+ - test/test_quant.rb