enterprice 0.1.4 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 43c7b1f57198bb9225cbaa672efcf889836c0750
4
- data.tar.gz: 292c225992f98ce2d0db60d51e3d547cca233d51
3
+ metadata.gz: a0a360b0c52d87288ae484ea5a8f01720476b5fc
4
+ data.tar.gz: e50d82ef862c7104de41b951922521cf3e67cb84
5
5
  SHA512:
6
- metadata.gz: 948dc92776d3eb807deacfd92642e7c85e879989b11724f2dec5f7462638292fa6b88c7186cf77c7611025d4c236f8d195217acc3a81c0b534b680827b99af8a
7
- data.tar.gz: 1d9267fb1bf616098612ce583fde68d13339c4da1f6c19c55da5172e556488061a6b84b6fd0cac5e4a7e83c2d4074a41daeddbc0104986fd470d9590e160c3d0
6
+ metadata.gz: 56026611241616e9fb0d09ab6b088544599598d9e8a70c696dcf8dad67c0f6fe27926f00975095b26705b382262af5bda29a05c51f3c517327c5838336b2ac76
7
+ data.tar.gz: 58b4e775151f475ab980d8b34b530acdf0c5dd2d35d6a312825c4b013e1c540b002cf26a8390e9e6fd617f2178f82358d567c4c7c2f5739fb3777418cb4416d5
@@ -1,4 +1,6 @@
1
- require "enterprice/io/candle_stream"
2
- require "enterprice/io/named_candle_stream"
3
- require "enterprice/io/multi_candle_stream"
1
+ require 'enterprice/io/candle_stream'
2
+ require 'enterprice/io/named_candle_stream'
3
+ require 'enterprice/io/multi_candle_stream'
4
+ require 'enterprice/io/moving_average_stream'
5
+ require 'enterprice/io/signal_stream'
4
6
 
@@ -0,0 +1,43 @@
1
+ require 'indicator/mixin'
2
+
3
+ module Enterprice; module IO
4
+
5
+ class MovingAverageStream
6
+ attr_reader :window
7
+ attr_reader :type
8
+
9
+ def initialize(type, window, block)
10
+ supported= %i(sma wma ema dema tema kama)
11
+ if !supported.include?(type)
12
+ raise "Error: unsupported smoothing method: #{type}, supported methods are: #{supported}"
13
+ end
14
+ @type= type
15
+ @window= window
16
+ @length= case type
17
+ when :kama then window+ 1
18
+ when :dema then window* 2
19
+ when :tema then window* 3
20
+ else window
21
+ end
22
+ @block= block
23
+ @data= []
24
+ end
25
+
26
+ def <<(value)
27
+ @data<< value
28
+ return if @data.length< @length
29
+ @data.shift if @data.length> @length
30
+ call
31
+ end
32
+
33
+ def call
34
+ @block.call @data.indicator(@type, @window)[0]
35
+ end
36
+
37
+ def self.start(type, window, &block)
38
+ MovingAverageStream.new(type, window, block)
39
+ end
40
+ end
41
+
42
+ end; end # Enterprice.IO
43
+
@@ -0,0 +1,62 @@
1
+ require_relative './moving_average_stream'
2
+
3
+ module Enterprice; module IO
4
+
5
+ class SignalStream
6
+ attr_reader :ma_type
7
+ attr_reader :window1
8
+ attr_reader :window2
9
+
10
+ def initialize(ma_type, window1, window2, stop_loss, block)
11
+ @avg1= nil
12
+ @avg2= nil
13
+ @sma1= MovingAverageStream.new(ma_type, window1, proc { |avg| @avg1= avg })
14
+ @sma2= MovingAverageStream.new(ma_type, window2, proc { |avg| @avg2= avg })
15
+ @stop_loss= stop_loss
16
+ @block= block
17
+ reset
18
+ end
19
+
20
+ def <<(value)
21
+ @sma1<< value
22
+ @sma2<< value
23
+ @last_value= value
24
+ if !@avg1.nil? && !@avg2.nil?
25
+ @temp_state= :hold
26
+ if @state== :buy && value< @last_price* @stop_loss
27
+ @state= :stop_loss
28
+ @efficiency+= 1.0* (value- @last_price)/ @last_price
29
+ @last_price= value
30
+ @temp_state= @state
31
+ elsif @avg1< @avg2 && !(@state== :buy || @state== :stop_loss)
32
+ @state= :buy
33
+ @last_price= value
34
+ @temp_state= @state
35
+ elsif @avg1> @avg2 && @state== :buy
36
+ @state= :sell
37
+ @temp_state= @state
38
+ @efficiency+= 1.0* (value- @last_price)/ @last_price
39
+ end
40
+ call
41
+ end
42
+ end
43
+
44
+ def call
45
+ @block.call @temp_state, @last_value, @efficiency, @avg1, @avg2
46
+ end
47
+
48
+ def reset
49
+ @state= :hold
50
+ @temp_state= :hold
51
+ @last_value= nil
52
+ @last_price= nil
53
+ @efficiency= 0
54
+ end
55
+
56
+ def self.start(ma_type, window1, window2, stop_loss, &block)
57
+ SignalStream.new(ma_type, window1, window2, stop_loss, block)
58
+ end
59
+ end
60
+
61
+ end; end # Enterprice.IO
62
+
@@ -1,3 +1,3 @@
1
1
  module Enterprice
2
- VERSION= "0.1.4"
2
+ VERSION= "0.2.4"
3
3
  end
metadata CHANGED
@@ -1,15 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: enterprice
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nurettin Onur TUĞCU
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-09 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2014-04-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: minitest
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: ta-indicator
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
13
41
  description: This gem provides utilities and methods I use when inspecting time series
14
42
  on remote machines.
15
43
  email: onur.tugcu@gmail.com
@@ -19,9 +47,10 @@ extra_rdoc_files: []
19
47
  files:
20
48
  - lib/enterprice.rb
21
49
  - lib/enterprice/io/candle_stream.rb
50
+ - lib/enterprice/io/moving_average_stream.rb
22
51
  - lib/enterprice/io/multi_candle_stream.rb
23
52
  - lib/enterprice/io/named_candle_stream.rb
24
- - lib/enterprice/version.rb
53
+ - lib/enterprice/io/signal_stream.rb
25
54
  - lib/version.rb
26
55
  homepage: https://github.com/nurettin/enterprice
27
56
  licenses:
@@ -1,4 +0,0 @@
1
- module Enterprice
2
- VERSION= '0.0.1'
3
- end
4
-