Sha256: 0ac5a193fb5cb7bd7f3b8e60c75f3e70a3c3ed2939e3a1eecaa286d649030af1

Contents?: true

Size: 820 Bytes

Versions: 19

Compression:

Stored size: 820 Bytes

Contents

# lib/sqa/strategry/consensus.rb

require_relative 'common'

class SQA::Strategy::Consensus
	extend SQA::Strategy::Common

	def self.trade(vector)
		new(vector).my_fancy_trader
	end

	def initialize(vector)
		@vector 	= vector
		@results 	= []
	end

	def my_fancy_trader
		strat_one
		strat_two
		strat_three
		strat_four
		strat_five
		consensus
	end

	def consensus
		count = @results.group_by(&:itself).transform_values(&:count)

		if count[:buy] > count[:sell]
			:buy
		elsif count[:sell] > count[:buy]
			:sell
		else
			:hold
		end
	end

	def strat_one 	= @results << (0==rand(2) ? :buy : :sell)
	def strat_two 	= @results << (0==rand(2) ? :buy : :sell)
	def strat_three = @results << (0==rand(2) ? :buy : :sell)
	def strat_four 	= @results << (0==rand(2) ? :buy : :sell)
	def strat_five 	= @results << :hold
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
sqa-0.0.24 lib/sqa/strategy/consensus.rb
sqa-0.0.22 lib/sqa/strategy/consensus.rb
sqa-0.0.21 lib/sqa/strategy/consensus.rb
sqa-0.0.20 lib/sqa/strategy/consensus.rb
sqa-0.0.19 lib/sqa/strategy/consensus.rb
sqa-0.0.18 lib/sqa/strategy/consensus.rb
sqa-0.0.17 lib/sqa/strategy/consensus.rb
sqa-0.0.15 lib/sqa/strategy/consensus.rb
sqa-0.0.14 lib/sqa/strategy/consensus.rb
sqa-0.0.13 lib/sqa/strategy/consensus.rb
sqa-0.0.12 lib/sqa/strategy/consensus.rb
sqa-0.0.11 lib/sqa/strategy/consensus.rb
sqa-0.0.10 lib/sqa/strategy/consensus.rb
sqa-0.0.9 lib/sqa/strategy/consensus.rb
sqa-0.0.8 lib/sqa/strategy/consensus.rb
sqa-0.0.7 lib/sqa/strategy/consensus.rb
sqa-0.0.6 lib/sqa/strategy/consensus.rb
sqa-0.0.5 lib/sqa/strategy/consensus.rb
sqa-0.0.4 lib/sqa/strategy/consensus.rb