Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
simple pairs strategy questions

So this is the first algorithm i have scratch coded (loosely based on this algorithm - emphasis on loosely) on quantopian and I wanted to post it here for comments as it is clearly less than successful. basically the algorithm works as follows (or was intended to anyway)

  1. take the ratio of two stocks
  2. compute the mean and stdev of the ratio over a 30 day look back period
  3. if the current ratio exceeds some number of standard deviations from the mean go long on the under performer and short on the overachiever.
  4. position are exited when the ratio return close to the mean again.

so my questions regarding this are two fold.
being new to python is and the platform is that actually what I'm doing?
secondly does the strategy make any sense at all? i.e. are the poor results because of a completely incorrect strategy or because of implementation details?

3 responses

Stephan,

Pairs Trading can be an effective method, but there are some factors to take into consideration when implementing this strategy:

  • Ensure that the profit target (usually estimate at about half the spread between the two stocks) is at least enough to cover the cost of slippage, and commissions
    - Slippage and commissions models and examples can be found in the API
  • Calculate the period of the cointegration between the two stocks you are trading.
  • Check to see if the two stocks you are trading actually cointegrate. (one method is the johannsen test)

You might want to consider trading etfs instead of stocks for pairs trading. Individual companies stock prices are affected by a lot more than industry and sector, so they will move independent of their sector. This will cause errors in any pair trade.

The link below is to a thread on Ernie Chan's Pair Trading method. This a very followed thread of a lot of people discussing different aspects of his algorithm. It would be a great place to start.

-Daniel

Ernie Chan's EWA/EWC pair trade with kalman filter

Thank you for the advice. I can see how a big part of the issue is not doing enough analysis before actually trading...
I had looked at that thread before but tried to simplify that a little as a starting point. (i.e. not including filter etc) evidentially that was something of an oversimplification...

Stephen,
Some people do use price ratios as a signal for pairs trading strategies, if you assume the ratio is mean reverting, in theory, it should be profitable. The problem is that's a huge assumption, and you will still need to select an intelligent hedge ratio because the price ratio itself might not be the best choice.

I like the idea so I threw together a modified version of your algorithm. It still uses the ratio as an entry signal, but I used the regression coefficients between the two to determine the hedge ratio.

If n is the number of shares you are betting, the value invested in each stock is;

  • Under performer: n * price
  • Over performer: -n * h * price, where h is is regression coefficient used as the hedge ratio

It's by no means a winner, but does show potential. It could become a decent strategy with a little tweaking and a good choice of stocks.