Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
ETF Arbitrage

I want to create an algo that automatically detects divergences between ETF's that track the S and P. The algo would then seek to profit off of the divergence. I have tested out my main premise with historical data and it works. I just don't have the coding expertise. Where can I start?
It would be a simple sell the expensive buy the cheaper and then undo when the divergence disappears.

5 responses

I would be extremely surprised if this was profitable with Quantopian, this is firmly in the realm of HFT these days. What data were you using to test the premise?

I saw divergences in two etf's (nothing big about 10 basis points) on my iphone's ticker. I know that this info isn't 100% accurate and timely and that for this strategy you are actually interested in bid and ask price but I am speculating that there are divergences throughout the day. Anyways, I used that data and then I saw that eventually the divergence went away.

People do do this, but I think it's mostly HFT, and when I backtested this sort of thing using bid/ask data, there was very little in the way of executable opportunities unless market-making.

Anyway, to answer your question, you would make an algo with several equivalent ETFs in a list, and use Pipeline to calculate some sort of adjustment factor for each to normalize their prices (since they may split/pay dividends at different times, and this can be a significant complication). Alternatively, you could assume that their opening prices were all correct, then track their relative returns-since-open, and place the spread trades based on deviations in those returns.

But, to be honest, you'll be trying to calculate all this from unknowably-sparse trade data, unknowably-aggregated into one-minute bars, and you won't be able to adjust your orders except every minute, so to capture a hypothetical deviation reliably, you'll need to use market orders or you'll only get executed on one leg at the worst time, and then you'll pay four slippages per round trip of a deviation that is, best case, 10bp, so you'll need your execution costs to be under 2bp, and everything else is going to drown out that edge.

There might still be an opportunity to do this sort of thing in less liquid ETFs, but even that I wouldn't dare attempt on Quantopian, I'd want at least Level 1 quote data and co-located machine to execute.

Fully agree with Simon. I tried a similar algo before and found after all costs, that approach generated very little return. The market is quite efficient in that respect.