Relative Momentum Trading Strategy: SPY vs GLD

In this post, we’ll explore a momentum-based trading strategy that dynamically selects between SPY and GLD based on relative momentum, moving to cash during adverse market conditions to manage risk effectively. It aims to balance growth potential from equity (SPY) with a defensive position in gold (GLD), providing flexibility in various market conditions.

Strategy Overview

This strategy uses key features to help make allocation decisions:

  • Momentum Comparison: Measures momentum between SPY and GLD using both 60-day and 120-day lookback periods.
  • Risk Management: Moves the portfolio to cash when both assets show negative momentum, minimizing exposure to drawdowns.
  • Flexible Exposure: Allocates between SPY and GLD based on their relative strength, maintaining regular exposure with the potential to move to cash in downturns.

Strategy Rules

  • Calculate Momentum: Determine momentum for both SPY and GLD based on percentage price change over a lookback period.
  • Allocate Based on Momentum:
    • If SPY’s momentum is higher than GLD’s momentum → Allocate to SPY.
    • If GLD’s momentum is higher than SPY’s momentum → Allocate to GLD.
  • Risk-Off Mechanism: If both assets show negative momentum → Move to cash.

By comparing 60-day and 120-day lookback periods, this strategy captures both shorter- and longer-term trends, adapting quickly to market shifts while reducing sensitivity to short-term noise.

Performance Results

60-Day Momentum Strategy

Performance Metrics for 60-Day Momentum Strategy:

120-Day Momentum Strategy

Performance Metrics for 120-Day Momentum Strategy:

Monthly Return Analysis

Monthly Returns Heatmap

Analyzing monthly returns helps identify the most favorable periods for this strategy, shedding light on its resilience and adaptability to varying market conditions.

Key Features of the Strategy

  • Dynamic Asset Allocation: The strategy automatically switches between assets based on their relative strength.
  • Risk Management: The cash position feature helps protect capital during market downturns.
  • Long-term Perspective: Using 60-day and 120-day momentum helps avoid short-term noise.

Implementation Details

The strategy is implemented in Python using the following libraries:

  • yfinance for data acquisition
  • pandas for data manipulation
  • numpy for calculations
  • matplotlib for visualizations

def calculate_momentum(prices, window):
    #Calculate momentum as percentage change over window period
    return (prices / prices.shift(window) - 1).fillna(0)

Conclusion

This strategy demonstrates how combining momentum and risk management can create a robust trading system. The ability to move to cash during adverse conditions helps manage drawdowns, while the selective use of SPY and GLD positions can enhance returns during favorable market conditions.

Leave a Comment