Free lesson · Trading algorithms
Moving averages, EWMA and momentum/reversion rules
Open interactive lessonPractice calculationsExplore labs
Start with the idea
A moving average is a filter: it summarises recent observations. A trading rule adds a hypothesis about what deviations from that summary mean. The same filter can support trend following, mean reversion or risk estimation.
Symbols, units & horizon
- m_t: smoothed value in the input’s units
- x_t: newest available observation
- α: update weight with 0<α<1
- 1−α: retained weight per step
- h_1/2: observation-weight half-life in steps
- ln: natural logarithm
- Initial m: explicitly chosen training/warmup state
When and why to use this
Use EWMA as an inexpensive causal baseline for level, trend, volatility or flow features before fitting a complex state model.
A simple moving average gives equal weight to a fixed window. EWMA gradually reduces the influence of older observations and updates with constant memory. A fast-minus-slow average is a trend feature; price minus an average is a displacement feature. Neither dictates whether to follow or fade the move without an economic and empirical hypothesis.
EWMA is useful when recent information deserves more weight and computation must be cheap. It reacts gradually, so it lags abrupt changes and can whipsaw in noisy ranges. Choose its memory relative to the holding horizon and compare turnover across settings using chronological validation.
Applied to squared innovations, exponential smoothing becomes a volatility-state update. Applied to order flow, it becomes a flow-pressure feature. Keep input units explicit: averaging returns, prices and squared returns produces different objects.
Moving averages, EWMA and momentum/reversion rules
- Give the old summary weight 1−α and the new observation weight α; the weights sum to one.
- Expanding the recursion shows that an old observation’s influence decays by a factor 1−α each step.
- Set (1−α)^h=.5 and take logs to derive the half-life. This is the filter’s memory half-life, not a spread’s economic reversion half-life.
Old average 100, new value 104 and α=.25 give 101. The observation-weight half-life is ln(.5)/ln(.75)≈2.409 steps.
Apply it in a strategy
- Choose input units and a decision horizon, then specify warmup and update timing.
- Compare EWMA with a fixed-window average and a no-signal baseline.
- Evaluate both prediction quality and trading turnover; do not select the lookback from final-test performance.
Research deliverable
State whether the filter estimates a level, risk or direction, and compare its lag and turnover across a small prespecified memory range.
How the same weighting idea appears in probability and state inference →
Research sources, review dates and limitations
Python implementation
Self-contained teaching example. Python 3.10+; dependencies and input conventions are shown in the code and notation. Run in your own Python environment.
from math import log
def ewma_step(previous,observation,alpha):
if not 0<alpha<1: raise ValueError("Use 0<alpha<1")
return (1-alpha)*previous+alpha*observation,log(.5)/log(1-alpha)
print(ewma_step(100,104,.25))Continue learning
Trading Algorithms: A Practical Selection Guide — all lessons- Moving averages, EWMA and momentum/reversion rules
- Kalman filtering: combine a prediction with a noisy observation
- ARIMA for conditional means and GARCH for conditional variance
- Linear models, random forests and gradient boosting
- PCA, clustering, risk parity and quadratic programming
- TWAP, VWAP and percentage-of-volume execution
- Optimal execution: impact versus waiting risk
Quantitative finance and development glossary · Python resources and libraries · Research sources and limitations