Back

PCA and Pair Trading

Hello, 

I am trying to implement a pair trading strategy based on the following paper:

https://www.math.nyu.edu/faculty/avellane/AvellanedaLeeStatArb071108.pdf

 

I tried to code the strategy (the paper is not hard to understand) but it appears that the algorithm doesn't liquidate stocks .How can I fix this small problem?

Thank you 

 

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.


Hi,

 

Thanks for interesting share.

The main problem I noticed is that your function CoarseSelectionAndPCA sets the dataframes self.weights_buy etc to new/empty on all but a single day of the backtesting period (2001-01-17). Consequently trades occured only on that day. You can see that this is happening by placing self.Log or self.Debug commands. I have not debugged further why this is happening.

 

Moreover additional changes will probably be required around the SetHoldings calls:

  • The pattern below is problematic, because it will fail to rebalance the position, and will fail to increase/decrease the holding in case the security is already invested, but its intended weight has changed. Worse it may also miss the case when a security goes direct from intended long to intended short or vice versa.
if self.Securities[symbol].Invested:
continue
self.SetHoldings(symbol, -weight)

 

  • Generally speaking it should be better to liquidate unwanted positions before calling SetHoldings, because SetHoldings requires available buying power. But even then it is not guaranteed that positions will be scaled in the optimal order, and liquidating the full portfolio before investing back is not economically efficient.
  • To address the above point consider using SetHoldings with a "portfolio of asset targets" as per the documentation.

 Bests

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