Lesson 6 of 15

Momentum Strategy

Momentum Strategy

Momentum investing is based on the observation that assets that have performed well recently tend to continue performing well in the short term (and vice versa).

Momentum

The momentum at time t with lookback period lb is the return over the lookback window:

momentum[t] = prices[t] / prices[t - lb] - 1

The first lb values are None because there are not enough prior prices.

Momentum Signal

  • +1 if momentum > 0 (upward trend, go long)
  • -1 if momentum < 0 (downward trend, go short)
  • 0 if momentum == 0 or None

Task

Implement:

  • momentum(prices, lookback) — returns the momentum series (first lookback values are None)
  • momentum_signal(prices, lookback) — returns 1, -1, or 0 for each time step
Python runtime loading...
Loading...
Click "Run" to execute your code.