Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
VXX/XIV Pair Trade Algo

Alright, I had another thread where I was trying to find where ratios are deviating between pairs and when they reach an outlier 2.5*Standard Deviation to short one and go long the other. Here is the code that I came up with... again, I am terrible at Quant coding so go easy.

I still think it needs work to exit the pair trade before entering a new one. Also, the leverage is really bad and I don't know how to fix that. Any help is appreciated.

2 responses

If you're inPosition, you're exiting if the ratioToday is <upper or >lower, which is always. That means you're only in for a minute.

You should distinguish between being long and short the pair, and incorporate this information into the conditions in lines 23 and 30.

Ok, I have modified the code a little further.

But I need it to only purchase once when it crosses above 2.5/-2.5 and then close once it crosses back below. The algo is still making multiple purchases as the ratio might stay outside the band for a couple minutes.

Any help is appreciated.