Simple mean reversion short only algorithm. In bear markets it beats the S&P 500 (first attached backtest) but in longer periods it performs worse. In sideways markets I was expecting the performance to be worse but not that much so there might be an error somewhere or I don't properly understand how shorting works in Quantopian.
Details of the algorithm:
Objective
- Trade short only on a large universe of stocks, taking advantage of overbought conditions by short selling the best stocks, and buying each back when it reverts to its mean.
- Execute trades every day.
- Beat the benchmarks, especially in bear 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 20 days is above 500.000 shares (ensure liquidity).
- Minimum price is 10 USD.
Position Sizing:
- Maximum 10 positions.
- Fixed fractional risk: 2 percent.
- Maximum position size: 10 percent.
Buys
1. Trade every day.
3. Seven day average directional index (ADX) is above 50 (short term trend strength).
4. Average true range percent of the last 10 days is above 5 percent (volatility).
5. The three day RSI is above 85 (overbought on a short term basis).
6. Rank orders by the highest three day RSI.
Sells:
1. Trade every day.
2. Sell when one of the following conditions is met:
2.1 Stop Loss: 1.5 times the ten-day ATR.
2.2 Profit Target: 4 percent or more.
2.3 Time Exit: 2 days have passed and none of the above conditions is met.
Notes:
- The rebalance is split in 2 functions with an hour gap. This is just to "ensure" sell orders are filled before we start buying.
- The only purpose of canceling open orders at the end of the trading day is to avoid the console warnings.
Other algorithms:
- Weekly Rotation S&P 500
- Mean-Reversion Long - For Bold Contrarians