📦 SQA::Ensemble¶
Description
Ensemble - Combine multiple trading strategies
Provides methods for: - Majority voting - Weighted voting based on past performance - Meta-learning (strategy selection) - Strategy rotation based on market conditions - Confidence-based aggregation
🏭 Class Methods¶
.trade(vector)¶
Make ensemble compatible with Backtest (acts like a strategy)
Parameters
| Name | Type | Description |
|---|---|---|
vector |
OpenStruct |
Market data |
Returns
Type: Symbol
Trading signal
Source Location
🔨 Instance Methods¶
#strategies()¶
Returns the value of attribute strategies.
Source Location
#strategies=(value)¶
Sets the attribute strategies
Parameters
| Name | Type | Description |
|---|---|---|
value |
Any |
the value to set the attribute strategies to. |
Source Location
#weights()¶
Returns the value of attribute weights.
Source Location
#weights=(value)¶
Sets the attribute weights
Parameters
| Name | Type | Description |
|---|---|---|
value |
Any |
the value to set the attribute weights to. |
Source Location
#performance_history()¶
Returns the value of attribute performance_history.
Source Location
#performance_history=(value)¶
Sets the attribute performance_history
Parameters
| Name | Type | Description |
|---|---|---|
value |
Any |
the value to set the attribute performance_history to. |
Source Location
#initialize(strategies:, voting_method: = :majority, weights: = nil)¶
Initialize ensemble
Parameters
| Name | Type | Description |
|---|---|---|
strategies |
Array<Class> |
Array of strategy classes |
voting_method |
Symbol |
:majority, :weighted, :unanimous, :confidence |
weights |
Array<Float> |
Optional weights for weighted voting |
Returns
Type: Ensemble
a new instance of Ensemble
Source Location
#signal(vector)¶
Generate ensemble signal
Parameters
| Name | Type | Description |
|---|---|---|
vector |
OpenStruct |
Market data vector |
Returns
Type: Symbol
:buy, :sell, or :hold
Source Location
#majority_vote(vector)¶
Majority voting
Parameters
| Name | Type | Description |
|---|---|---|
vector |
OpenStruct |
Market data |
Returns
Type: Symbol
Signal with most votes
Source Location
#weighted_vote(vector)¶
Weighted voting based on strategy performance
Parameters
| Name | Type | Description |
|---|---|---|
vector |
OpenStruct |
Market data |
Returns
Type: Symbol
Weighted signal
Source Location
#unanimous_vote(vector)¶
Unanimous voting (all strategies must agree)
Parameters
| Name | Type | Description |
|---|---|---|
vector |
OpenStruct |
Market data |
Returns
Type: Symbol
:buy/:sell only if unanimous, otherwise :hold
Source Location
#confidence_vote(vector)¶
Confidence-based voting
Weight votes by strategy confidence scores.
Parameters
| Name | Type | Description |
|---|---|---|
vector |
OpenStruct |
Market data |
Returns
Type: Symbol
Signal weighted by confidence
Source Location
#update_weight(strategy_index, performance)¶
Update strategy weights based on performance
Adjust weights to favor better-performing strategies.
Parameters
| Name | Type | Description |
|---|---|---|
strategy_index |
Integer |
Index of strategy |
performance |
Float |
Performance metric (e.g., return) |
Source Location
#update_confidence(strategy_class, correct)¶
Update confidence score for strategy
Parameters
| Name | Type | Description |
|---|---|---|
strategy_class |
Class |
Strategy class |
correct |
Boolean |
Was the prediction correct? |
Source Location
#select_strategy(market_regime:, volatility: = :medium)¶
Select best strategy for current market conditions
Meta-learning approach: choose the strategy most likely to succeed.
Parameters
| Name | Type | Description |
|---|---|---|
market_regime |
Symbol |
Current market regime (:bull, :bear, :sideways) |
volatility |
Symbol |
Volatility regime (:low, :medium, :high) |
Returns
Type: Class
Best strategy class for conditions
Source Location
#rotate(stock)¶
Rotate strategies based on market conditions
Parameters
| Name | Type | Description |
|---|---|---|
stock |
SQA::Stock |
Stock object |
Returns
Type: Class
Strategy to use
Source Location
#statistics()¶
Get ensemble statistics
Returns
Type: Hash
Performance statistics
Source Location
#backtest_comparison(stock, initial_capital: = 10_000)¶
Backtest ensemble vs individual strategies
Parameters
| Name | Type | Description |
|---|---|---|
stock |
SQA::Stock |
Stock to backtest |
initial_capital |
Float |
Starting capital |
Returns
Type: Hash
Comparison results
Source Location
#trade(vector)¶
Instance method for compatibility
Source Location
📝 Attributes¶
🔄 strategies read/write¶
Returns the value of attribute strategies.
🔄 weights read/write¶
Returns the value of attribute weights.
🔄 performance_history read/write¶
Returns the value of attribute performance_history.