Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Mean-Reversion Long - For Bold Contrarians

Simple mean reversion long only algorithm. Got the rules from a book by Laurens Bensdorp.

Objective
- Trade stocks that are in a long-term uptrend, that have significantly volatility and are oversold on the short term.
- Execute trades every day.
- Beat the overall market in both bull and sideways markets.

Trading universe
- All stocks from AMEX, NASDAQ, and NYSE.
- Do not trade ETFs, pink sheets or bulletin board stocks.

Filters
- Minimum Average Volume of the last 50 days is above 500.000 shares (ensure liquidity).
- Minimum price is 1 USD.
- Dollar volume is at least 2.500.000 USD (ensure worth trading).

Position Sizing:
- Maximum 10 positions.
- Fixed fractional risk: 2 percent.
- Maximum position size: 10 percent.

Buys
1. Trade every day.
2. Close of the stock is above the 150-daily SMA (long term uptrend).
3. Seven day average directional index (ADX) is above 45 (short term trend strength.
4. Average true range percent of the last 10 days is above 4 percent (volatility).
5. The three day RSI is below 30 (oversold on a short term basis).
6. Rank orders by the lowest three day RSI.

Sells:
1. Trade every day.
2. Sell when one of the following conditions is met:
2.1 Stop Loss: 2.5 times the ten-day ATR.
2.2 Profit Target: 3 percent or more.
2.3 Time Exit: 4 days have passed and none of the above conditions is met.

Notes:
- The algorithm tracks the available cash trying to avoid spending more than we have.
- The rebalance is split in 2 functions with an hour gap. This is just to "ensure" sell orders are filled before we start buying.
- Sometimes 2.5 times the ATR is higher than the stock price, in those cases we don’t place the stop loss.
- The book tries to buy more fear by placing the buy orders at 4 percent less than the previous day closing price.
- The only purpose of canceling open orders at the end of the trading day is to avoid the console warnings.
- The backtests shown in the book are better. That could be because the entry and exit rules are a bit different. However it does beat the S&P 500.

Other algorithms:
- Weekly Rotation S&P 500
- Mean-Reversion Short - Money in bad markets

1 response

There was an error when selling at profit. I was using a limit order, this means it could get filled at less than the desired price. In the new version total return is slightly higher (+5%) but the drawdown is around 25% worse.