Class: SQA::Strategy::Consensus
- Inherits:
-
Object
- Object
- SQA::Strategy::Consensus
- Extended by:
- Common
- Defined in:
- lib/sqa/strategy/consensus.rb
Class Method Summary collapse
Instance Method Summary collapse
- #consensus ⇒ Object
-
#initialize(vector) ⇒ Consensus
constructor
A new instance of Consensus.
- #my_fancy_trader ⇒ Object
- #strat_five ⇒ Object
- #strat_four ⇒ Object
- #strat_one ⇒ Object
- #strat_three ⇒ Object
- #strat_two ⇒ Object
Methods included from Common
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
#consensus ⇒ Object
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_trader ⇒ Object
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_five ⇒ Object
42 |
# File 'lib/sqa/strategy/consensus.rb', line 42 def strat_five = @results << :hold |
#strat_four ⇒ Object
41 |
# File 'lib/sqa/strategy/consensus.rb', line 41 def strat_four = @results << (0==rand(2) ? :buy : :sell) |
#strat_one ⇒ Object
38 |
# File 'lib/sqa/strategy/consensus.rb', line 38 def strat_one = @results << (0==rand(2) ? :buy : :sell) |
#strat_three ⇒ Object
40 |
# File 'lib/sqa/strategy/consensus.rb', line 40 def strat_three = @results << (0==rand(2) ? :buy : :sell) |
#strat_two ⇒ Object
39 |
# File 'lib/sqa/strategy/consensus.rb', line 39 def strat_two = @results << (0==rand(2) ? :buy : :sell) |