This is a corrected version of the strategy I posted earlier (https://www.quantopian.com/posts/statistical-arbitrage-based-on-divergence).
Also, I have changed the entry and exit rules. The aim is to create a beta neutral position when divergence is observed.
For back-testing, I have used 6 IT stocks from S&P 500 companies, namely
- Apple Inc. (AAPL)
- Microsoft Corporation (MSFT)
- Amazon.com Inc. (AMZN)
- Alphabet Inc. Class A (GOOGL)
- Accenture (ACN)
- Adobe (ADBE)
Following are the steps for the strategy:
Calculations required
Every day, at market open, I calculate the historical volatility of the stocks as well as the benchmark (SPY) based on last one month's data, and calculate beta with respect to the benchmark for every stock.
Every day, 5 minutes before the market closes, I compute the divergence of every stock. Divergence is calculated is the difference between the stock's daily percentage return and the expected return of the stock based on its beta (Expected Return = (Benchmark Return*Stock Beta)).
Entry Rules
Once I have the divergence for every stock, I find the stock with maximum divergence values. Then I find the stock with minimum positive divergence. In case all the other stocks have a negative divergence, I select the stock with maximum negative divergence.
Then, I short the stock with maximum divergence if the divergence value is more than 1% and long the stock with minimum positive (or maximum negative) divergence value.
Exit and Stop Loss Rule
I square off my positions when the divergence of the stock with maximum divergence (at the time of entry) becomes less than or equal to 1/4th of divergence at the time of entry or when the the divergence of the stock with maximum divergence (at the time of entry) becomes more than or equal to 1.5 times the divergence at the time of entry.