{"id":1989641,"date":"2014-04-29T17:32:31","date_gmt":"2014-04-29T12:02:31","guid":{"rendered":"http:\/\/stockviz.biz\/index.php\/?p=1989641"},"modified":"2014-09-09T12:06:08","modified_gmt":"2014-09-09T06:36:08","slug":"finding-pairs-trade","status":"publish","type":"post","link":"https:\/\/stockviz.biz\/index.php\/2014\/04\/29\/finding-pairs-trade\/","title":{"rendered":"Finding Pairs to Trade"},"content":{"rendered":"<h3>Correlation<\/h3>\n<p>When we discussed banks and <a href=\"http:\/\/stockviz.biz\/index.php\/2014\/04\/28\/bank-nifty-vs-hdfc-bank-icici-bank\/\" target=\"_blank\">introduced pair trading<\/a>, we pointed out that a pairs trading strategy involves answering these questions:<\/p>\n<ol>\n<li>How do you identify &#8220;stocks that move together?&#8221;<\/li>\n<li>Should they be in the same industry?<\/li>\n<li>How far should they have to diverge before you enter the trade?<\/li>\n<li>When is a position unwound?<\/li>\n<\/ol>\n<p>Traders new to pair trading often mistake the correlation of prices to be indicative of &#8220;similarity&#8221;. For example, consider the Bank Nifty, HDFC Bank and ICICI bank. Here&#8217;s the chart of the closing price of the nearest to expiration futures contract:<\/p>\n<p><a href=\"http:\/\/portalvhds29z8xdrqhczq.blob.core.windows.net\/wordpress\/2014\/04\/bank-futures-prices.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1989651\" alt=\"bank-futures-prices\" src=\"http:\/\/portalvhds29z8xdrqhczq.blob.core.windows.net\/wordpress\/2014\/04\/bank-futures-prices.png\" width=\"1024\" height=\"768\" srcset=\"https:\/\/portalvhds29z8xdrqhczq.blob.core.windows.net\/wordpress\/2014\/04\/bank-futures-prices.png 1024w, https:\/\/portalvhds29z8xdrqhczq.blob.core.windows.net\/wordpress\/2014\/04\/bank-futures-prices-300x225.png 300w, https:\/\/portalvhds29z8xdrqhczq.blob.core.windows.net\/wordpress\/2014\/04\/bank-futures-prices-400x300.png 400w, https:\/\/portalvhds29z8xdrqhczq.blob.core.windows.net\/wordpress\/2014\/04\/bank-futures-prices-900x675.png 900w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/p>\n<p>And there are some really tight correlations:<\/p>\n<div class=\"row-fluid\">\n<div class=\"span8 offset2\">\n<table class=\"table table-condensed table-bordered\">\n<thead>\n<tr>\n<th><\/th>\n<th>BANKNIFTY<\/th>\n<th>HDFCBANK<\/th>\n<th>ICICIBANK<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>BANKNIFTY<\/td>\n<td>1.0000000<\/td>\n<td>0.7419966<\/td>\n<td>0.9462238<\/td>\n<\/tr>\n<tr>\n<td>HDFCBANK<\/td>\n<td>0.7419966<\/td>\n<td>1.0000000<\/td>\n<td>0.8327847<\/td>\n<\/tr>\n<tr>\n<td>ICICIBANK<\/td>\n<td>0.9462238<\/td>\n<td>0.8327847<\/td>\n<td>1.0000000<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>However, this is only part of the story. What we need are pairs who&#8217;s price <em>movements<\/em> are mean reverting. Looking at price correlation alone is not enough.<\/p>\n<h3>Spreads<\/h3>\n<p>We need the spread between pairs to be &#8220;stable&#8221;, i.e., mean reverting.<\/p>\n<p style=\"text-align: center\"><strong>spread = A &#8211; \u03b2B<\/strong><\/p>\n<p style=\"text-align: center\"><small>where A and B are prices and \u03b2 is the first regression coefficient.<\/small><\/p>\n<h5>200-day spreads<\/h5>\n<p>Here are the spreads between these pairs using 200-day data for regression:<\/p>\n<p><a href=\"http:\/\/portalvhds29z8xdrqhczq.blob.core.windows.net\/wordpress\/2014\/04\/BANKNIFTY-ICICIBANK-Spread-200.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1989661\" alt=\"BANKNIFTY - ICICIBANK Spread 200\" src=\"http:\/\/portalvhds29z8xdrqhczq.blob.core.windows.net\/wordpress\/2014\/04\/BANKNIFTY-ICICIBANK-Spread-200.png\" width=\"640\" height=\"480\" srcset=\"https:\/\/portalvhds29z8xdrqhczq.blob.core.windows.net\/wordpress\/2014\/04\/BANKNIFTY-ICICIBANK-Spread-200.png 640w, https:\/\/portalvhds29z8xdrqhczq.blob.core.windows.net\/wordpress\/2014\/04\/BANKNIFTY-ICICIBANK-Spread-200-300x225.png 300w, https:\/\/portalvhds29z8xdrqhczq.blob.core.windows.net\/wordpress\/2014\/04\/BANKNIFTY-ICICIBANK-Spread-200-400x300.png 400w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><\/a><\/p>\n<p><a href=\"http:\/\/portalvhds29z8xdrqhczq.blob.core.windows.net\/wordpress\/2014\/04\/BANKNIFTY-HDFCBANK-Spread-200.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1989681\" alt=\"BANKNIFTY - HDFCBANK Spread 200\" src=\"http:\/\/portalvhds29z8xdrqhczq.blob.core.windows.net\/wordpress\/2014\/04\/BANKNIFTY-HDFCBANK-Spread-200.png\" width=\"640\" height=\"480\" srcset=\"https:\/\/portalvhds29z8xdrqhczq.blob.core.windows.net\/wordpress\/2014\/04\/BANKNIFTY-HDFCBANK-Spread-200.png 640w, https:\/\/portalvhds29z8xdrqhczq.blob.core.windows.net\/wordpress\/2014\/04\/BANKNIFTY-HDFCBANK-Spread-200-300x225.png 300w, https:\/\/portalvhds29z8xdrqhczq.blob.core.windows.net\/wordpress\/2014\/04\/BANKNIFTY-HDFCBANK-Spread-200-400x300.png 400w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><\/a><\/p>\n<p><a href=\"http:\/\/portalvhds29z8xdrqhczq.blob.core.windows.net\/wordpress\/2014\/04\/ICICIBANK-HDFCBANK-Spread-200.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1989671\" alt=\"ICICIBANK - HDFCBANK Spread 200\" src=\"http:\/\/portalvhds29z8xdrqhczq.blob.core.windows.net\/wordpress\/2014\/04\/ICICIBANK-HDFCBANK-Spread-200.png\" width=\"640\" height=\"480\" srcset=\"https:\/\/portalvhds29z8xdrqhczq.blob.core.windows.net\/wordpress\/2014\/04\/ICICIBANK-HDFCBANK-Spread-200.png 640w, https:\/\/portalvhds29z8xdrqhczq.blob.core.windows.net\/wordpress\/2014\/04\/ICICIBANK-HDFCBANK-Spread-200-300x225.png 300w, https:\/\/portalvhds29z8xdrqhczq.blob.core.windows.net\/wordpress\/2014\/04\/ICICIBANK-HDFCBANK-Spread-200-400x300.png 400w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><\/a><\/p>\n<h5>50-day spreads<\/h5>\n<p>Here are the spreads between these pairs using 50-day data for regression:<\/p>\n<p><a href=\"http:\/\/portalvhds29z8xdrqhczq.blob.core.windows.net\/wordpress\/2014\/04\/BANKNIFTY-ICICIBANK-Spread-50.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1989701\" alt=\"BANKNIFTY - ICICIBANK Spread 50\" src=\"http:\/\/portalvhds29z8xdrqhczq.blob.core.windows.net\/wordpress\/2014\/04\/BANKNIFTY-ICICIBANK-Spread-50.png\" width=\"640\" height=\"480\" srcset=\"https:\/\/portalvhds29z8xdrqhczq.blob.core.windows.net\/wordpress\/2014\/04\/BANKNIFTY-ICICIBANK-Spread-50.png 640w, https:\/\/portalvhds29z8xdrqhczq.blob.core.windows.net\/wordpress\/2014\/04\/BANKNIFTY-ICICIBANK-Spread-50-300x225.png 300w, https:\/\/portalvhds29z8xdrqhczq.blob.core.windows.net\/wordpress\/2014\/04\/BANKNIFTY-ICICIBANK-Spread-50-400x300.png 400w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><\/a><\/p>\n<p><a href=\"http:\/\/portalvhds29z8xdrqhczq.blob.core.windows.net\/wordpress\/2014\/04\/BANKNIFTY-HDFCBANK-Spread-50.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1989691\" alt=\"BANKNIFTY - HDFCBANK Spread 50\" src=\"http:\/\/portalvhds29z8xdrqhczq.blob.core.windows.net\/wordpress\/2014\/04\/BANKNIFTY-HDFCBANK-Spread-50.png\" width=\"640\" height=\"480\" srcset=\"https:\/\/portalvhds29z8xdrqhczq.blob.core.windows.net\/wordpress\/2014\/04\/BANKNIFTY-HDFCBANK-Spread-50.png 640w, https:\/\/portalvhds29z8xdrqhczq.blob.core.windows.net\/wordpress\/2014\/04\/BANKNIFTY-HDFCBANK-Spread-50-300x225.png 300w, https:\/\/portalvhds29z8xdrqhczq.blob.core.windows.net\/wordpress\/2014\/04\/BANKNIFTY-HDFCBANK-Spread-50-400x300.png 400w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><\/a><\/p>\n<p><a href=\"http:\/\/portalvhds29z8xdrqhczq.blob.core.windows.net\/wordpress\/2014\/04\/ICICIBANK-HDFCBANK-Spread-50.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1989711\" alt=\"ICICIBANK - HDFCBANK Spread 50\" src=\"http:\/\/portalvhds29z8xdrqhczq.blob.core.windows.net\/wordpress\/2014\/04\/ICICIBANK-HDFCBANK-Spread-50.png\" width=\"640\" height=\"480\" srcset=\"https:\/\/portalvhds29z8xdrqhczq.blob.core.windows.net\/wordpress\/2014\/04\/ICICIBANK-HDFCBANK-Spread-50.png 640w, https:\/\/portalvhds29z8xdrqhczq.blob.core.windows.net\/wordpress\/2014\/04\/ICICIBANK-HDFCBANK-Spread-50-300x225.png 300w, https:\/\/portalvhds29z8xdrqhczq.blob.core.windows.net\/wordpress\/2014\/04\/ICICIBANK-HDFCBANK-Spread-50-400x300.png 400w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><\/a><\/p>\n<h3>Testing for cointegration<\/h3>\n<p>You don&#8217;t have to visually inspect spreads to see if they are mean-reverting. The most straightforward way of checking if a time-series is co-integrated is to perform a Dickey-Fuller test on it. If the p-value is less than 0.10, then this could be a good pair for trading.<\/p>\n<div class=\"row-fluid\">\n<div class=\"span8 offset2\">\n<table class=\"table table-bordered table-condensed\">\n<thead>\n<tr>\n<th>N<\/th>\n<th>Pair<\/th>\n<th>p-value<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>300<\/td>\n<td>BANKNIFTY vs. ICICIBANK<\/td>\n<td><strong>0.010000<\/strong><\/td>\n<\/tr>\n<tr>\n<td>300<\/td>\n<td>BANKNIFTY vs. HDFCBANK<\/td>\n<td>0.904480<\/td>\n<\/tr>\n<tr>\n<td>300<\/td>\n<td>ICICIBANK vs. HDFCBANK<\/td>\n<td>0.407347<\/td>\n<\/tr>\n<tr>\n<td>200<\/td>\n<td>BANKNIFTY vs. ICICIBANK<\/td>\n<td><strong>0.010000<\/strong><\/td>\n<\/tr>\n<tr>\n<td>200<\/td>\n<td>BANKNIFTY vs. HDFCBANK<\/td>\n<td>0.472129<\/td>\n<\/tr>\n<tr>\n<td>200<\/td>\n<td>ICICIBANK vs. HDFCBANK<\/td>\n<td><strong>0.037115<\/strong><\/td>\n<\/tr>\n<tr>\n<td>100<\/td>\n<td>BANKNIFTY vs. ICICIBANK<\/td>\n<td>0.223806<\/td>\n<\/tr>\n<tr>\n<td>100<\/td>\n<td>BANKNIFTY vs. HDFCBANK<\/td>\n<td>0.980776<\/td>\n<\/tr>\n<tr>\n<td>100<\/td>\n<td>ICICIBANK vs. HDFCBANK<\/td>\n<td>0.670717<\/td>\n<\/tr>\n<tr>\n<td>50<\/td>\n<td>BANKNIFTY vs. ICICIBANK<\/td>\n<td>0.429057<\/td>\n<\/tr>\n<tr>\n<td>50<\/td>\n<td>BANKNIFTY vs. HDFCBANK<\/td>\n<td>0.405498<\/td>\n<\/tr>\n<tr>\n<td>50<\/td>\n<td>ICICIBANK vs. HDFCBANK<\/td>\n<td>0.133357<\/td>\n<\/tr>\n<tr>\n<td>30<\/td>\n<td>BANKNIFTY vs. ICICIBANK<\/td>\n<td>0.570427<\/td>\n<\/tr>\n<tr>\n<td>30<\/td>\n<td>BANKNIFTY vs. HDFCBANK<\/td>\n<td><strong>0.057717<\/strong><\/td>\n<\/tr>\n<tr>\n<td>30<\/td>\n<td>ICICIBANK vs. HDFCBANK<\/td>\n<td>0.370011<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>If you are trading futures, then a 200-day fit may not make much sense. The latest 30-day test between BANKNIFTY and HDFCBANK has a surprisingly low p-value of 0.057, indicating that there is a potential trade there.<\/p>\n<p><em>To be continued&#8230;<\/em><\/p>\n<h6 class=\"zemanta-related-title\" style=\"font-size: 1em\">Related articles<\/h6>\n<ul class=\"zemanta-article-ul\">\n<li class=\"zemanta-article-ul-li\"><a href=\"http:\/\/stockviz.biz\/2014\/04\/28\/bank-nifty-vs-hdfc-bank-icici-bank\/\">Bank Nifty vs. HDFC Bank and ICICI Bank<\/a> (stockviz.biz)<\/li>\n<\/ul>\n<div class=\"zemanta-pixie\" style=\"margin-top: 10px;height: 15px\"><img decoding=\"async\" class=\"zemanta-pixie-img\" style=\"border: none;float: right\" alt=\"\" src=\"http:\/\/img.zemanta.com\/pixy.gif?x-id=0c493193-22c4-4a60-aad6-dd096d7ab289\" \/><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Correlation When we discussed banks and introduced pair trading, we pointed out that a pairs trading strategy involves answering these questions: How do you identify &#8220;stocks that move together?&#8221; Should they be in the same industry? How far should they have to diverge before you enter the trade? When is a position unwound? Traders new &hellip; <\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3471,9],"tags":[3371,2761],"class_list":["post-1989641","post","type-post","status-publish","format-standard","hentry","category-investing-insight","category-your-money","tag-pair-trading","tag-quant","entry"],"_links":{"self":[{"href":"https:\/\/stockviz.biz\/index.php\/wp-json\/wp\/v2\/posts\/1989641","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/stockviz.biz\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/stockviz.biz\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/stockviz.biz\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/stockviz.biz\/index.php\/wp-json\/wp\/v2\/comments?post=1989641"}],"version-history":[{"count":0,"href":"https:\/\/stockviz.biz\/index.php\/wp-json\/wp\/v2\/posts\/1989641\/revisions"}],"wp:attachment":[{"href":"https:\/\/stockviz.biz\/index.php\/wp-json\/wp\/v2\/media?parent=1989641"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/stockviz.biz\/index.php\/wp-json\/wp\/v2\/categories?post=1989641"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/stockviz.biz\/index.php\/wp-json\/wp\/v2\/tags?post=1989641"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}