Class: SQA::Strategy::Consensus

Inherits:
Object
  • Object
show all
Extended by:
Common
Defined in:
lib/sqa/strategy/consensus.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Common

desc, trade_against

Constructor Details

#initialize(vector) ⇒ Consensus

Returns a new instance of Consensus.



12
13
14
15
# File 'lib/sqa/strategy/consensus.rb', line 12

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

Class Method Details

.trade(vector) ⇒ Object



8
9
10
# File 'lib/sqa/strategy/consensus.rb', line 8

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

Instance Method Details

#consensusObject



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/sqa/strategy/consensus.rb', line 26

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

#my_fancy_traderObject



17
18
19
20
21
22
23
24
# File 'lib/sqa/strategy/consensus.rb', line 17

def my_fancy_trader
	strat_one
	strat_two
	strat_three
	strat_four
	strat_five
	consensus
end

#strat_fiveObject



42
# File 'lib/sqa/strategy/consensus.rb', line 42

def strat_five 	= @results << :hold

#strat_fourObject



41
# File 'lib/sqa/strategy/consensus.rb', line 41

def strat_four 	= @results << (0==rand(2) ? :buy : :sell)

#strat_oneObject



38
# File 'lib/sqa/strategy/consensus.rb', line 38

def strat_one 	= @results << (0==rand(2) ? :buy : :sell)

#strat_threeObject



40
# File 'lib/sqa/strategy/consensus.rb', line 40

def strat_three = @results << (0==rand(2) ? :buy : :sell)

#strat_twoObject



39
# File 'lib/sqa/strategy/consensus.rb', line 39

def strat_two 	= @results << (0==rand(2) ? :buy : :sell)