Cointegration scanner

Hi all,

A few years ago I started taking an interest in algo trading, especially around statistical arbitrage and cointegration. I’m a (back-end) programmer by profession.

I’ve created a webpage (webapplication1020221211163337 dot azurewebsites dot net/) that scans, calculates, and displays the cointegration of various forex pairs using the Augmented Dickey-Fuller method. The displayed pairs that have been calculated to have a p-value of 0.05 or less.

The site is still showing old data as I had to put things on pause last year due to health issues and just picked it back up recently. The page is pretty crude as it was more of a proof of concept and you can see the same data is displayed on 2 graphs as I was experimenting with different graphing libraries.

I kind of want to gauge the usefulness of such information for retail traders. Does anyone here have a use for such data? Would appreciate any feedback or suggestions and if you find such data helpful to your trading strategy.

Thanks

Looks pretty fancy!

Except I don’t know how to use it. :sweat_smile:

What have been you use cases for this one?

Also, I hope you’re doing much better health-wise these days!

For anyone interested btw, here’s the link: https://webapplication1020221211163337.azurewebsites.net/

Hi and thanks for taking the time to have a look and your well wishes.

So the graph is showing the statistical relationship between 2 sets of currencies it has found to be showing signs of cointegration (ie p value < 0.05) which means the graph should be cycling up and down (stationarity) as opposed to trailing up or down only (non-stationary).

The black and blue horizontal lines represent the values of the calculated standard deviation (SD) eg ±2.5. In its most basic terms, a value that is on either side of SD=2.5 would more of less means it has an upper/lower percentile of somewhere around 0.5% (I think), which means it is statistically significant.

So if the 2 sets of currency fall out of this SD line and the cointegration is expected to continue then we would expect these 2 sets of currencies to eventually mean revert, ie for the graph to head back towards 0.

Eg you can see below the EURGBP and AUDCAD pair at T12.45 the graph is way below the SD=-2.5 line and by hovering over that point you can see how how the value was calculated. So if I am expecting the graph to head back to 0 (mean revert) and I would long EURGBP and short AUDCAD at those prices or better (the tooltip also shows I have to buy 2.3113 EURGBP for each AUDCAD to maintain the ratio).

You can see the graph does indeed head back to 0 and if I close both positions 45min later I would’ve made a profit on both trades.

The devil is in the details of course:

  1. in real-time u won’t be seeing ahead of the graph you would see maybe 1 data point to the far right of the graph that is outside of the SD line and you would be betting that these 2 pairs of currencies would continue to be cointegrated for the duration you’re holding those positions as there is the chance that the cointegration was purely a statistical anomaly.

  2. you have to buy both currencies at the price indicated on the graph or better.

The 2nd matter is where I struggled to make this work on short time frames (even with programmed bots to submit orders), if you set both currencies/stocks as market orders you risk buying them at the price above/below your desired price. If you set both as limit orders you then risk only being able to fill out 1 order and not the 2nd.

I thought about maybe if I used much higher time frames (eg daily) then maybe the price might not need to be that precise but haven’t had the time to test it out yet.

If you want to know what cointegration means (as opposed to correlation) feel free to ask and I can try to explain it in a further post.