Cointegration Weighted Index.

Cointegration Weighted Index.

In this article, we will talk about an index for pair trading, built using the formula of the "minimum residuals from the difference between two price series with an optimal multiplier" indicator. In OsEngine, we have the calculation of this indicator in the layer for creating robots for pair trading (BotTabPair), however, we were asked to present it in this format. The data should be in the form of candlestick data, onto which various indicators can be applied.

 

1. Chart of the minimum residuals from the difference between instruments with an optimal multiplier.

In pair trading, it looks like this:

The essence is to select a multiplier for the second instrument so that the standard deviation from zero over a certain period is minimized. In the end, the formula looks very simple:

The magic lies in finding this very multiplier.

* Important! The name of the index type "Cointegration" is humorous and simplified. This is because writing "Chart of the minimum residuals from the difference between instruments with an optimal multiplier" every time would be even more absurd.

 

2. How to include the Cointegration index through the auto formula in OsEngine.

In the index settings window, you need to select the desired weighting type - Cointegration:

You can view the final formula in the bottom left corner.

Ultimately, we get a candlestick chart of the index, onto which any indicators available in OsEngine can be applied, and from which trading signals can be taken.

And friends... You can apply all indicators to the chart, but not all of them support negative values on the chart.

 

3. Source code.

The indexing is done in the BotTabIndex file, in the IndexFormulaBuilder class:

https://github.com/AlexWan/OsEngine

In the method:

The logic is divided into different types of weighting. By methods.

* If you find any errors in the source code, please make sure to contact support.

https://t.me/osengine_official_support

Good luck with your algorithms!