WU Trading Library 0.2.0
A backtesting and trading strategy library
Loading...
Searching...
No Matches
WU_PairsTradingStrat Struct Reference

WU_PairsTradingStrat implements a classic pairs trading strategy that trades the spread between two correlated assets (statistical arbitrage). More...

#include <strategies.h>

Data Fields

struct WU_Strategy_ base
WU_SMA spread_ma
WU_MStDev spread_std
double threshold
double ratio
WU_Side last_signal

Detailed Description

WU_PairsTradingStrat implements a classic pairs trading strategy that trades the spread between two correlated assets (statistical arbitrage).

Strategy Logic:

  • Calculates the spread: spread = asset_a - (ratio * asset_b)
  • Tracks the mean and standard deviation of the spread using a rolling window
  • Generates BUY signal when spread falls below (mean - threshold * stdev) → Asset A is undervalued relative to Asset B, so buy A and sell B
  • Generates SELL signal when spread rises above (mean + threshold * stdev) → Asset A is overvalued relative to Asset B, so sell A and buy B
  • Generates CLOSE signal when spread returns to mean (exit position)

Typical use cases:

  • Coca-Cola (KO) vs PepsiCo (PEP)
  • ExxonMobil (XOM) vs Chevron (CVX)
  • Gold (GLD) vs Gold Miners (GDX)

Parameters:

  • window: lookback period for calculating spread statistics
  • threshold: number of standard deviations for entry signals (typically 1.5-2.5)
  • ratio: hedge ratio between the two assets (typically 1.0 or calculated via regression)

Definition at line 79 of file strategies.h.

Field Documentation

◆ base

struct WU_Strategy_ WU_PairsTradingStrat::base

Definition at line 80 of file strategies.h.

◆ last_signal

WU_Side WU_PairsTradingStrat::last_signal

Definition at line 85 of file strategies.h.

◆ ratio

double WU_PairsTradingStrat::ratio

Definition at line 84 of file strategies.h.

◆ spread_ma

WU_SMA WU_PairsTradingStrat::spread_ma

Definition at line 81 of file strategies.h.

◆ spread_std

WU_MStDev WU_PairsTradingStrat::spread_std

Definition at line 82 of file strategies.h.

◆ threshold

double WU_PairsTradingStrat::threshold

Definition at line 83 of file strategies.h.


The documentation for this struct was generated from the following file: