Robot for classical index arbitrage. Trading from index.

Robot for classical index arbitrage. Trading from index.

Trading idea: Trading the spread between two indexes as if it were a pair. Buy and sell the spread between them.

1. Robot sources:

1. Index. BotTabIndex for generating index number 1.

2. Index 2. BotTabIndex for generating index number 2.

3. Screener. BotTabScreener for trading index number 1.

4. Screener 2. BotTabScreener for trading index number 2.

 

2. Indicators:

1. Correlation, needed for calculating the correlation between the indexes.

2. Chart of "Minimum Residuals from the Difference Between Instruments with Optimal Multiplier" for generating signals between the indexes.

 

3. Robot logic:

1. Build a sectoral oil index by selecting everything in the sector.

2. Build a sectoral bank index by selecting everything in the sector.

3. When the value deviates beyond the standard deviation multiplied by the multiplier on the "Minimum Residuals" chart, buy the spread between the instruments. Sell on the opposite signal.

 

4. Source code in the project:

GitHub link: https://github.com/AlexWan/OsEngine

Constructor:

1. Creating index (BotTabIndex) number 1. Also subscribing to its updates. Instruments added to it should be synchronous with the ones added to Screener 1.

2. Creating index (BotTabIndex) number 2. Also subscribing to its updates. Instruments added to it should be synchronous with the ones added to Screener 2.

3. Creating Screener 1. Trading will be conducted through it for index 1.

4. Creating Screener 2. Trading will be conducted through it for index 2.

5. Initializing strategy parameters.

Where to look in the code:

1. Synchronization logic between the indexes and choosing the branch of logic. Opening / Closing positions.

2. Position opening branch.

3. Position closing branch.

 

5. Robot settings:

1. Regime. Operating mode:

a. On - all trading modes are enabled.

b. Off - disabled.

2. Regime Close Position. Position closure type:

a. Reverse signal. Reverse signal type from the minimum deviation chart with optimal multiplier.

b. No signal. Neutral position on the minimum deviation chart with optimal multiplier.

3. Percent depo on one leg. Percentage of available funds per side of the trade.

4. Asset in portfolio. Name of the monetary unit in the portfolio.

5. Correlation candles look back. Period for calculating correlation between the index and instrument in trading.

6. Cointegration candles look back. Period for calculating the minimum residuals chart between the instrument and index with the optimal multiplier.

7. Deviation mult. Deviation for the standard deviation on the minimum residuals chart with the optimal multiplier.

8. Correlation min value. Minimum correlation value to open a position by instrument.

 

6. Running the robot in the tester:

In the exchange emulator settings, I have connected a data set with securities from the Moscow Exchange:

Create a robot. Open its chart and configure the sources:

Securities from the Russian oil and gas sector are added to Index number 1:

Auto-formula is set up for Index 1 to calculate once a day, weighted by price:

Securities from the Russian financial sector are added to Index number 2:

Auto-formula is set up for Index 2 to calculate once a day, weighted by price:

Securities from Index 1 are added to Screener 1 for trading:

Securities from Index 2 are added to Screener 2 for trading:

7. One of the testing scenarios.

If you have any difficulties or questions, please write to the support chat. Link

OsEngine: https://github.com/AlexWan/OsEngine