Sierra Chart | Pairs Trader
The strategy known as “Pairs Trading” was founded in 1980 by a group of Quants at Morgan Stanley. It has been used by proprietary trading desks and investment banks since – some of which have yielded good results. It had been kept a secret for many years by the professional traders. The internet and the spread of information put an end to that making the strategy available to retail traders.
The strategy works under the observation that some instruments are highly correlated. Highly correlated means the following: say we have 2 stocks A and B. If A and B are highly correlated they will mostly move together meaning when A goes up B goes up and when A goes down B goes down. To a certain extent – take note because this is the interesting part – it can be said that you might not know which way A or B are going to move, up or down, but you can be pretty certain that whichever way they do go, they will be going together.
Sometimes the market offers us an opportunity when the correlation breaks. This happens when at some point, for some reason, pair A and B do not move together. It is a form of divergence and it is often the case in the market that when two highly correlated items diverge, at some point, they tend to come back together – at some point.
Pairs Trading is also referred to as a market neutral strategy because we are essentially not betting on the direction that either A or B will go – we are betting on the fact that they will come back together.
When two highly correlated instruments diverge, a pairs trader will step in and place a trade that bets that the divergence will close. The trader will do this by going long one instrument and short the other.
In a nutshell, there are 4 steps to pairs trading:
Step 1: Find a pair A and B that are highly correlated.
Step 2: Wait for the ratio between A and B to diverge.
Step 3: When they have diverged far enough put on a position that is long one of the instruments and short the other.
Step 4: When the ratio comes back to normal, exit the trade – hopefully with a profit.
In general, a pairs trader would enter Long the Derivative (Long A and Short B) when the number of SD’s drops below a threshold (e.g., below -2.2). Or Short the Derivative (Short A and Long B) when the number of SD’s (e.g., exceeds +2.2). An exit would be taken when the spread returns to zero.
The above description is a simplistic explanation for those that not familiar with the technique and is offered here as a high level description. It does not cover a lot of questions that become urgent when trading. How far do they have to diverge in order to enter? What happens if they continue to diverge – when do I get out with a loss? Which instrument do I go long? And how do I size the position (i.e., how much of A and how much of B)? None of these are idle questions and all of them and more need to be answered before trading this strategy.
Pairs Trader 2
“Pairs Trader 2” is one study in a set of studies designed with pairs trading in mind.
How it works
Pairs Trading in general is a statistical method. The study receives the pair to plot as input and produces a subgraph of the spread. The spread being the difference between the two instruments. There are various ways to calculate the spread. Most will use some form of ratio between the two instruments and a normalization method based on standard deviation. More elaborate math is possible.
In our case, the spread is calculated in the following manner:
- Take a ratio between the A and B (i.e., A / B).
- Calculate the log of the ratio.
- Calculate the average of the log – this is done using a simple moving average.
- Calculate a Standard Deviation of the log – this is used for normalization.
- Calculate the spread which is by taking the difference between the log of the ratio and the average of the log of the ratio (as calculated in steps 2 and 3 respectively) and dividing by the standard deviation (as calculated in step 4).
Lets use two stocks as an example – GM and FORD using historical daily data. Being in the same sector, these two stocks are highly correlated and would be good candidates for a pairs trade.
- First open a chart with GM.
- Second open a chart for FORD. Not mandatory, but it makes sense that the two charts be of the same timeframe (daily, 15 min, etc.). It also makes sense to be using time based charts as opposed to non time based charts such as range/tick/volume/renko.
- We will be overlaying the FORD chart on top of the GM chart. In the GM chart, add the “Overlay (Single Line)” study that comes built in with Sierra Chart. In the overlay study settings, under the “Chart Number to Overlay” field, set a referenced to the FORD.
See the section On Overlay below for more details on this.
- If you have done this correctly, you should see the FORD chart appear below the GM chart in it’s own separate region.
- Still on the GM chart, add “Pairs Trader 2” study.
- In the Study Settings, set the “Pair” field to reference the “GM” overlay we added previously. It should look something like this.
- Optionally, set Lines 1/2/3 to the # of Standard Deviations you want the study to plot.
That’s it, if all went well, you should be seeing something like the image below.
Length – the lookback length used in calculating the Standard Deviation and the Average. (Read note below On Length).
Pair – the instrument against which we want to pair.
Line1, Line2, Line3 – set the value at which to plot the horizontal lines
The study produces 7 subgraphs. One subgraph to plot the spread and three lines to plot SD lines as reference for the distance the spread has moved from the calculated average. Then we have 3 levels plotted as 6 lines; two for each level. These levels are the # of SD’s distance from the average. This provides a visual indication of how far the spread between the pair has diverged.
- Line1 Positive, Line1 Negative
- Line2 Positive, Line2 Negative
- Line3 Positive, Line3 Negative
In general, the length is left as an input value and can be changed. As a rule of thumb on this, look to use larger values – smaller values might look like they produce more trades and faster returns to the mean, but they are sometimes problematic in generating any profit. Take this as something to keep in mind. The final values needs to be determined by testing on historical data. If you don’t have a specific # you are looking to use, a good starting point is the default value (50).
For the pairs study, we need to overlay one pair over the other. There are generally 2 quick ways to do this using the built in Sierra Chart studies. It is usually more convenient to look at Pairs Trades using a single line as opposed to a bar type of chart. That said, both methods will work equally well and produce the exact same results. Also, the Study / Price Overlay study has some options for the cases that you need more control over how the overlay is executed by Sierra Chart.
Study / Price Overlay – produces a Candle Stick chart
Overlay (Single Line) – produces a Line chart