Testing a Moving Average Strategy with Realistic Trading Assumptions
Summary
The document outlines a simple moving average rule that buys when price is below its average and sells when it is above, then asks how to evaluate its apparent returns against a rising equity market. Its practical guidance is to use a tradable instrument rather than an index, execute after the signal becomes observable, and account for transaction costs, financing, market impact, and slippage.
The discussion identifies benchmark choice and timing as central to a credible backtest. Comparing with buy and hold can help distinguish strategy performance from broad market growth, while trading at the next session’s open helps avoid look-ahead bias from using closing prices that were not yet available at decision time. The source gives general recommendations rather than an empirical comparison or a worked backtest. It does not specify sizing rules, parameter selection, or how to estimate costs, so those choices would need further research before treating results as evidence of live performance.
Key ideas
- Use a tradable asset to test a strategy that signals on an index.
- Compare strategy returns with an appropriate buy-and-hold benchmark.
- Trade after the signal is observable to reduce look-ahead bias.
- Include transaction, financing, market-impact, and slippage costs.
- The document offers implementation considerations but no measured strategy results.
Tags
Full text
# Workflow in algorithmic strategies
# Workflow in algorithmic strategies
Sorry for the basic question, I'm trying to educate myself on algorithmic strategies.
Just to see how it works, my idea is to create a simple moving average strategy.
Let us suppose I have $N$ observations of the price of an asset $P_t$
I define the simple moving average of $P_t$ at time $t$
$$\text{SMA}_t^{(n)} = {1\over n}\sum_{k=t-n+1}^t P_k~,$$ where $n$ is the number of prices included in the average.
Now the trading signals are generated by these two trading rules:
- $\text{BUY}_t$ when $P_t < \text{SMA}_t^{(n)}$
- $\text{SELL}_t$ when $P_t > \text{SMA}_t^{(n)}$
Every time I have a signal I buy/sell everything I can/have, in other words I maximize the volume of my operations.
My question is how to test this strategy? I tried with the $SP500$ index and I found very good results in terms of $\%$ returns, but I think my approach is misleading since I should compare it with a buy and hold strategy, considered that this index has only grown in the period that I considered...I also read that simple moving average is good when the market is mean-reverting, and this makes sense to me... What are more appropriate way to test it with real-world data? Also, can you suggest the next steps to make it more realistic?
Thanks in advance
## Answer by user42108 (score 4, accepted)
https://quant.stackexchange.com/a/69258
"What are more appropriate way to test it with real-world data? Also, can you suggest the next steps to make it more realistic?"
Pick a tradable instrument (e.g. SPY rather than S&P500), eliminate look-ahead bias (e.g. trade at the next day's open rather than the close), take into account transaction costs and financing costs, estimate market impact/slippage...I'd guess there are some blog posts and books aimed at retail traders that cover these basic ideas, e.g. from Rob Carver [EDIT: I think Ernie Chan's books might also be of use/interest to you. I have no affiliation with either Carver or Chan]Shown in full with attribution under the source's licence. Licence: CC BY-SA 4.0 (Stack Exchange)
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.