Quant.Strategy.Composite (quant v0.1.0-alpha.1)

Composite strategy implementation for combining multiple strategies.

This module allows combining multiple individual strategies using various logical operators to create more sophisticated trading systems.

Combination Logic

  • :all (AND) - All strategies must agree for signal generation
  • :any (OR) - Any strategy can trigger a signal
  • :majority - Majority of strategies must agree
  • :weighted - Weighted combination based on strategy confidence

Examples

# Combine SMA crossover with RSI confirmation
strategies = [
  Quant.Strategy.sma_crossover(fast_period: 12, slow_period: 26),
  Quant.Strategy.rsi_threshold(oversold: 30, overbought: 70)
]

composite = Quant.Strategy.Composite.create(strategies, logic: :all)

Summary

Functions

Apply indicators for all sub-strategies in the composite.

Combine multiple signal DataFrames using specified logic.

Create a composite strategy from multiple individual strategies.

Generate signals for a composite strategy.

Types

combination_logic()

@type combination_logic() :: :all | :any | :majority | :weighted

strategy_weight()

@type strategy_weight() :: {map(), float()}

Functions

apply_indicators(dataframe, strategy, opts \\ [])

@spec apply_indicators(Explorer.DataFrame.t(), map(), keyword()) ::
  {:ok, Explorer.DataFrame.t()} | {:error, term()}

Apply indicators for all sub-strategies in the composite.

Parameters

  • dataframe - Input DataFrame
  • strategy - Composite strategy configuration
  • opts - Additional options

Returns

DataFrame with all required indicators for sub-strategies applied.

combine(signals_list, opts \\ [])

@spec combine(
  [Explorer.DataFrame.t()],
  keyword()
) :: Explorer.DataFrame.t()

Combine multiple signal DataFrames using specified logic.

Parameters

  • signals_list - List of DataFrames with signals
  • opts - Combination options

Options

  • :logic - Combination logic
  • :weights - Strategy weights
  • :columns - Which signal columns to combine

create(strategies, opts \\ [])

@spec create(
  [map()],
  keyword()
) :: map()

Create a composite strategy from multiple individual strategies.

Parameters

  • strategies - List of individual strategy configurations
  • opts - Composite strategy options

Options

  • :logic - Combination logic (:all, :any, :majority, :weighted)
  • :weights - Strategy weights for weighted combination (list of floats)
  • :threshold - Minimum confidence threshold for signal generation
  • :name - Name for the composite strategy

Examples

iex> strategies = [
...>   Quant.Strategy.sma_crossover(fast_period: 12, slow_period: 26),
...>   Quant.Strategy.rsi_threshold(oversold: 30, overbought: 70)
...> ]
iex> composite = Quant.Strategy.Composite.create(strategies, logic: :all)
iex> composite.type
:composite
iex> length(composite.strategies)
2

generate_signals(dataframe, strategy, opts \\ [])

@spec generate_signals(Explorer.DataFrame.t(), map(), keyword()) ::
  {:ok, Explorer.DataFrame.t()} | {:error, term()}

Generate signals for a composite strategy.

This function generates signals for each sub-strategy and then combines them according to the specified combination logic.

Parameters

  • dataframe - DataFrame with all required indicators
  • strategy - Composite strategy configuration
  • opts - Signal generation options

Returns

DataFrame with combined signals.