Skip to content

Ensemble Strategies

Combine multiple strategies with voting and meta-learning.

Basic Ensemble

ensemble = SQA::Ensemble.new(
  strategies: [
    SQA::Strategy::RSI,
    SQA::Strategy::MACD,
    SQA::Strategy::BollingerBands
  ],
  voting_method: :majority
)

signal = ensemble.signal(vector)  # => :buy, :sell, or :hold

Voting Methods

Majority Voting

voting_method: :majority  # Most common signal wins

Weighted Voting

voting_method: :weighted
# Weight strategies by past performance

Unanimous

voting_method: :unanimous  # All must agree

Confidence-Based

voting_method: :confidence  # Weight by confidence scores

Dynamic Weighting

# Update weights based on performance
ensemble.update_weight(SQA::Strategy::RSI, 1.5)   # Increase weight
ensemble.update_weight(SQA::Strategy::MACD, 0.5)  # Decrease weight

Strategy Rotation

# Select best strategy for current market
selected = ensemble.rotate(stock)
# Automatically switches based on recent performance

Backtest Comparison

comparison = ensemble.backtest_comparison(stock)

comparison.each do |name, results|
  puts "#{name}: Return = #{results[:return]}%"
end