Back

Intraday Pairs Trading Based on Correlation and Cointegration

Hi Everyone. I'm working on a HFT pairs trading. I finished the prototype of it, and it looks promising. The Algorithm has a 3-month warming up peroid so there are no trades. I will continue to adjust the opening threshould, stop loss parameter and closing threshoud. I will also explore some good pairs to make the the algorithm trade at a high frequency. 

I will update the algorithm here. Anyone thought or feedbacks are welcome.

Update Backtest








The alpha seems good enough as it has both a high win rate and large wins, a few things I can think of however:

1) Few trades always makes me scared that what I'm observing is just some random fluctuation. Of course, since you're building on statistical methods this is less of a concern than for someone trying e.g. hand coded pattern recognition.

2) Due to aforementioned high win per trade, it's again probably manageable, however: Setting a simple slippage model is advisable (e.g. ConstantSlippageModel) to account for bid-ask spread slippage. I just checked one of the symbols you have and the bid-ask spread was approximately 0.5% of share price.

2

Hi there Yan Xiaowei 

Great work!

As Peter noticed, there are few trades, 24 in 9 months for minute data is too low. Is the cointegration criteria too high? Maybe more stocks are needed, by the way, what is the rationality behind the stocks selection?

Finally, from the implementation perspective, maybe you can use a Schedule event to tests correlation/cointegration every three months.

1

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 QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect 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. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


It looks like it trades more in highly volatile periods; perhaps you could add in more volatile stocks to encourage more trading.

0

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 QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect 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. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


Hi Peter JayJay and Jared,

Thank you for your suggestions! Here are my thoughts about the issue you pointed out:

1. Few trades are caused by the number of stocks in the universe. I can defenitely select more stocks to make up more pairs, but it takes 6 second on average to conduct ADF test on a single pair -- I'm thinking about using a lower resolution such as 5min or 10min to speed up the ADF test so that I can have more pairs.

2. If we use a lower resolution, the bid-ask spread might not be a big problem -- although we will still overestimate the profit. I will check that after the algorithm is finished.

3. All of the stocks are U.S. bank equity. I randomly deleted some of them to make the list shorter for test purpose. I plan to select stocks in traditional industries such as energy, retails, manufactory and bank. The reason is the companies in the traditional industries are not that distinguishable, thus they are likely to have a stable high correlation.

4. The strategy first use 3-month history data to select pairs, and then use a rolling window to conduct correlation and cointegration test very month. 

I will write the 3-month warmup period into Initialize step, and try to use a lower resolution data. Hopefully we can have more stocks so that we can trade at a higher frequency. I will also update it here. 

Again, thank you for your feedbacks!

 

 

1

Hi everyone,

I updated the algorithm to make it more flexible. Now you can change the resolution of the data by changing the parameter self.data_resolution. For example, 5 means aggregating the data into 5-minute resolution.

I also updated the method of using SetHoldings, which is wrong previously. In python you need to write 1.0/n to make it a float, otherwise it would be 0.

This algorithm is now flexible enough and it defenitely has a large room for improment. Feel free to play with it, try it on your target industry and find the best parameter for your own version.

Again, any thought or feedback are welcome!

 

3


    Suggestion for intra day trading use futures.  You get atleast 10:1 leverage using futures.  Principal pairs I trade Silver (SI) & Gold(GC)    also Russel(TF or RTY) & SP Futures(ES).  I have found that (for these) you only need to trade the more volatile instrument of each pair.   For Silver/Gold pair I only trade the silver contract where  most of the price movement occurs, Gold is simply used as indicator..  This method used to be called Unipair Trading.

    One other issue parameters have to be optimized every two weeks due to changing market character.   Lean does not have this feature yet.  Algorithm can be made self optimizing but for me was not worth the effort.

 

   I would post the code but its in EasyLanguage not Lean.

Link to old  (2004) out of print book.  Still useful for ideas.

https://cp.sync.com/dl/476749430#ww9t7ymc-6xzwhbvq-9xpgbhua-83t8wnfp

 

0

Update Backtest





0

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 QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect 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. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


Loading...

This discussion is closed