Mean reversion basket

This is the strategy logic in *backtrader* to do it. There aren't many requirements in the original post (for example there is no exit criterion), so the assumption is that there is an unlimited supply of cash, which can be added to the broker for the new acquisitions.


Thanks for your reply and for the backtrader project. I should have written that the strategy is to own the N most oversold stocks each day. Then the exit criterion is to sell the stock when it is no longer one of those N most oversold.
 
Quantopian claims they don't look at your code, but what are the odds on that actually being true?
Meh. So what if they do? There's nothing new under the sun.

I read an article in SeekingAlpha that gets my interest, code it up, backtest and find it interesting. All it does for me is simplify executing a system. No magical secrets involved.
 
Meh. So what if they do? There's nothing new under the sun.

I disagree. And obviously it's not true that there is nothing new or else they wouldn't be paying random people from the internet to use their trading strategies. They would just use all the already known strategies.
 
Last edited:
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?

Hmm...moving averages are momentum signal, not mean reversion. Check out this website, this website and this website for ideas.
 
... buying/selling a stock when it is below/above a moving average is a plausible mean-reversion strategy ... The question is whether it will work.
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.
 
A practical definition of mean-reversion : Trading in the direction toward a mean. That mean is relative though, since it may depend on conditions like the timeframe and period/method used to calculate it.

So two traders trading mean-reversion could actually be in opposite directions of one another, even take the opposite side of the other's trade!
 
Back
Top