Back to Community
Statistical Arbitrage based on Divergence

This is statistical arbitrage strategy based on divergence of stock returns. 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) and 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
3. Once I have the divergence for every stock, I find the stocks with maximum and minimum divergence values. Then if the maximum divergence value is more than 1% or minimum divergence value is less than -1%, I short the stock with maximum divergence value, and long the stock with minimum divergence value.

Exit and Stop Loss Rule
In case the position is taken on the basis of maximum divergence value, then 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/10th 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 2 times the divergence at the time of entry.

Similarly, in case the position is taken on the basis of minimum divergence value, then I square off my positions when the divergence of the stock with minimum divergence (at the time of entry) becomes more than or equal to 1/10th of divergence at the time of entry or when the the divergence of the stock with minimum divergence (at the time of entry) becomes less than or equal to 2 times the divergence at the time of entry.

Clone Algorithm
8
Loading...
Backtest from to with initial capital
Total Returns
--
Alpha
--
Beta
--
Sharpe
--
Sortino
--
Max Drawdown
--
Benchmark Returns
--
Volatility
--
Returns 1 Month 3 Month 6 Month 12 Month
Alpha 1 Month 3 Month 6 Month 12 Month
Beta 1 Month 3 Month 6 Month 12 Month
Sharpe 1 Month 3 Month 6 Month 12 Month
Sortino 1 Month 3 Month 6 Month 12 Month
Volatility 1 Month 3 Month 6 Month 12 Month
Max Drawdown 1 Month 3 Month 6 Month 12 Month
# Backtest ID: 5a2293c7a1e68c416d1e6944
There was a runtime error.
6 responses

It looks like the algo holding the same position : AMZN(+6051), ADBE(-10000) since 2008-01-03.

Hi Vladimir,
Thanks for pointing that out. I am working on the code to resolve this error.

Hi Vladimir,

I have tried to resolve the error you pointed out. Also, I have modified the strategy a bit.
Please find the find the updated strategy by visiting the following link.
https://www.quantopian.com/posts/statistical-arbitrage-based-on-divergence-version-2

Please reply if you find any error in the back-test results.

@Himanshu,

Now you have leverage problem.

position on 2008-05-29
ACN(-1000) -$39,900.00
GOOG_L(909) 529,728.84

Cash -418.702.47

Try to normalize ratio

ratio = ratio/np.sum(abs(ratio))  

and use order_target_percent...

Good luck.

Hi Vladimir,

Hi increased my capital from $100,000 to $400,000 to reduced my leverage to 2x.
I have attached the back-test with this mail.

Please suggest whether it is correct to consider 2x leverage while analysing a strategy or not.

Thanks

Clone Algorithm
11
Loading...
Backtest from to with initial capital
Total Returns
--
Alpha
--
Beta
--
Sharpe
--
Sortino
--
Max Drawdown
--
Benchmark Returns
--
Volatility
--
Returns 1 Month 3 Month 6 Month 12 Month
Alpha 1 Month 3 Month 6 Month 12 Month
Beta 1 Month 3 Month 6 Month 12 Month
Sharpe 1 Month 3 Month 6 Month 12 Month
Sortino 1 Month 3 Month 6 Month 12 Month
Volatility 1 Month 3 Month 6 Month 12 Month
Max Drawdown 1 Month 3 Month 6 Month 12 Month
# Backtest ID: 5a2459ef0089f540792e7284
There was a runtime error.

I have attached another back-test, which runs with a capital of $1,000,000.
With this capital, I virtually need no leverage.

In this case, my maximum drawdown is -6% and my Sharpe is 0.58.

Will it wise to lever such a strategy in real life scenario?

Clone Algorithm
11
Loading...
Backtest from to with initial capital
Total Returns
--
Alpha
--
Beta
--
Sharpe
--
Sortino
--
Max Drawdown
--
Benchmark Returns
--
Volatility
--
Returns 1 Month 3 Month 6 Month 12 Month
Alpha 1 Month 3 Month 6 Month 12 Month
Beta 1 Month 3 Month 6 Month 12 Month
Sharpe 1 Month 3 Month 6 Month 12 Month
Sortino 1 Month 3 Month 6 Month 12 Month
Volatility 1 Month 3 Month 6 Month 12 Month
Max Drawdown 1 Month 3 Month 6 Month 12 Month
# Backtest ID: 5a245c36cc11dd44cd66ccf9
There was a runtime error.