Mean reversion basket

Actually, it's only plausible if you could take a position in the moving average itself as a trading instrument. Then you could buy/sell the primary trading instrument and take an offsetting position in the moving average. Sooner or later, they will converge and you will have your reversion strategy. Of course, this is impossible since you cannot trade the moving average itself.

Buying a stock because it is well below its moving average is an oversold strategy, not a mean-reversion strategy. Oversold means you think it will bounce back, so you take a long position. There is no mean reversion involved. Another trader may look at the same situation and take the opposite view ... that the weakness of the stock is a breakout to the short side.

What the original poster has described is exactly mean reversion. The mean being defined by the moving average and the thesis being that the prices will revert towards there means (MAs). What you describe is betting on mean reversion of a spread. For example, if you believe that SPY is to high relative to IWM, then you might sell SPY and buy IWM. This is betting that a synthetic asset (SPY - IWM) will revert to some mean (could be an MA). This is commonly referred to as pairs trading, and can be considered a sort of naive statistical arbitrage strategy.
 
For a group of M related stocks that I specify, I would like to backtest the strategy of buying at the close, each day, equal dollar amounts of the N stocks that are most oversold, defined as being the most below (on a percentage basis) their P-day moving averages. (For example, I could own the 5 stocks out 50 that are most below their 21-day MA, in which case M = 50, N = 5, and P = 21.)

I would like to be able to test two versions -- on which assumes you can use the closing price to determine the basket, and a more realistic version that uses yesterday's closing price.

What software would you use for this?

Why can't you use today's closing price? Suppose you are using P = 21. Then for a given stock X(t) at closing time t, the MA is defined as,

1/21*(X(t-20)+X(t-20)+...+X(t-1)+X(t))

Now todays closing print X(t) will only be worth 1/21th of the average. Moreover, if X(t) is approximately equal to X(t-e) where e is small (say 5 minutes, so 3:55 EST) then valuing the averages and determining the basket at 3:55 each day is completely feasible and will be almost exactly the value of waiting for the closing prints at 4:00 EST.
 
Quantopian claims they don't look at your code, but what are the odds on that actually being true?
I doubt they don't. If they don't look at your code, why do they care if the algorithm is developed entirely on their platform? But once they know your algorithm, what are the odds you are of any use for them?
 
Last edited:
What the original poster has described is exactly mean reversion. The mean being defined by the moving average and the thesis being that the prices will revert towards there means (MAs). What you describe is betting on mean reversion of a spread. For example, if you believe that SPY is to high relative to IWM, then you might sell SPY and buy IWM. This is betting that a synthetic asset (SPY - IWM) will revert to some mean (could be an MA). This is commonly referred to as pairs trading, and can be considered a sort of naive statistical arbitrage strategy.
If the mean is not stationary, it's not really a mean. The moving average is not stationary, it's a "moving mean". So if you want to refer to it as "moving mean reversion", then I'm with you :)
 
Back
Top