AlgoTraderAlgoTrader Documentation

Appendix G. Example Strategy "Spreader"

The spreader is a pair trading strategy that seeks to either short or buy the spread between EURUSD@IB and GBPUSD@IB when the value of the spread between the price of both instruments breaches a certain threshold.

The Strategy enters a LONG/SHORT position if the spread goes below the "go long" threshold and enters a SHORT/LONG position if the spread goes over the "go short" threshold.

Positions are closed either with profit (spread moves favourably by the take profit offset) or with loss (spread moves unfavourably by the stop loss offset).

The main artifacts needed for the Implementation of a new Strategy are described in Chapter 4, Strategy Development.

The Spreader Strategy consist of the following artifacts:

/src/main/java/ch/algotrader/strategy/SpreaderService.java

The strategy service class providing the main methods invoked by different Esper statements.

/src/main/java/ch/algotrader/strategy/SpreaderConfig.java

Contains all strategy configuration items

/src/main/java/ch/algotrader/strategy/State.java

Defines the state the strategy can be in. (LONG, SHORT, FLAT, PENDING_LONG, PENDING_SHORT, PENDING_FLAT)

/src/main/resources/conf-spreader.properties

Contains parameters used by the strategy (e.g. firstSecurityId and secondSecurityId and firstSecurityFeedType and secondSecurityFeedType)

/src/main/resources/META-INF/applicationContext-client-spreader.xml

Contains the Spring Bean definitions for spreaderConfig, spreaderConfigParams, spreaderEngine, spreaderService.

/src/main/resources/db/mysql/spreader.sql

Contains the MySQL database records. Needs to be imported into the database before running the strategy with the MySQL database.

To start the Strategy please see the explanations in Chapter 3, Starting AlgoTrader.

To setup the strategy for back testing and live trading on a development workstation please execute the following steps:

To start the strategy in live trading mode on a development workstation please execute the following steps:

To start the strategy in live trading mode on a productive server please execute the following steps:

Copy docker compose file

Copy the following file to the server and make changes as needed:

https://gitlab.algotrader.ch/general/examples/blob/master/spreader/docker-compose.yml

Run docker compose

Invoke the following command inside the directory where the docker-compose.yml file is located:

docker-compose up -d

Note

Prior to starting the strategy for the very first time please start the AlgoTrader server by itself by executing the following command inside /bootstrap/launch. this will load the MySQL sample data

docker-compose up -d mysql ibgateway algotrader