A robot for classic statistical pair arbitrage in OsEngine.

A robot for classic statistical pair arbitrage in OsEngine.

Overview of a free robot for pair arbitrage in OsEngine. The robot is ready for launch on the Moscow Exchange (MOEX), and other exchanges such as Binance, Bitget, etc. In general, join us.

Logic:

The essence is that when the correlation breaks the level of 0.9, we enter based on some cointegration, expecting pairs to converge.

Exit based on the cointegration signal in the opposite direction.

Fig. 1. Example of logic.

Location:

Fig. 2. Location in the project.

Robot code: 

Fig. 3. Constructor.

1. Create a private field of type BotTabPair.

2. Call the TabCreate method from the base robot class, passing the BotTabType enumeration as a parameter, in our case Pair. Then write the reference to the previously created field below.

3. Subscribe to the CointegrationPositionSideChangeEvent event.

4. Create a Regime parameter to check the robot's status, whether it is on or off.

5. Also, create a MaxPositionCount parameter to set the maximum number of positions.

Fig. 4. Method GetNameStrategyType.

1. Create the GetNameStrategyType method and write the name of the robot in it.

Fig. 5. CorrelationChangeEvent event handler.

Go to the event handler:

1. Check if the robot is on or off, if not, exit the event.

2. Check if we have open positions, if yes, enter the logic of closing positions, if there are no open positions, then move on to the logic of opening positions.

Fig. 6. Logic for closing positions.

1. Look at the direction of cointegration:

a. Direction above the upper line.

b. The previous value was below the lower line.

Then we close positions.

2. Also check the direction.

a. Value below the lower line.

b. The previous value was above the upper line.

Close positions.

Fig. 7. Logic for opening positions.

1. Compare the last correlation value. If it is less than 0.9, then exit the method.

2. Check the number of open positions and exit the method if they equal the maximum allowed number of positions.

3. If the cointegration is above zero, then we open a Short position on the first instrument and a Long on the second.

4. If it is below zero, then vice versa; the first instrument - enter Long, and the second - enter Short.

Testing:

We conducted a test on 6 pairs. Here's what we got from it:

Fig. 8. Testing results.

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