{"id":2022351,"date":"2015-05-08T20:53:08","date_gmt":"2015-05-08T15:23:08","guid":{"rendered":"http:\/\/stockviz.biz\/index.php\/?p=2022351"},"modified":"2015-05-08T20:53:08","modified_gmt":"2015-05-08T15:23:08","slug":"machine-learning-long-short-trend-following","status":"publish","type":"post","link":"https:\/\/stockviz.biz\/index.php\/2015\/05\/08\/machine-learning-long-short-trend-following\/","title":{"rendered":"Machine Learning Long-Short Trend Following"},"content":{"rendered":"<h3>Introduction<\/h3>\n<p>Our <a href=\"https:\/\/stockviz.biz\/index.php\/2015\/04\/30\/long-short-trend-following\/\" title=\"Long-Short Trend Following\" target=\"_blank\">previous post<\/a> discussed how a simple <em>SMA On\/Off Switch<\/em> based tactical algo can be enhanced by a volatility metric. We generated significant alpha by following a simple rule: <\/p>\n<div class=\"row-fluid well well-small\">\nGo short if either or the volatility signal or the 50-DMA indicates a negative bias and long otherwise.\n<\/div>\n<p>But what if we trained a machine on the same data and allowed it to decide when to go long and short?<\/p>\n<h3>Support Vector Machines<\/h3>\n<p>We fed an SVM our volatility metric and the percentage distance from 50-day SMA. A 5-year training set was used to predict the next year daily long\/short. We will not delve into the details of how SVMs work, <a href=\"http:\/\/en.wikipedia.org\/wiki\/Support_vector_machine\" target=\"_blank\">Wikipedia<\/a> does a decent job introducing the concept. <\/p>\n<h3>Performance<\/h3>\n<p>To make it easier to compare, we plot the wealth-charts for the NIFTY and BANKNIFTY indices side-by-side. <\/p>\n<p>The black line is the Machine Learning Long-Short Model and the blue line is buy-and-hold. NIFTY and BANKNIFTY since 2011:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/portalvhds29z8xdrqhczq.blob.core.windows.net\/wordpress\/2015\/05\/nifty.machine.learning.2011.png\" alt=\"nifty.machine.learning.2011\" width=\"1200\" height=\"800\" class=\"alignnone size-full wp-image-2022371\" srcset=\"https:\/\/portalvhds29z8xdrqhczq.blob.core.windows.net\/wordpress\/2015\/05\/nifty.machine.learning.2011.png 1200w, https:\/\/portalvhds29z8xdrqhczq.blob.core.windows.net\/wordpress\/2015\/05\/nifty.machine.learning.2011-300x200.png 300w, https:\/\/portalvhds29z8xdrqhczq.blob.core.windows.net\/wordpress\/2015\/05\/nifty.machine.learning.2011-1024x683.png 1024w, https:\/\/portalvhds29z8xdrqhczq.blob.core.windows.net\/wordpress\/2015\/05\/nifty.machine.learning.2011-450x300.png 450w, https:\/\/portalvhds29z8xdrqhczq.blob.core.windows.net\/wordpress\/2015\/05\/nifty.machine.learning.2011-900x600.png 900w\" sizes=\"auto, (max-width: 1200px) 100vw, 1200px\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/portalvhds29z8xdrqhczq.blob.core.windows.net\/wordpress\/2015\/05\/banknifty.machine.learning.2011.png\" alt=\"banknifty.machine.learning.2011\" width=\"1200\" height=\"800\" class=\"alignnone size-full wp-image-2022361\" srcset=\"https:\/\/portalvhds29z8xdrqhczq.blob.core.windows.net\/wordpress\/2015\/05\/banknifty.machine.learning.2011.png 1200w, https:\/\/portalvhds29z8xdrqhczq.blob.core.windows.net\/wordpress\/2015\/05\/banknifty.machine.learning.2011-300x200.png 300w, https:\/\/portalvhds29z8xdrqhczq.blob.core.windows.net\/wordpress\/2015\/05\/banknifty.machine.learning.2011-1024x683.png 1024w, https:\/\/portalvhds29z8xdrqhczq.blob.core.windows.net\/wordpress\/2015\/05\/banknifty.machine.learning.2011-450x300.png 450w, https:\/\/portalvhds29z8xdrqhczq.blob.core.windows.net\/wordpress\/2015\/05\/banknifty.machine.learning.2011-900x600.png 900w\" sizes=\"auto, (max-width: 1200px) 100vw, 1200px\" \/><\/p>\n<p>NIFTY and BANKNIFTY since 2013:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/portalvhds29z8xdrqhczq.blob.core.windows.net\/wordpress\/2015\/05\/nifty.machine.learning.2013.png\" alt=\"nifty.machine.learning.2013\" width=\"1200\" height=\"800\" class=\"alignnone size-full wp-image-2022391\" srcset=\"https:\/\/portalvhds29z8xdrqhczq.blob.core.windows.net\/wordpress\/2015\/05\/nifty.machine.learning.2013.png 1200w, https:\/\/portalvhds29z8xdrqhczq.blob.core.windows.net\/wordpress\/2015\/05\/nifty.machine.learning.2013-300x200.png 300w, https:\/\/portalvhds29z8xdrqhczq.blob.core.windows.net\/wordpress\/2015\/05\/nifty.machine.learning.2013-1024x683.png 1024w, https:\/\/portalvhds29z8xdrqhczq.blob.core.windows.net\/wordpress\/2015\/05\/nifty.machine.learning.2013-450x300.png 450w, https:\/\/portalvhds29z8xdrqhczq.blob.core.windows.net\/wordpress\/2015\/05\/nifty.machine.learning.2013-900x600.png 900w\" sizes=\"auto, (max-width: 1200px) 100vw, 1200px\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/portalvhds29z8xdrqhczq.blob.core.windows.net\/wordpress\/2015\/05\/banknifty.machine.learning.2013.png\" alt=\"banknifty.machine.learning.2013\" width=\"1200\" height=\"800\" class=\"alignnone size-full wp-image-2022381\" srcset=\"https:\/\/portalvhds29z8xdrqhczq.blob.core.windows.net\/wordpress\/2015\/05\/banknifty.machine.learning.2013.png 1200w, https:\/\/portalvhds29z8xdrqhczq.blob.core.windows.net\/wordpress\/2015\/05\/banknifty.machine.learning.2013-300x200.png 300w, https:\/\/portalvhds29z8xdrqhczq.blob.core.windows.net\/wordpress\/2015\/05\/banknifty.machine.learning.2013-1024x683.png 1024w, https:\/\/portalvhds29z8xdrqhczq.blob.core.windows.net\/wordpress\/2015\/05\/banknifty.machine.learning.2013-450x300.png 450w, https:\/\/portalvhds29z8xdrqhczq.blob.core.windows.net\/wordpress\/2015\/05\/banknifty.machine.learning.2013-900x600.png 900w\" sizes=\"auto, (max-width: 1200px) 100vw, 1200px\" \/><\/p>\n<h3>Cumulative Returns<\/h3>\n<p>Buy-and-hold has two big advantages over a trading strategy: transaction costs and tax treatment. Here is how the different strategies compare with buy and hold:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/portalvhds29z8xdrqhczq.blob.core.windows.net\/wordpress\/2015\/05\/NIFTY-SVM.png\" alt=\"NIFTY SVM\" width=\"820\" height=\"288\" class=\"alignnone size-full wp-image-2022401\" srcset=\"https:\/\/portalvhds29z8xdrqhczq.blob.core.windows.net\/wordpress\/2015\/05\/NIFTY-SVM.png 820w, https:\/\/portalvhds29z8xdrqhczq.blob.core.windows.net\/wordpress\/2015\/05\/NIFTY-SVM-300x105.png 300w, https:\/\/portalvhds29z8xdrqhczq.blob.core.windows.net\/wordpress\/2015\/05\/NIFTY-SVM-500x176.png 500w\" sizes=\"auto, (max-width: 820px) 100vw, 820px\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/portalvhds29z8xdrqhczq.blob.core.windows.net\/wordpress\/2015\/05\/BANKNIFTY-SVM.png\" alt=\"BANKNIFTY SVM\" width=\"820\" height=\"288\" class=\"alignnone size-full wp-image-2022411\" srcset=\"https:\/\/portalvhds29z8xdrqhczq.blob.core.windows.net\/wordpress\/2015\/05\/BANKNIFTY-SVM.png 820w, https:\/\/portalvhds29z8xdrqhczq.blob.core.windows.net\/wordpress\/2015\/05\/BANKNIFTY-SVM-300x105.png 300w, https:\/\/portalvhds29z8xdrqhczq.blob.core.windows.net\/wordpress\/2015\/05\/BANKNIFTY-SVM-500x176.png 500w\" sizes=\"auto, (max-width: 820px) 100vw, 820px\" \/><\/p>\n<p>It appears that the ML(V + 50-DMA) Long Short strategy works better on the BankNifty than on the Nifty. The out-performance of the ML model on the BankNifty more than compensates for transaction costs and taxation.<\/p>\n<h3>Conclusion<\/h3>\n<p>The ML model outperformed the NIFTY by an average of 12% in the last 4-years and the BANKNIFTY by 94% in the same period. The out-performance on the BANKNIFTY is considerable enough to warrant further exploration.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction Our previous post discussed how a simple SMA On\/Off Switch based tactical algo can be enhanced by a volatility metric. We generated significant alpha by following a simple rule: Go short if either or the volatility signal or the 50-DMA indicates a negative bias and long otherwise. But what if we trained a machine &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":[3411,3391,2761,3551],"class_list":["post-2022351","post","type-post","status-publish","format-standard","hentry","category-investing-insight","category-your-money","tag-banknifty","tag-nifty","tag-quant","tag-support-vector-machine","entry"],"_links":{"self":[{"href":"https:\/\/stockviz.biz\/index.php\/wp-json\/wp\/v2\/posts\/2022351","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=2022351"}],"version-history":[{"count":0,"href":"https:\/\/stockviz.biz\/index.php\/wp-json\/wp\/v2\/posts\/2022351\/revisions"}],"wp:attachment":[{"href":"https:\/\/stockviz.biz\/index.php\/wp-json\/wp\/v2\/media?parent=2022351"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/stockviz.biz\/index.php\/wp-json\/wp\/v2\/categories?post=2022351"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/stockviz.biz\/index.php\/wp-json\/wp\/v2\/tags?post=2022351"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}