Language:  ▾
Follow us:

Live trading of stock pairs

In previous articles in this series, we introduced the Stock Pair Builder program for back-testing pairs and for putting together a trading portfolio. Today, we will take a look at how to trade a portfolio.
The Stock Pair Trader, second from the StockPairTrading package of programs, is used for trading stock pairs. The Trader and the Builder form a mutually connected package that ensures reliable stock pair trading.

Getting your trading portfolio ready

The first step in preparing for live trading is saving your trading portfolio. Enter all of the stock pairs that you wish to have in your trading portfolio in the Stock Pair Builder program, on the Backtest card, in the Table of Pairs. Check the settings of the allocated capital, period, and time stop-loss. Save your portfolio to the disk, for example as “My portfolio.spt”. Start the StockPairTrader and open your portfolio in it by clicking on the “Load Portfolio” button. When you next launch the Trader, it will remember the portfolio you used, so typically, you will only need to do this once.
Both the Trader and the Builder use the same file type (extension): *.SPT. This means that you can transfer your portfolio between the programme as you need, without any conversions being required. If you for example wish to modify your portfolio, open it in Builder, make the changes required, and save it. Next time you start the Trader, it will work with the adapted portfolio.

Connection to the TWS (Trader Work Station)

Stock Pair Trader trades through InteractiveBrokers as the broker. It is one of the world’s largest and most reliable traders, with relatively low commissions. InteractiveBrokers makes it possible to trade on most stock exchanges around the world.
The InteractiveBrokers trading platform is called Trader WorkStation (TWS for short). It is a standard application for Windows (iOS) which gives a trader access his account and to the stock exchange. TWS displays current prices, open positions, submission of trading orders, etc.
Stock Pair Trader receives all data from the market, information about open positions and active orders in a trader’s account through TWS. Trading orders are also executed through TWS: the Trader prepares orders and submits them to TWS. Here, they either wait for a trader’s approval and sending to the exchange, or they are sent to the exchange directly.
What is important for a trader is that the Trader does not store any trading data on the local disk of the computer. There are three major advantages to this approach: (a) there is no risk of loss of locally stored data; (b) there is no risk of a discrepancy between locally stored data and data on IB servers; (c) you can switch between computers when trading without having to synchronise or otherwise transfer data: you can trade from your desktop one day, from your notebook the next, and another time through VPS (see our next article). The only thing that is stored locally is the definition of your portfolio.

Trading modes

Once a connection with TWS is established, the Trader automatically starts to download real-time data of all stock forming pairs in the trading portfolio. Every time there is a change, it automatically recalculates the pair’s calculation model, signals are updated, and any trading orders as well. All information is displayed in the easy-to-use graphics of the main program window.
Program main window
Stock Pair Trader can work in two different modes:
  1. Manual mode – in this mode, the Trader receives price updates and generates signals. Trading orders are generated and passed on to TWS only once the user clicks on “Submit Orders”. This means that the trader has the running of the program fully under his control. The trader can view and check all orders in TWS before they are submitted to the stock exchange.
  2. Automatic mode – in the automatic mode, the program takes full control of the execution of trading orders. It prepares orders at the time entered, submits them to the stock exchange through TWS, and checks that they have been duly fulfilled. The user need not take care of anything in this mode, the program trades for him.
The type of orders generated by the Trader can be set up. The default type is LIMIT, which ensures that each order is fulfilled optimally, reducing the price “slip”. If the Automatic Trading Mode is active, submitted orders are managed intelligently such that they are optimally fulfilled during the set time slot. The alternative is the MARKET type order that ensures an immediate fulfilment of an order, but at a less favourable price.

Aligning live trading with a back-test

The trading model used by the Trader for generating signals and trading orders is identical to that used by the Builder for back-testing. The logic of portfolio management (limiting the number of open positions, blocking cross and duplicate pairs, ordering according to the fitness function) is also identical. The risk of human error is eliminated due to automatic preparation and transfer of trading orders.
Hence, StockPairTrading creates ideal conditions for a successful transfer of the results from back-testing to real trading.
The only “systematic” difference between a back-test and real trading is the price for which a share is purchased / sold. The back-test uses End-Of-Day Close prices. In live trading, it is naturally impossible to enter into a position after a market closes. But an effort should be made to get as close to EOD Close as possible. It is therefore advisable to execute trading orders right before a market closes. To make a certain time provision, we recommend setting the time slot for entry and exit at 5 – 10 minutes before the end of trading.
The time slots for entry and exit can be set independently. Some traders take advantage of this and have their time slot for leaving a position set for the whole day – any time they get a signal for exit during a day, they end their position. Its approach is more aggressive than trading at the close of the day. It usually results in a higher percentage of profitable transactions but decreases alignment with the back-test (which is calculated on the basis of EOD Close prices). It is up to each trader which approach he chooses.
The extreme option is “intraday” pair trading when the time slots for entry and exit are the entire day.

Program activity log

Stock Pair Trader records all of its activities in a log. This means that at any point, you can find detailed information about the trading process, fulfilment of trading orders, etc. The program log is saved in a text file in RTF format, which means that it can be opened in any text editor (e.g., MS Word). You can enter your own notes in the log directly in StockPairTrader, edit it, or delete parts of the text.
Stock Pair Trader's log


Today, we introduced a reliable and efficient tool for trading stock pair portfolios. In the next part of our series, we will focus on historic data for stock pair back-testing. We will see how and where data can be obtained, how to check it, and how to cleanse it off splits and errors.