Introduction
Paired switching is a strategy where in its simplest form, investors pick two assets that are negatively correlated and periodically switch position based on their relative performance. The idea behind this strategy is that if the assets are negatively correlated, then a traditional mixed portfolio might lead to a lower return than the return for the individual assets. If the negative correlation exists, switching positions could improve the performance of a portfolio where two assets are statically weighted.
Method
After two negatively correlated assets are determined, we will analyze them on a quarterly basis. The analysis will consist of retrieving historical prices for the two assets and calculating their performances over the prior quarter. We will buy the asset that yields a higher return during the period. The position is held for one quarter, and then the analysis is repeated.
def rebalance(self):
self.months +=1
if(self.months%3==0):
history_call = self.history(self.securities.keys,timedelta(days=90))
if not history_call.empty:
first_bars = history_call.loc[self.first.symbol.value]
last_p1 = first_bars["close"].iloc[0]
second_bars = history_call.loc[self.second.symbol.value]
last_p2 = second_bars["close"].iloc[0]
first_performance = (float(self.securities[self.first.symbol].price) - float(last_p1))/(float(self.securities[self.first.symbol].price))
second_performance = (float(self.securities[self.second.symbol].price) - float(last_p2))/(float(self.securities[self.second.symbol].price))
if(first_performance > second_performance):
if(self.securities[self.second.symbol].invested==True):
self.liquidate(self.second.symbol)
self.set_holdings(self.first.symbol,1)
else:
if(self.securities[self.first.symbol].invested==True):
self.liquidate(self.first.symbol)
self.set_holdings(self.second.symbol,1)
Derek Melchin
See the attached backtest for an updated version of the algorithm in PEP8 style.
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.
Gurumeher Sawhney
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.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!