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

Momentum-based trading strategies.

This module implements strategies based on momentum indicators such as MACD, RSI, and other oscillators that help identify trend strength and potential reversal points.

Supported Strategies

  • MACD Crossover: MACD line crossing signal line
  • RSI Threshold: RSI oversold/overbought levels
  • RSI Divergence: Price vs RSI divergence detection

Strategy Examples

# Classic MACD crossover
strategy = Quant.Strategy.Momentum.macd_crossover(
  fast_period: 12,
  slow_period: 26,
  signal_period: 9
)

# RSI mean reversion
strategy = Quant.Strategy.Momentum.rsi_threshold(
  period: 14,
  oversold: 30,
  overbought: 70
)

Summary

Functions

Apply the required technical indicators for momentum strategies.

Get the column names that will be created by this strategy.

Create a MACD crossover strategy.

Create an RSI threshold strategy.

Validate that a DataFrame has the required columns for momentum strategies.

Functions

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

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

Apply the required technical indicators for momentum strategies.

Parameters

  • dataframe - Input DataFrame with OHLCV data
  • strategy - Strategy configuration
  • opts - Additional options

Returns

DataFrame with momentum indicators added as new columns.

get_indicator_columns(strategy)

@spec get_indicator_columns(map()) :: [String.t()]

Get the column names that will be created by this strategy.

Examples

iex> strategy = Quant.Strategy.Momentum.macd_crossover()
iex> columns = Quant.Strategy.Momentum.get_indicator_columns(strategy)
iex> "close_macd_12_26" in columns
true

macd_crossover(opts \\ [])

@spec macd_crossover(keyword()) :: map()

Create a MACD crossover strategy.

Generates buy signals when MACD line crosses above signal line and sell signals when MACD line crosses below signal line.

Parameters

  • :fast_period - Fast EMA period (default: 12)
  • :slow_period - Slow EMA period (default: 26)
  • :signal_period - Signal line EMA period (default: 9)
  • :column - Price column to use (default: :close)

Examples

iex> strategy = Quant.Strategy.Momentum.macd_crossover()
iex> strategy.type
:macd_crossover
iex> strategy.fast_period
12

rsi_threshold(opts \\ [])

@spec rsi_threshold(keyword()) :: map()

Create an RSI threshold strategy.

Generates buy signals when RSI drops below oversold threshold and sell signals when RSI rises above overbought threshold.

Parameters

  • :period - RSI calculation period (default: 14)
  • :oversold - Oversold threshold (default: 30)
  • :overbought - Overbought threshold (default: 70)
  • :column - Price column to use (default: :close)

Examples

iex> strategy = Quant.Strategy.Momentum.rsi_threshold(oversold: 25, overbought: 75)
iex> strategy.type
:rsi_threshold
iex> strategy.oversold
25
iex> strategy.overbought
75

validate_dataframe(dataframe, strategy)

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

Validate that a DataFrame has the required columns for momentum strategies.

Parameters

  • dataframe - DataFrame to validate
  • strategy - Strategy configuration

Returns

:ok if valid, {:error, reason} if invalid.