Searching and back-testing stock pairs
In the introductory articles of this series, we presented pair stock trading. If you have read our previous article, you know how interesting a portfolio comprising several dozen stock pairs can be. In this article, we will tell you how to find suitable pairs and how to make a portfolio of trading from them.
Computational complexity of stock pairs
With appropriate effort, a stock pair calculation table using the basic Ratio model can be put together in any spreadsheet program, for example in MS Excel. The model uses basic mathematical and statistical tools that most of us remember from school. Evaluating the statistics of the transactions executed is also not difficult. So what is the big deal?
The problem lies in the number of pairs available, and in the volume of data that must be processed. In previous parts of the series, we have already told you that stock pairs should be selected from individual sectors of the economy to best protect ourselves from the adverse impact of fundamental news. Even in the finest division, into 140 sectors, there are more than 340,000 stock pairs available among the stock traded on the NYSE and NASDAQ!
Just to give you an idea: if we managed to calculate and evaluate one pair per second in Excel (sic!), evaluating all of the pairs available would take us nearly four days of uninterrupted work! And this would only be one calculation of the lowest estimate of the number of pairs! Analysing robustness across sectors, there would be 36,000,000 pairs available that would take us more than one year of work straight to analyse in Excel!
This is not the way to go...
It is clear that this is not the way to go. Specialised software
is required for analysing stock pairs, that will do the work for us and allow us to concentrate on a trader’s real work – analysing and building a portfolio.
Stock Pair Builder
The Stock Pair Builder
program is designed for searching, testing, and analysing stock pairs and for putting together a trading portfolio. The program has been continuously developed since 2006.
The Stock Pair Builder
program features a list of all stock titles traded on US exchanges – NYSE, NASDAQ, and AMEX, their historical data since 1 January 2012, and definitions of 137 sectors of the US economy. This means that the program is immediately ready for use, nothing needs to be downloaded and no complex set-up is required. Currently, the program is being actively used by several hundred users around the world.
Searching for stock pairs (stock screening)
Screening is used for searching for stock pairs that meet the set criteria. Criteria can be divided into three groups:
Fundamental – stock price and average daily volume
Strategic – minimum value of correlation of the stock in a pair, assessed for two different periods
Performance-based – total profit / loss of the pair, average profit per transaction, number of transactions, percentage of profitable transactions, profit and drawdown ratio, percentage amount of drawdown, equity stability
Selection criteria can be combined as necessary, turned on or off. Screening can run on any time slot, with any setup of pair calculation model. All stock pair calculation models are available: Ratio, Residual, Log-Residual. Thanks to this, it is possible to make very quickly various analyses, model comparisons, a walk-forward analysis, etc.
Searching is possible either in selected sectors of the economy or in all defined sectors. The initial definition of sectors may be adapted or expanded. Sectors can be edited either directly in the Stock Pair Builder program or in an external spreadsheet (Excel).
Example from the Stock Pair Builder program prepared for searching for stock pairs
Stock Pair Builder is optimised to make full use of the calculation performance of contemporary multi-core processors. This makes for very fast searching for pairs. Depending on processor speed, the program can process hundreds or even thousands of pairs per second. The complete screening of all pairs in a predefined sector therefore takes less than one hour (!).
Pair back testing
Once we have identified stock pairs, we can go on to the second program tab – pair back testing. The back test shows detailed graphs and tables with the performance characteristics of pairs. Naturally, it shows the equity curve, a detailed calculation table for the pair, and a detailed list of all transactions. A pleasant function is the visualisation of the calculation model used, including the transactions executed, the course of correlation in up to four different periods, a histogram of the standard relative deviation distribution, a histogram of the profit / loss in individual transactions and pairs.
All tables used in the programme support direct export to MS Excel. That means that the data generated can be used for further analysis.
Now we will show you an overview of basic information in a back test of a sample stock pair:
Main window of Stock Pair Builder. Program support floating windows and docking.
Main window of Stock Pair Builder. Backtester provides many tools for detailed backtest of stock pairs.
Visualisation of the pair calculation model (the Residual calculation model was used). Green shows profitable transaction, red loss-making transactions.
Histogram of relative deviation distribution
Histogram of pairs profit / loss
In this article, we have demonstrated basic tools for back-testing and evaluating stock pairs in the Stock Pair Builder program. In our next article, we will show you how a back test of a portfolio is done, talk about the strategy of capital allocation to pairs, and show you the pair selection process.