Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Multiple Pairs Trading Strategy

The basic idea mainly comes from Ernest Chan's pair trading in his book. Instead of trading just one pair of stocks, I traded all possible pairs among 10 stocks. In other words, I am trading 45=(10 choose 2) pairs simultaneously. Good to see that works.

Idea of the Multiple Pair Trading Strategy :
Step 1 : Define hedged spread : Spread = Stock1Price - HedgeRatio x Stock2Price
Step 2 : Define Z-score : Z-score = ( SMA30(Spread) - Spread ) / STD30(Spread)
Step 3 : Short the Spread if Z-score > EnterThreshold. ( resp. Long the Spread if Z-score < -EnterThreshold )
Step 4 : Exit the Short if Z-score < ExitThreshold . ( resp. Exit the Long if Z-score > -ExitThreshold )
Step 5 : Trade all possible pairs among selected securities.

I am quite new to this field. I just pick the 10 stocks randomly. Is there any better stock picks? Is there any principles behind how to select stock pairs on which the strategy may work best?

Here's the backtest. Cheers.

6 responses

Savio,
This algorithm is really interesting and produces very good returns. The construction of the algo is very robust, but the use of 10 stocks some of which are seemingly unrelated surprises me in its effectiveness. I would suspect choosing a few targeted paris rather than a combination of ten might produce even better results. I am working on this now and will keep you updated. Thanks for posting your progress!

This is great! Could you explain whats happening at the beginning?

Good returns. How did you select the stocks?

Thank you for the replies.
I guess I have over-fitted the data which accounts for the nice Sharpe ratio.
I should have picked stocks within a particular sector. Stocks within one particular sector is expected to have higher correlation than that from multiple sectors. The original idea of the pair trading strategy is to trade the reversal of the spread between 2 correlated securities. At the beginning, I just randomly picked a basket of stocks/indexes and played with them. After learning more about the Pair Trading System, I am surprised with the above result too.

Savio don't just limit yourself to stocks in the same sector, that's probably a good initial screen if you are trying to dynamically find and select pairs but it wouldn't at all surprise me if a CAT is cointegrated with NEM, as heavy equipment is needed for mining even though they aren't in the same sector/industry.

Disclaimer

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by Quantopian. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. No information contained herein should be regarded as a suggestion to engage in or refrain from any investment-related course of action as none of Quantopian nor any of its affiliates is undertaking to provide investment advice, act as an adviser to any plan or entity subject to the Employee Retirement Income Security Act of 1974, as amended, individual retirement account or individual retirement annuity, or give advice in a fiduciary capacity with respect to the materials presented herein. If you are an individual retirement or other investor, contact your financial advisor or other fiduciary unrelated to Quantopian about whether any given investment idea, strategy, product or service described herein may be appropriate for your circumstances. All investments involve risk, including loss of principal. Quantopian makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances.

Hi,

Thanks for sharing the code! Really helped me on my learning journey. Would be really helpful if you could explain your thought process on the position sizing in the following code. Thanks!

order_target_percent(stock1, hedge/l )  
order_target_percent(stock2, -1.0/l)