Measure trend from past closes only, such as the return over the last 12 months or price above a long average, hold long while it is positive and exit when it turns, and size each position by its recent volatility. Test across many years and several markets, because trend following earns most of its return in a few large moves.
Two kinds of momentum
- Time-series momentum compares an asset with its own past: hold it when its return over a lookback period is positive. Moskowitz, Ooi and Pedersen documented this across futures markets in 2012. Managed-futures funds are built on it.
- Cross-sectional momentum compares assets with each other: hold the ones with the best recent returns and avoid the worst. Jegadeesh and Titman's 1993 study of US stocks is the classic reference. It is a ranking problem, covered in the portfolio backtest guide.
This page covers the time-series kind on one market.
Common signals
- The return over the last N bars is positive (12 months is common on daily data, often skipping the latest month).
- Price is above its N-bar moving average.
- A moving average crossover or a Donchian breakout.
Sizing by volatility
Trend followers usually size each position so that every market contributes similar risk: qty = risk budget / (volatility × price). A quiet market gets a larger position, a volatile one a smaller one. Without this, a portfolio's result is dominated by whichever market happens to move most. See position sizing.
What to watch for
- Short histories. A few years can be all trendless or all trending. Use as long a history as you have.
- Low win rate. Trend following often loses on more than half its trades and makes it up on a few large ones. A drawdown lasting a year or more is normal.
- Rebalancing costs. Resizing on every bar adds costs; resize when the signal changes or on a schedule.
How Reamer Research handles it
In Reamer Research the signal and the sizing fit in one class:
import numpy as np
import reamer_research as rr
class Momentum:
lookback = 120
capital, risk = 10_000, 0.01
def on_bar(self, d):
c = d.close
if c[0] == 0:
return None
trend_up = c[-1] > c[0] and c[-1] > c[-60:].mean()
if trend_up and d.position() == 0:
vol = np.diff(np.log(c[-60:])).std() # per-bar volatility
qty = int(min(self.capital * self.risk / (vol * c[-1]), 0.95 * self.capital / c[-1]))
return rr.buy_market(qty) if qty > 0 else None
if not trend_up and d.position() > 0:
return rr.close_position()
result = rr.backtest(Momentum, 'data/SPY.bin', spread=0.01, commission_per_unit=0.005)
print(result.win_rate, result.profit_factor, result.equity_drawdown_relative)
The sizing is capped below the account's buying power, because the engine rejects an order that would take open notional past equity times leverage, as a margin account would. The same rule runs as a function on_bar(data) or as an object configured with the lookback and risk. Several markets run in one backtest against one account by passing a dictionary of tickers, and result.monte_carlo() reshuffles the trade sequence to show how deep the drawdowns could have been in another order.
Limits to know
- Futures need rolls. A continuous futures series needs roll handling, which
roll_cycle_monthsprovides; see futures rolls and FX swap. - Several markets and long histories need a licence. Evaluation Mode runs one ticker over 30 days or 50,000 bars.
A $20 month includes the full kit, so you can run trend following across your own markets and cancel if it does not fit.