Cointegration in forex pairs trading is a valuable tool. For me, cointegration is the foundation for an excellent market-neutral mechanical trading strategy that allows me to profit in any economic environment. Whether a market is in an uptrend, downtrend or simply moving sideways, forex pairs trading allows me to harvest gains year-round.
A forex pairs trading strategy that utilizes cointegration is classified as a form of convergence trading based on statistical arbitrage and reversion to mean. This type of strategy was first popularized by a quantitative trading team at Morgan Stanley in the 1980s using stock pairs, although I and other traders have found it also works very well for forex pairs trading, too.
Forex pairs trading based on cointegration
Forex pairs trading based on cointegration is essentially a reversion-to-mean strategy. Stated simply, when two or more forex pairs are cointegrated, it means the price spread between the separate forex pairs tends to revert to its mean value consistently over time.
It’s important to understand that cointegration is not correlation. Correlation is a short-term relationship regarding co-movements of prices. Correlation means that individual prices move together. Although correlation is relied upon by some traders, by itself it’s an untrustworthy tool.
On the other hand, cointegration is a longer-term relationship with co-movements of prices, in which the prices move together yet within certain ranges or spreads, as if tethered together. I’ve found cointegration to be a very useful tool in forex pairs trading.
During my forex pairs trading, when the spread widens to a threshold value calculated by my mechanical trading algorithms, I “short” the spread between the pairs’ prices. In other words, I’m betting the spread will revert back toward zero due to their cointegration.
Basic forex pairs trading strategies are very simple, especially when using mechanical trading systems: I choose two different currency pairs which tend to move similarly. I buy the under-performing currency pair and sell the out-performing pair. When the spread between the two pairs converges, I close my position for a profit.
Forex pairs trading based on cointegration is a fairly market-neutral strategy. As an example, if a currency pair plummets, then the trade will probably result in a loss on the long side and an offsetting gain on the short side. So, unless all currencies and underlying instruments suddenly lose value, the net trade should be near zero in a worst-case scenario.
By the same token, pairs trading in many markets is a self-funding trading strategy, since the proceeds from short sales can sometimes be used to open the long position. Even without this benefit, cointegration-fueled forex pairs trading still works very well.
Understanding cointegration for forex pairs trading
Cointegration is helpful for me in forex pairs trading because it lets me program my mechanical trading system based on both short-term deviations from equilibrium prices as well as long-term price expectations, by which I mean corrections and returning to equilibrium.
To understand how cointegration-driven forex pairs trading works, it’s important to first define cointegration then describe how it functions in mechanical trading systems.
As I’ve said above, cointegration refers to the equilibrium relationship between sets of time series, such as prices of separate forex pairs that by themselves aren’t in equilibrium. Stated in mathematical jargon, cointegration is a technique for measuring the relationship between non-stationary variables in a time series.
If any two or more time series each have a root value equal to 1, but their linear combination is stationary, then they are said to be cointegrated.
As a simple example, consider the prices of a stock-market index and its related futures contract: Although the prices of each of these two instruments may wander randomly over brief periods of time, ultimately they will return to equilibrium, and their deviations will be stationary.
Here’s another illustration, stated in terms of the classic “random walk” example: Let’s say there are two individual drunks walking homeward after a night of carousing. Let’s further assume these two drunks don’t know each other, so there’s no predictable relationship between their individual pathways. Therefore, there is no cointegration between their movements.
In contrast, consider the idea that an individual drunk is wandering homeward while accompanied by his dog on a leash. In this case, there is a definite connection between the pathways of these two poor creatures.
Although each of the two is still on an individual pathway over a short period of time, and even though either one of the pair may randomly lead or lag the other at any given point in time, still, they will always be found close together. The distance between them is fairly predictable, thus the pair are said to be cointegrated.
Returning now to technical terms, if there are two non-stationary time series, such as a hypothetical set of currency pairs AB and XY, that become stationary when the difference between them is calculated, these pairs are called an integrated first-order series – also call an I(1) series.
Even though neither of these series stays at a constant value, if there is a linear combination of AB and XY that is stationary (described as I(0)), then AB and XY are cointegrated.
The above simple example consists of only two time series of hypothetical forex pairs. Yet, the concept of cointegration also applies to multiple time series, using higher integration orders… Think in terms of a wandering drunk accompanied by several dogs, each on a different-length leash.
In real-world economics, it’s easy to find examples showing cointegration of pairs: Income and spending, or harshness of criminal laws and size of prison population. In forex pairs trading, my focus is on capitalizing on the quantitative and predictable relationship between cointegrated pairs of currencies.
For example, let’s assume that I’m watching those two cointegrated hypothetical currency pairs, AB and XY, and the cointegrated relationship between them is AB – XY = Z, where Z equals a stationary series with a mean of zero, that is I(0).
This would seem to suggest a simple trading strategy: When AB – XY > V, and V is my threshold trigger price, then the forex pairs trading system would sell AB and buy XY, since the expectation would be for AB to decrease in price and XY to increase. Or, when AB – XY < -V, I would expect to buy AB and sell XY.
Avoid spurious regression in forex pairs trading
Yet, it’s not as simple as the above example would suggest. In practice, a mechanical trading system for forex pairs trading needs to calculate cointegration instead of just relying on the R-squared value between AB and XY.
That’s because ordinary regression analysis falls short when dealing with non-stationary variables. It causes so-called spurious regression, which suggests relationships between variables even when there aren’t any.
Suppose, for example, that I regress 2 separate “random walk” time series against each other. When I test to see if there’s a linear relationship, very often I will find high values for R-squared as well as low p-values. Still, there’s no relationship between these 2 random walks.
Formulas and testing for cointegration in forex pairs trading
The simplest test for cointegration is the Engle-Granger test, which works like this:
- Verify that ABt and XYt are both I(1)
- Calculate the cointegration relationship [XYt = aABt + et] by using the least-squares method
- Verify that the cointegration residuals et are stationary by using a unit-root test like the Augmented Dickey-Fuller (ADF) test
A detailed Granger equation:
ΔABt = α1(XYt-1 − βABt-1) +ut and ΔXYt = α2(XYt-1 − βABt-1) + vt
When XYt-1 − βABt-1 ~ I(0) describes the cointegration relationship.
XYt-1 − βABt-1 describes the extent of the disequilibrium away from the long-run, while αi is both the speed and direction at which the currency pair’s time series corrects itself from the disequilibrium.
When using the Engle-Granger method in forex pairs trading, the beta values of the regression are used to calculate the trade sizes for the pairs.
When using the Engle-Granger method in forex pairs trading, the beta values of the regression are used to calculate the trade sizes for the pairs.
Error correction for cointegration in forex pairs trading:
When using cointegration for forex pairs trading, it’s also helpful to account for how cointegrated variables adjust and return to the long-run equilibrium. So, for example, here are the two sample forex pairs’ time series shown autoregressively:
ABt = aABt-1 + bXYt-1 + ut and XYt = cABt-1 + dXYt-1 + vt
Forex pairs trading based on cointegration
When I use my mechanical trading system for forex pairs trading, the setup and execution are fairly simple. First, I find two currency pairs which seem like they may be cointegrated, such as EUR/USD and GBP/USD.
Then, I calculate the estimated spreads between the two pairs. Next, I check for stationarity using a unit-root test or another common method.
I make sure that my inbound data feed is working appropriately, and I let my mechanical trading algorithms create the trading signals. Assuming I’ve run adequate back-tests to confirm the parameters, I’m finally ready to use cointegration in my forex pairs trading.
I’ve found a MetaTrader indicator which offers an excellent starting point to build a cointegration forex pairs trading system. It looks like a Bollinger Band indicator, yet in fact the oscillator shows the price differential between the two different currency pairs.
When this oscillator moves toward either the high or low extreme, it indicates that the pairs are decoupling, which signals the trades.
Still, to be sure of success I rely on my well-built mechanical trading system to filter the signals with the Augmented Dickey-Fuller test before executing the appropriate trades.
Of course, anyone who wants to use cointegration for his or her forex pairs trading, yet lacks the requisite algo programming skills, can rely on an experienced programmer to create a winning expert advisor.
Through the magic of algorithmic trading, I program my mechanical trading system to define the price spreads based on data analysis. My algorithm monitors for price deviations, then automatically buys and sells currency pairs in order to harvest market inefficiencies.
Risks to be aware of when using cointegration with forex pairs trading
Forex pairs trading is not entirely risk-free. Above all, I keep in mind that forex pairs trading using cointegration is a mean-reversion strategy, which is based on the assumption that the mean values will be the same in the future as they were in the past.
Although the Augmented Dickey-Fuller test mentioned previously is helpful in validating the cointegrated relationships for forex pairs trading, it doesn’t mean that the spreads will continue to be cointegrated in the future.
I rely on strong risk management rules, which means that my mechanical trading system exits from unprofitable trades if or when the calculated reversion-to-mean is invalidated.
When the mean values change, it’s called drift. I try to detect drift as soon as possible. In other words, if the prices of previously-cointegrated forex pairs begin to move in a trend instead of reverting to the previously-calculated mean, it’s time for the algorithms of my mechanical trading system to recalculate the values.
When I use my mechanical trading system for forex pairs trading, I use the autoregressive formula mentioned earlier in this article in order to calculate a moving average to forecast the spread. Then, I exit the trade at my calculated error bounds.
Cointegration is a valuable tool for my forex pairs trading
Using cointegration in forex pairs trading is a market-neutral mechanical trading strategy that lets me trade in any market environment. It’s a smart strategy that’s based on reversion to mean, yet it helps me avoid the pitfalls of some of the other reversion-to-mean forex trading strategies.
Because of its potential use in profitable mechanical trading systems, cointegration for forex pairs trading has attracted interest from both professional traders as well as academic researchers.
There are plenty of recently-published articles, such as this quant-focused blog article, or this scholarly discussion of the subject, as well as plenty of discussion among traders.
Cointegration is a valuable tool in my forex pairs trading, and I highly recommend that you look into it for yourself.
Very good article. It is inspiring. Thanks for writing it!
Excellent article!
Correlation is also applied in stocks (equities). What is the difference? Can the above process be applied to stocks?
Thanks
Harish:
Yes, the same process can be applied to stocks as well as to derivatives. Since there is such a large universe of stocks when compared with forex pairs, there should be a larger number of potential opportunities for trading. With the number-crunching power of today’s trading systems, many sets of relationships can be examined quickly, in real time. Cointegration can also be used by options traders; it may be expected to produce results like the popular Coca Cola-Pepsi spreads in which the price relationships between certain stocks/options lets traders engage in fairly low-risk plays with a fairly good chance of winning.
Ed
Hi Eddie,
Do you trade intra day or over weeks using this strategy? Also, what programming language would you recommend. R does take time to run calculations and if it is intra day trade, latency comes into play.
Thanks,
Harish
The programming language doesn’t matter for end of day trading. Any major language like Perl, Python, C/C++ and C# is fine. R can be extremely fast but it slows down if it’s forced to dynamically allocate memory.
Harish:
I trade using daily charts, and I stay in most trades for a couple of days to a couple of weeks. Shaun is an expert programmer, and I always trust his judgment to use the best programming language to obtain the best results for a given trading strategy. In fact, Shaun can create a well-balanced, winning program to leverage cointegration and other factors as well. If you’d like a quote, please contact him directly at info@onestepremoved.com
Ed
Hi Eddie.
There is some interest in an implementation of this for MT4. If you can you provide some specifics on your implementation of this strategy in code, please send to czimmer@onestepremoved.com.
thanks
Chris
Hello Eddie,
I am doing a small project on cointegration strategies in FX for my MSc. I believe you ran cointegration tests on a lot of currency pairs. Which ones did you find to be statistically significantly cointegrated?
Thanks,
Sasha
Hi Sasha,
I don’t think Eddie actually ran the numbers. The article is intended to be an overall guide to the concept, but not quite to the point of being a bona fide strategy.
–Shaun
1) USD/JPY and EUR/CHF
2) EUR/PLN and EUR/HUF
3) USD/TRY and USD/ZAR
4) AUD/USD and NZD/USD
5) EUR/NOK and EUR/SEK
I know these ones are quite highly correlated, but that doesn’t imply cointegration.
Best,
Sasha
There are good forex pairs cointegrated:
– NZDUSD – USDCHF
– GBPUSD – NZDUSD
– EURGBP – EURNZD
I don’t thing USDJPY / EURCHF would be a cointegrated pair because there will not be a market-neutral strategy
Hi Camilo,
Thanks for sharing.
Has anyone implemented a backtest code using mean reversion strategy?
Should I ajust pip values between two forex pairs?
Has anyone added commission cost to backtest code and got profitable results?
I’m sure someone has, but it’s not something where you’re going to find an obvious answer on short term charts. You may find long term cointegrations, but that’s not research I’ve done.
The only cointegration is between EUR and CHF and between AUD and NZD since are the only intimate trade and economics between this countries and central banks are creating this cointegration.
Not EUR and GBP?
Hello Eddie. Excellent article. I have been back testing 10 years of charts thinking ” I can’t be the first person to have thought of this!” when I found this site. Thanks so much for writing this. I don’t feel quite so alone anymore. 🙂 Just wondering which broker you use or do you use multiple brokers. Thanks for your time.
Sincerely Robert J. Armagost
Hi Robert,
The main broker that I use is Pepperstone and STO (via TopTradr).
–Shaun
Hello Shaun I have been trading this strategy manually. Do have software to automate this? (So I don’t have to get up in the middle of the night anymore) Thanks for your time.
Not off the shelf, but it’s something that we can build. Shoot me an email with your entry and exit rules to get an estimate. info@onestepremoved.com
Robert — Thanks for your good feedback. Shaun has the right tools to implement this type of trading strategy, and I entirely agree with his broker recommendations, Thanks again for commenting! EF