www.diversifyportfolio.com - Entries for the tag Cointegrationhttp://www.diversifyportfolio.com/blog/tags/Cointegration/The last entries tagged with Cointegrationen-usZinniaTue, 24 Oct 2017 07:47:50 +0000Pair Trading Statistics
http://www.diversifyportfolio.com/blog/2017/07/18/pair-trading-statistics/<p>If you're planning on pair trading, it's important that you have at least a general understanding of the statistics that are used. This article gives an overview of some of the key statistics used in pair trading and what to look for when analyzing them.</p>
<h3>Overview</h3>
<p>
This article is the third in a multi-part series on pair trading. If you're new to pair trading, we suggest you read the first two articles
in this series before continuing with this one. The prior articles explain the basics of what pair trading is and the difference
between correlation and cointegration. Article 1 is <a href="/blog/2017/04/18/what-pair-trading/" target="_blank">here</a>. Article 2 is
<a href="/blog/2017/05/09/stock-correlation-vs-cointegration/" target="_blank">here</a>.
</p>
<p>
This article is not meant to be an depth analysis of the statistics used for pair trading but is rather aimed at traders and investors
who want enough of an understanding of the key concepts to be able to apply them in their own trading. All of the statistics
discussed are computed automatically for users of our <a href="/pair-trading/" target="_blank">pair analysis platform</a>.
</p>
<p>
For each statistic we first provide a definition and overview of the concept before providing a practical application of it.
</p>
<h3>Cointegration</h3>
<p>
First and foremost when dealing with pair trading we are looking for pairs that are cointegrated.
<a class="dphiddenlink" href="https://www.quantopian.com/posts/how-to-build-a-pairs-trading-strategy-on-quantopian">Cointegration</a> as discussed in the prior article, is an indication of
stationarity. Said another way, a pair of stocks is said to be cointegrated if the spread between them is stationary.
</p>
<p>
For the spread to be stationary, the mean and standard deviation need to be constant over time. In other words, at any point in time
the current value of the spread can be drawn from the same probability distribution.
</p>
<h3>P-Value</h3>
<p>
The p-value provides a way to test for cointegration. P values are used to determine the statistical significance of a hypothesis test.
The hypothesis in this case is determining if a pair of stocks is cointegrated.
</p>
<p>
Typically you're going to want a p-value of less than 0.05. Anything above that is typically not good enough to qualify for pair trading.
</p>
<h3>Test Statistic</h3>
<p>
The test statistic and the p-value go hand in hand. When calculating a test statistic, you're generally trying to find evidence of a
significant difference between population means or between the population mean and a hypothesized value.
</p>
<p>
In terms of stock pairs, the test statistic measures the size of the difference relative to the variation in the spread data. Once you
have a test statistic, you need to compare it in relation to the critical values (discussed next).
</p>
<h3>Critical Values</h3>
<p>
Critical values are essentially cut-off values for specific confidence levels. For example we provide confidence levels of 1%, 5% and 10%
in our <a href="/pair-trading/" target="_blank">pair analysis platform</a>. Depending on the confidence level that you're looking at, the goal for a
cointegrated pair is to have a test statistic lower than the critical value associated with that confidence level.
</p>
<p>
The critical values and test statistic provide us with the level of confidence as to whether or not a stock pair is in fact cointegrated.
For example in the following screenshot we have a test statistic that is lower than the critical value at the 10% confidence level.
However it is higher than the 5% and 1% critical values.
</p>
<img src="/media/uploads/zinnia/2017/07/18/stats.png"/>
<p>
Typically you're going to want a test statistic that is lower than the critical value at the 5% confidence level. In practical terms,
if you were analyzing two stocks that produced the above results, you would typically <b>not</b> trade this pair.
</p>
<h3>Hedge Ratio</h3>
<p>
The hedge ratio (also known as beta) is calculated by performing an ordinary least squares regression on the spread data. The hedge
ratio provides the ratio of shares necessary to produce a cointegrated and therefore stationary pair.
</p>
<p>
In practical terms, we are always trading stocks that have different prices and volatility. If we find a pair that is cointegrated and
looks to be a good candidate for pair trading, it would be inaccurate to simply enter equal position sizes in both stocks. In other words,
short 50 shares of stock A and long 50 shares of stock B.
</p>
<p>
The reason for this is that based on the attributes of the spread and cointegration analysis, the pair would only be cointegrated if a
specific ratio of shares is used. If you simply enter the same position sizes in both shares, then you are no longer trading a pair that is
cointegrated in the true sense of the term.
</p>
<p>
For example, if a hedge ratio of 2.5 is computed that means that each share of stock A should be combined with 2.5 shares of stock B. If you
decide to enter 100 shares of stock A, then you would need to offset that with 250 shares of stock B.
</p>
<h3>Half Life</h3>
<p>
Half life indicates how long the spread typically takes to revert back to the mean. A half life of 10 days for example indicates that this
pair typically takes 10 days to revert.
</p>
<p>
Generally speaking, you would look to stay in a pair trade until one of the following happens:
</p>
<ul>
<li>Your profit targets are reached</li>
<li>The spread has reverted back to the mean</li>
<li>You've been in the trade for the period of the half life (even if you haven't reached your profit target or stop loss)</li>
<li>You reach your stop loss</li>
</ul>
<h3>Z-Score</h3>
<p>
The Z-score is the number of standard deviations that the pair ratio has diverged from its mean. For a pair that is cointegrated, you will
typically see the z-score bounce around 0 as per the following screenshot:
</p>
<img src="/media/uploads/zinnia/2017/07/18/zscore.png"/>
<p>
The z-score is often used in trading strategies for entry and exit signals. We discuss one such strategy in a future article in this series.
</p>
<h3>Pair Stress</h3>
<p>
The stress indicator was originally developed by <a class="dphiddenlink" href="http://perrykaufman.com">Perry Kaufman</a> who is well known in
the professional algorithmic trading space. We provide users with the stress indicator as a way to easily see when a pairs spread has reached
an extreme and to create pair trading strategies around that information.
</p>
<p>
As per the below screenshot, the chart displays the stochastic value of two stocks over time with the difference between them shaded in grey. The
stress indicator goes up when the spread between the two stocks reaches an extreme. Along with the z-score discussed above, real pair trading
strategies using the stress indicator are discussed in future articles in this series.
</p>
<img src="/media/uploads/zinnia/2017/07/18/stress.png"/>
<h3>Final Thoughts</h3>
<p>
Pair trading can be overwhelming at first due to the statistics involved. However with a basic understanding of them along with
<a href="/pair-trading/" target="_blank">tools</a> that calculate everything for you, pair trading can be an excellent addition to your portfolio.
</p>
<p>
Pair trading provides a unique way to profit in markets regardless of overall direction. This means you can profit if the market goes up,
down or simply stays in a range.
</p>
<p>
Future articles in this series discuss actual trading strategies that use the z-score and stress indicator. The final article wraps everything
up with a beginning to end process for pair trading which includes how to find opportunities, managing watch lists, entering trades and when to
exit them.
</p>
<h3>Free Trial</h3>
<p>
If you aren't already a member, you can sign up for a free trial <a href="/member/register">here</a>.
</p>
<h4>Stay Informed</h4>
<p>
Stay informed by <a href="#" data-toggle="modal" data-target="#newsletterModal">joining our mailing list</a> where you'll receive strategy, diversification and education related articles.
</p>
<ul class="list-inline">
<li>
<a href="https://www.facebook.com/diversifyportfolio">
<span class="fa-stack icon-facebook">
<i class="fa fa-facebook fa-stack-1x"></i>
</span>
</a>
</li>
<li>
<a href="https://www.twitter.com/divportfolio"><i class="fa fa-twitter fa-2x" aria-hidden="true"></i></a>
</li>
</ul>
brendon@diversifyportfolio.com (DiversifyPortfolio)Tue, 18 Jul 2017 12:39:34 +0000http://www.diversifyportfolio.com/blog/2017/07/18/pair-trading-statistics/Analysis ToolsEducationStock Correlation vs Cointegration
http://www.diversifyportfolio.com/blog/2017/05/09/stock-correlation-vs-cointegration/<p>Understanding the difference between correlation and cointegration is critical if you intend to pair trade stocks. Not knowing the difference is a sure fire way to mount up losses in your account.</p>
<img src="/media/uploads/zinnia/2017/05/09/facebook_ad.png"/>
<p>
This article is the second installment of a multi part series covering pair trading. We encourage you to read the <a href="/blog/2017/04/18/what-pair-trading/" target="_blank">first article here</a> before continuing with this one. Each article builds on knowledge learnt in the prior one.
</p>
<p>
Also, If you aren't already familiar with the concept of stock correlation, please read through
<a href="/blog/2017/02/20/what-correlation/" target="_blank">this article</a> before continuing with this one. To summarize stock correlation briefly, it is a statistic that quantifies the tendency of two stocks to move in relation to each other.
</p>
<h3>Pair Trading - What makes a good pair?</h3>
<p>
In pair trading, we are looking at trading the spread between the prices of two stocks. In other words if one stock has been very strong recently and another has been very weak, that means the spread between the two stocks has widened. A pair trade would involve buying the weaker stock and shorting the stronger one.
</p>
<p>
It should come as no surprise that you can't simply choose any two stocks for a pair trade. <b>You need to have some level of confidence that if the spread widens between two stocks, it will narrow once again.</b>
</p>
<p>
There are two requirements that need to be met in order for two stocks to be combined in a pair trade:
</p>
<ul>
<li>
<b>Fundamental Connection:</b> The stocks need to have a reason to move together that makes logical sense. For example, perhaps there are two companies that operate in the same industry with a large degree of overlap between their businesses. Perhaps there are two ETF's that track similar underlying components. Perhaps a single company has stock listed on more than one exchange or has an A-Class and B-Class of shares listed.
</li>
<li>
<b>Cointegrated:</b> The two stocks have been statistically shown to be cointegrated.
</li>
</ul>
<h3>What is Cointegration?</h3>
<p>
Cointegration can best be described using the common explanation of a drunk man walking home with his dog. As the drunk man leaves the bar he clips a leash onto his dog's collar so they can walk home together. Since the man is drunk, he walks in random directions. During this time the dog is free to walk only so far as the length of the leash will allow. The man and the dog can be said to be cointegrated.
</p>
<p>
In terms of two stocks, they are said to be cointegrated if some linear combination of the stocks varies around a mean. In simpler terms, the stocks don't wander off in different directions for very long before reverting back to their typical spread. Said one last way, the spread between the stocks does not widen indefinitely, but rather reaches an extreme before narrowing once again.
</p>
<p>
The below chart illustrates this concept. As you can see the spread tends to hover around the two yellow lines. There are 3 notable times when it widens significantly, but after a short period of time it narrows once again.
</p>
<img src="/media/uploads/zinnia/2017/05/09/spread.png"/>
<h3>How is this different from Correlation?</h3>
<p>
Correlation measures the extent to which two stocks move in relation to each other:
</p>
<ul>
<li>
If <b>Stock A</b> always moves up when <b>Stock B</b> moves up then the stocks have a perfectly positive correlation.
</li>
<li>
If <b>Stock A</b> always moves down when <b>Stock B</b> moves up then the stocks have a perfectly negative correlation.
</li>
</ul>
<p>
Notice that there is no mention of the spread between the two. It is simply a case of - do the stocks move in the same or different directions simultaneously.
</p>
<p>
The following chart is of two hypothetical stocks that are perfectly correlated:
</p>
<img src="/media/uploads/zinnia/2017/05/09/correlation.png"/>
<p>
Both stocks are always moving in the same direction which means they have a perfect positive correlation. However, notice how the spread between the stocks continues to widen. The stocks never reach a point where their prices narrow back towards each other. <b>This is the key difference between correlation and cointegration.</b>
</p>
<p>
If we were to use correlation for our pair trading analysis we may think that the above pair would be an excellent choice. We would go ahead and short the stronger stock and buy the weaker stock. Unfortunately, the spread between the two never narrows and we would continue losing money.
</p>
<p>
The above scenario is why we focus on cointegration when dealing with pair trading. The aim is to trade stocks whose spreads revert to a mean, thus allowing us to short the one and buy the other resulting in a profit.
</p>
<h3>Common Misperception</h3>
<p>
It is alarming how often people talk about correlation in the context of pair trading with no reference to cointegration. Many popular financial websites and financial media channels talk about pair trading highly correlated stocks. This is dangerous and misinformed.
</p>
<p>
Correlation and cointegration are both powerful tools to use in your trading, but it is important that you use them where appropriate and in the right context.
</p>
<h3>Final Thoughts</h3>
<p>
Pair trading has long been a popular strategy used in hedge funds, trading firms and quant algorithms. With an understanding of cointegration along with the other topics that will be discussed in this series, you will have the knowledge, strategies and tools required to add pair trading to your arsenal.
</p>
<p>
<a href="/pair-trading/">Our pair trading tool</a> performs all of the required statistical analysis for you on any pair of stocks, presenting the resulting charts and stats in an intuitive format. After identifying viable pair trading candidates, you can save them to your watch list which will automatically update all the relevant stats on a daily basis. You simply wait until an entry or exit signal occurs before taking action.
<p>
<h4>Stay Informed</h4>
<p>
Stay informed by <a href="#" data-toggle="modal" data-target="#newsletterModal">joining our mailing list</a> where you'll receive strategy,
diversification and educational articles to help maximize your profit in the stock market while minimizing your risk.
</p>
<ul class="list-inline">
<li>
<a href="https://www.facebook.com/diversifyportfolio">
<span class="fa-stack icon-facebook">
<i class="fa fa-facebook fa-stack-1x"></i>
</span>
</a>
</li>
<li>
<a href="https://www.twitter.com/divportfolio"><i class="fa fa-twitter fa-2x" aria-hidden="true"></i></a>
</li>
</ul>
<h4>Disclaimer</h4>
<p>
DiversifyPortfolio does not make trading or investing recommendations. This article, as well as all the content and analysis tools on DiversifyPortfolio are published as a research and informational service. Please refer to our <a href="https://www.diversifyportfolio.com/disclaimer/">Disclaimer</a>.
</p>
brendon@diversifyportfolio.com (DiversifyPortfolio)Tue, 09 May 2017 13:30:49 +0000http://www.diversifyportfolio.com/blog/2017/05/09/stock-correlation-vs-cointegration/Analysis ToolsEducationStrategyPair Trade of the Week
http://www.diversifyportfolio.com/blog/2017/03/02/pair-trade-week/<p>The two stock market ETF's $EWC (Canada) and $EWA (Australia) are a well known pair often used in pair trading. The 60 day stress indicator of this pair is currently at its most extreme level since November last year and is therefore worth keeping an eye on.</p>
<h3>Finding stocks to pair trade</h3>
<p>
When it comes to pair trading it's always important to have logical, fundamental reasons for choosing the stocks that make up a pair trade. Doing cointegration and stationarity tests across hundreds of stocks will reveal many potential pair trading candidates but this opens you up to what's known as <i>'multiple comparisons bias'</i>. What this means is that by randomly looking at hundreds of possible stocks to pair trade, you will inevitably uncover stocks that indicate that they are statistically suited to pair trading by pure chance and as a result of the large sample size.
</p>
<p>
A far better approach is to come up with a hypothesis with respect to potential stocks to pair trade and then test whether or not your hypothesis is correct. In other words, determine if there is a logical, fundamental reason why two stocks may be viable pair trading candidates and then perform the necessary statistical analysis to confirm or disprove your suspicions.
</p>
<p>
With the above in mind, a common method of finding potential pair trades is to look for ETF's that track similar characteristics. $EWC and $EWA for example track a basket of Canadian and Australian equities, with both countries being heavily commodity based.
</p>
<h3>Statistics</h3>
<p>
As can be seen in the below screenshot, $EWC and $EWA have proved to be viable pair trading ETF's over the past 3 years.
</p>
<img src="/media/uploads/zinnia/2017/03/02/stats.png"/>
<h3>Setup</h3>
<p>
Once two stocks have been shown to be viable for pair trading both from a logical, fundamental viewpoint and from a statistcal one, it comes time to look for entry and exit setups. The 60 days stress indicator for the $EWC / $EWA pair is currently at its most extreme since November last year. Add to this the fact that $EWC has had a large price drop over the last few days and is currently trading at what may potentially be a key price level.
</p>
<img src="/media/uploads/zinnia/2017/03/02/stress.png"/>
<img src="/media/uploads/zinnia/2017/03/02/EWA.png"/>
<img src="/media/uploads/zinnia/2017/03/02/EWC.png"/>
<h3>Understanding</h3>
<p>
For those new to pair trading, there are many concepts and metrics which require understanding. DiversifyPortfolio will be publishing educational articles over time that explain key concepts related to pair trading and how to apply those concepts to the tools provided to our members.
</p>
<ul class="list-inline">
<li>
Stay informed by following us:
</li>
<li>
<a href="https://www.facebook.com/diversifyportfolio">
<span class="fa-stack icon-facebook">
<i class="fa fa-facebook fa-stack-1x"></i>
</span>
</a>
</li>
<li>
<a href="https://www.twitter.com/divportfolio"><i class="fa fa-twitter fa-2x" aria-hidden="true"></i></a>
</li>
<li>
<a href="/blog/feeds/"><i class="fa fa-rss fa-2x" aria-hidden="true"></i></a>
</li>
</ul>
<p>
For more articles on strategy, tips, education and stock market analysis - <a href="#" data-toggle="modal" data-target="#newsletterModal">click here to subscribe to our free newsletter</a>
</p>
<h4>Disclaimer</h4>
<p>
DiversifyPortfolio does not make trading or investing recommendations. This article, as well as all the content and analysis tools on DiversifyPortfolio is published as a research and informational service. Please refer to our <a href="https://www.diversifyportfolio.com/disclaimer/">Disclaimer</a>.
</p>
brendon@diversifyportfolio.com (DiversifyPortfolio)Thu, 02 Mar 2017 13:56:35 +0000http://www.diversifyportfolio.com/blog/2017/03/02/pair-trade-week/Market Observations