class Enterprice::IO::MovingAverageStream
Attributes
type[R]
window[R]
Public Class Methods
new(type, window, block)
click to toggle source
# File lib/enterprice/io/moving_average_stream.rb, line 9 def initialize(type, window, block) supported= %i(sma wma ema dema tema kama) if !supported.include?(type) raise "Error: unsupported smoothing method: #{type}, supported methods are: #{supported}" end @type= type @window= window @length= case type when :kama then window+ 1 when :dema then window* 2 when :tema then window* 3 else window end @block= block @data= [] end
start(type, window, &block)
click to toggle source
# File lib/enterprice/io/moving_average_stream.rb, line 37 def self.start(type, window, &block) MovingAverageStream.new(type, window, block) end
Public Instance Methods
<<(value)
click to toggle source
# File lib/enterprice/io/moving_average_stream.rb, line 26 def <<(value) @data<< value return if @data.length< @length @data.shift if @data.length> @length call end
call()
click to toggle source
# File lib/enterprice/io/moving_average_stream.rb, line 33 def call @block.call @data.indicator(@type, @window)[0] end