class Enterprice::IO::SignalStream
Attributes
ma_type[R]
window1[R]
window2[R]
Public Class Methods
new(ma_type, window1, window2, stop_loss, block)
click to toggle source
# File lib/enterprice/io/signal_stream.rb, line 10 def initialize(ma_type, window1, window2, stop_loss, block) @avg1= nil @avg2= nil @sma1= MovingAverageStream.new(ma_type, window1, proc { |avg| @avg1= avg }) @sma2= MovingAverageStream.new(ma_type, window2, proc { |avg| @avg2= avg }) @stop_loss= stop_loss @block= block reset end
start(ma_type, window1, window2, stop_loss, &block)
click to toggle source
# File lib/enterprice/io/signal_stream.rb, line 56 def self.start(ma_type, window1, window2, stop_loss, &block) SignalStream.new(ma_type, window1, window2, stop_loss, block) end
Public Instance Methods
<<(value)
click to toggle source
# File lib/enterprice/io/signal_stream.rb, line 20 def <<(value) @sma1<< value @sma2<< value @last_value= value if !@avg1.nil? && !@avg2.nil? @temp_state= :hold if @state== :buy && value< @last_price* @stop_loss @state= :stop_loss @efficiency+= 1.0* (value- @last_price)/ @last_price @last_price= value @temp_state= @state elsif @avg1< @avg2 && !(@state== :buy || @state== :stop_loss) @state= :buy @last_price= value @temp_state= @state elsif @avg1> @avg2 && @state== :buy @state= :sell @temp_state= @state @efficiency+= 1.0* (value- @last_price)/ @last_price end call end end
call()
click to toggle source
# File lib/enterprice/io/signal_stream.rb, line 44 def call @block.call @temp_state, @last_value, @efficiency, @avg1, @avg2 end
reset()
click to toggle source
# File lib/enterprice/io/signal_stream.rb, line 48 def reset @state= :hold @temp_state= :hold @last_value= nil @last_price= nil @efficiency= 0 end