<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Au.Tra.Sy blog - Automated trading System &#187; Data</title>
	<atom:link href="http://www.automated-trading-system.com/category/data/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.automated-trading-system.com</link>
	<description>Systematic Trading research and development, with a flavour of Trend Following</description>
	<lastBuildDate>Tue, 07 Feb 2012 09:58:33 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Trend Following Wizard Correlations Heatmap [Video]</title>
		<link>http://www.automated-trading-system.com/trend-following-wizard-correlations-heatmap/</link>
		<comments>http://www.automated-trading-system.com/trend-following-wizard-correlations-heatmap/#comments</comments>
		<pubDate>Thu, 10 Mar 2011 15:45:36 +0000</pubDate>
		<dc:creator>Jez Liberty</dc:creator>
				<category><![CDATA[Data]]></category>
		<category><![CDATA[Trend Following Wizards]]></category>
		<category><![CDATA[correlation]]></category>
		<category><![CDATA[visualization]]></category>
		<category><![CDATA[wizards]]></category>

		<guid isPermaLink="false">http://www.automated-trading-system.com/?p=4067</guid>
		<description><![CDATA[One of my favourite non-trading-related blogs is FlowingData, a visualization and statistics site by Nathan Yau. I find Data visualization fascinating and inspiring. A good visualization usually &#8220;brings data to life&#8221; making it easier to understand. Most visualizations featured on FlowingData are very aesthetically pleasing, making the subject a sort of enjoyable and useful &#8220;geeky [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.automated-trading-system.com/wp-content/uploads/2011/03/heatmap.png" alt="" title="heatmap" width="375" height="269" class="alignnone size-full wp-image-4068" /></p>
<p>One of my favourite non-trading-related blogs is <a href="http://flowingdata.com/" target="_blank" rel="nofollow">FlowingData</a>, a visualization and statistics site by Nathan Yau.</p>
<p>I find Data visualization fascinating and inspiring. A good visualization usually &#8220;brings data to life&#8221; making it easier to understand. Most visualizations featured on FlowingData are very aesthetically pleasing, making the subject a sort of enjoyable and useful &#8220;geeky art&#8221;. The Correlations Heatmap video below is an attempt at some of this.</p>
<h3>Trend Following Wizard Correlations Visualization: Video of Evolution through time</h3>
<p>For this post, I got inspired by a reader comment mentioning that it would be interesting to calculate correlations between the <a href="http://www.automated-trading-system.com/resources/trend-following-wizards-fund-performance">Trend Following Wizards</a> reported on the blog. </p>
<p>I agreed with the idea, and seeing this <a href="http://flowingdata.com/2010/01/21/how-to-make-a-heatmap-a-quick-and-easy-solution/" target="_blank" rel="nofollow">tutorial post on creating heatmaps in R</a> on FlowingData (with sample code: thanks!) gave me the idea of a data visualization of my own: showing the evolution of correlations through a &#8220;time-lapse&#8221; video of monthly correlation heatmaps through time. Fun and quick little project dealing with trading-related data, visualization and programming. Perfect combination!</p>
<p>The resulting movie is embedded below (available directly on the <a href="http://vimeo.com/20855626" target="_blank" rel="nofollow">vimeo website</a> in slightly larger size):<span id="more-4067"></span></p>
<p><iframe src="http://player.vimeo.com/video/20855626" width="500" height="375" frameborder="0"></iframe></p>
<p>With the color key:</p>
<p><img src="http://www.automated-trading-system.com/wp-content/uploads/2011/03/color-key.png" alt="" title="color key" width="235" height="190" class="alignnone size-full wp-image-4069" /><br />
&nbsp;<br />
Every month, a rolling 12-month correlation number is calculated (using Pearson) between each Wizard, The full matrix of pairwise correlations is then represented in a heatmap format, with the cell color, directly representing the correlation coefficient, as per the color key above.</p>
<p>The movie simply stitches all heatmaps in chronological order, month after month, from January 1990.</p>
<p>You&#8217;ll notice that some cells are grey: light grey means that I do not have any available data for that month for the corresponding Wizard. Dark grey is to hide the correlation between a Wizard and itself (irrelevant as obviously always equal to 1).</p>
<p>It is interesting to see how the heatmap moves from periods of strong correlation (near all-blue, check the Summer of 2003 for example) to more heterogeneous periods.</p>
<p>I was also intrigued by some periods showing real jumps for the whole heatmap (check July 99 to August 99). It is not so surprising though, when you know how data outliers can have a strong influence on the (Pearson) correlation numbers (this is what happens in the jump from July to August in 1999: August 1998 showed strong returns for most Wizards; when these numbers drop off the correlation calculation, the correlation coefficients sharply decrease as a result).</p>
<p><em>Software note:</em> The movie was created using R to generate the heatmaps (as per FlowingData heatmap tutorial) and XnView + FFmpeg to edit and stitch images into a video.</p>
<h3>More Data Visualizations</h3>
<p>FlowingData publishes very regularly and the quality is usually very good (Nathan Yau&#8217;s <a href="http://www.amazon.com/exec/obidos/ASIN/0470944889/autotradblog-20" target="_blank" rel="nofollow">book</a> is definitely on my Wish List).<br />
For readers interested in checking it out (watch out, you can quickly spend an hour on the site!), here are some posts or links that caught my attention:</p>
<h4>Finance</h4>
<p><a href="http://flowingdata.com/2011/01/13/in-investing-timing-is-everything/" target="_blank" rel="nofollow">In investing, timing is everything</a> (we know that!): This one is directly related to investing/trading, and I believe Trend Following Wizard CTAs could use the idea to present their past results to prospective investors in a similar fashion. This is a grid diagram which shows annualized returns for the S.&#038; P. 500 for every starting year and every ending year since 1920 &#8211; nearly 4,000 combinations in all:</p>
<p><img src="http://www.automated-trading-system.com/wp-content/uploads/2011/03/investing-575x3051.png" alt="" title="investing-575x305" width="499" height="305" class="alignnone size-full wp-image-4071" /></p>
<p>Originally from the NY Times, link to <a href="http://www.nytimes.com/interactive/2011/01/02/business/20110102-metrics-graphic.html" target="_blank" rel="nofollow">full original diagram</a></p>
<p>CTAs could plot their monthly returns to get an overall view of what an investor could have made at different periods and highlight specific stats like 36-month, 60-month rolling returns. Possibly another similar chart with drawdowns to complete the picture. This could be an interesting project.</p>
<p>Past century of government and economy: Displays several economic indicators over 100 years, aligned with political parties in power.<br />
<a href="http://flowingdata.com/2010/11/02/past-century-of-government-and-economy/" target="_blank" rel="nofollow"><img src="http://www.automated-trading-system.com/wp-content/uploads/2011/03/100-years-of-government-575x362.png" alt="" title="100-years-of-government-575x362" width="400" height="50" class="alignnone size-full wp-image-4072" /></a></p>
<h4>Sports</h4>
<p>For sport stats lovers:</p>
<ul>
<li><a href="http://www.pennant.cc/index.php" target="_blank" rel="nofollow">Pennant iPad app: Every team. Every game. Every play. 1952 to 2010.</a> If I had an iPad and were into baseball, I&#8217;d definitely get this one: it looks really cool. Check the video out.</li>
<li><a href="http://www.juiceanalytics.com/nfl-visualization/" target="_blank" rel="nofollow">Juice Analytics display NFL statistics</a> visually, more interesting than the usual tables.</li>
</ul>
<h4>Maps</h4>
<p>Facebook worldwide friendships mapped:<br />
<a href="http://flowingdata.com/2010/12/13/facebook-worldwide-friendships-mapped/" target="_blank" rel="nofollow"><img src="http://www.automated-trading-system.com/wp-content/uploads/2011/03/United-States-Facebook-connections-575x441.png" alt="" title="United-States-Facebook-connections-575x441" width="400" height="50" class="alignnone size-full wp-image-4073" /></a></p>
<p>Commercial Air Traffic Seen Around the World (video):<br />
<a href="http://flowingdata.com/2008/10/08/commercial-air-traffic-seen-around-the-world/" target="_blank" rel="nofollow"><img src="http://www.automated-trading-system.com/wp-content/uploads/2011/03/Commercial-air-traffic.png" alt="" title="Commercial-air-traffic" width="400" height="50" class="alignnone size-full wp-image-4074" /></a></p>
<p>Watching the Growth of Walmart Across America (video):<br />
<a href="http://flowingdata.com/2008/07/10/watching-the-growth-of-walmart-across-america-interactive-edition/" target="_blank" rel"nofollow"><img src="http://www.automated-trading-system.com/wp-content/uploads/2011/03/walmart.8ojjze0qi70gwwso44wwwcggo.53yv50rplpk4cwoc00sw8o0k8.th.png" alt="" title="walmart" width="400" height="50" class="alignnone size-full wp-image-4075" /></a></p>
<p>Our changing world in cartograms:<br />
<a href="http://flowingdata.com/2011/01/10/our-changing-world-in-cartograms/" target="_blank" rel="nofollow"><img src="http://www.automated-trading-system.com/wp-content/uploads/2011/03/Cartogram-of-richest-countries-575x323.png" alt="" title="Cartogram-of-richest-countries-575x323" width="400" height="50" class="alignnone size-full wp-image-4076" /></a><br />
Series of videos showing the evolution of several indicators per country, morphing the size of countries proportionally to its indicator value. Some surprising world map redrawing!</p>
<h4>Others</h4>
<p>10 Best Data Visualization Projects of the Year &#8211; 2010:<br />
<a href="http://flowingdata.com/2010/12/14/10-best-data-visualization-projects-of-the-year-%E2%80%93-2010/" target="_blank" rel="nofollow"><img src="http://www.automated-trading-system.com/wp-content/uploads/2011/03/tourists-in-sf-575x374.png" alt="" title="tourists-in-sf" width="400" height="50" class="alignnone size-full wp-image-4077" /></a></p>
<p>What New Yorkers complain about:<br />
<a href="http://flowingdata.com/2010/11/08/what-new-yorkers-complain-about/" target="_blank" rel="nofollow"><img src="http://www.automated-trading-system.com/wp-content/uploads/2011/03/Calls-to-311-in-New-York1.png" alt="" title="Calls-to-311-in-New-York1" width="400" height="50" class="alignnone size-full wp-image-4078" /></a></p>
<p>Fancy drinks recipes infographics:<br />
<a href="http://flowingdata.com/2011/01/31/charted-guide-to-fancy-alcoholic-beverages/" target="_blank" rel="nofollow"><img src="http://www.automated-trading-system.com/wp-content/uploads/2011/03/fancy-drinks-575x813.png" alt="" title="fancy-drinks-575x813" width="253" height="50" class="alignnone size-full wp-image-4079" /></a></p>
<p>And finally, an interesting one hour documentary video on <a href="http://www.gapminder.org/videos/the-joy-of-stats/" target="_blank" rel="nofollow">&#8220;The Joy of Stats&#8221;</a> by Hans Rosling</p>
<p>Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.automated-trading-system.com/trend-following-wizard-correlations-heatmap/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ETF v. Futures: a Quantification</title>
		<link>http://www.automated-trading-system.com/etf-v-futures-a-quantification/</link>
		<comments>http://www.automated-trading-system.com/etf-v-futures-a-quantification/#comments</comments>
		<pubDate>Wed, 09 Feb 2011 10:57:58 +0000</pubDate>
		<dc:creator>Jez Liberty</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Data]]></category>
		<category><![CDATA[Equities]]></category>
		<category><![CDATA[Futures]]></category>
		<category><![CDATA[correlation]]></category>
		<category><![CDATA[etf]]></category>

		<guid isPermaLink="false">http://www.automated-trading-system.com/?p=4019</guid>
		<description><![CDATA[I have already covered the idea of using ETFs in place of Futures. Today, I wanted to run a quantitative comparison between the two instrument types The ETF sector has been growing at an impressive rate, with new offerings popping up every month and providing a wider choice in selecting a portfolio to trade. One [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.automated-trading-system.com/wp-content/uploads/2011/02/ETF-Growth.png" alt="" title="ETF Growth" width="354" height="211" class="alignnone size-full wp-image-4025" /></p>
<p>I have already covered the idea of <a href="http://www.automated-trading-system.com/futures-vs-etfs/">using ETFs in place of Futures</a>. Today, I wanted to run a <strong>quantitative comparison</strong> between the two instrument types</p>
<p>The ETF sector has been growing at an impressive rate, with new offerings popping up every month and providing a wider choice in selecting a portfolio to trade. One of the drawbacks of using ETFs for mechanical trading strategies is the <strong>relative short history</strong> of these instruments, making it hard or impossible to run to back-tests looking back far in the past &#8211; which I believe is critical to understand how a strategy works over different types of market conditions.</p>
<p>In <a href="http://www.automated-trading-system.com/practical-guide-to-etf-trading-systems-garner/">A Practical Guide to ETF Trading Systems</a>, author Anthony Garner uses <strong>futures contracts as a proxy</strong> for testing strategies on ETFs. If futures are good proxies for ETFs, the back-test results from a long run with futures can be extrapolated to the ETF world.</p>
<p>This post is attempting to look at <em>one way</em> of quantifying how well futures can act as a proxy.</p>
<h3>Quantification by Correlation</h3>
<p>The main &#8220;tool&#8221; used in this post, to test whether futures are good proxies to ETFs, is that of correlation between prices as well as returns. The assumption being that correlations between an ETF and a good candidate futures proxy must be as close as possible to 1.0. The closer to 1, the better the proxy relationship.</p>
<p>I picked a few ETFs and associated futures and calculated the correlation (using Pearson product-moment) between several of the data attributes:<span id="more-4019"></span></p>
<ul>
<li>Open</li>
<li>High</li>
<li>Low</li>
<li>Close</li>
<li>t-1 Return</li>
<li>t-5 Return</li>
<li>t-30 Return</li>
</ul>
<p>The data considered in each case was the list of all dates where both futures and ETF had data. The futures contract were proportionally back-adjusted (to keep price ratio at correct values, as discussed in <a href="http://www.automated-trading-system.com/trade-what-you-test-and-test-what-you-trade/">this post</a>).</p>
<p>The table below shows the number of records for each comparison, the start date and the various correlation coefficients.</p>
<table style="border:1px solid #c3c3c3; border-collapse:collapse;">
<tr>
<th style="background-color:#e5eecc; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;" rowspan="2" align = "center">
      ETF v Future
    </th>
<th style="background-color:#e5eecc; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;" rowspan="2" align = "center">
      num.<br />records
    </th>
<th style="background-color:#e5eecc; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;" rowspan="2" align = "center">
      Start<br />Date
    </th>
<th style="background-color:#e5eecc; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;" colspan="7" align = "center">
      Correlation Coefficients
    </th>
</tr>
<tr>
<th style="background-color:#e5eecc; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;" align = "center">
      Open
    </th>
<th style="background-color:#e5eecc; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;" align = "center">
      High
    </th>
<th style="background-color:#e5eecc; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;" align = "center">
      Low
    </th>
<th style="background-color:#e5eecc; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;" align = "center">
      Close
    </th>
<th style="background-color:#e5eecc; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;" align = "center">
      t-1 Rtn
    </th>
<th style="background-color:#e5eecc; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;" align = "center">
      t-5 Rtn
    </th>
<th style="background-color:#e5eecc; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;" align = "center">
      t-30 Rtn
    </th>
</tr>
<tr>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;">
<strong>Aussie Dollar</strong>: FXA v AD
    </td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;" align = "right">
1154
    </td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;">
20060627
    </td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;" align = "right">
0.9928
    </td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;" align = "right">
0.9939
    </td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;" align = "right">
0.9945
    </td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;" align = "right">
0.9945
    </td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;" align = "right">
0.9000
    </td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;" align = "right">
0.9802
    </td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;" align = "right">
0.9947
    </td>
</tr>
<tr>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;">
<strong>Cotton</strong>: BAL v CT
    </td>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;" align = "right">
652
    </td>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;">
20080626
    </td>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;" align = "right">
0.9980
    </td>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;" align = "right">
0.9983
    </td>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;" align = "right">
0.9989
    </td>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;" align = "right">
0.9991
    </td>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;" align = "right">
0.8541
    </td>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;" align = "right">
0.9666
    </td>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;" align = "right">
0.9954
    </td>
</tr>
<tr>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;">
<strong>Cotton</strong>: COTN-L v CT
    </td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;" align = "right">
1010
    </td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;">
20061221
    </td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;" align = "right">
0.9939
    </td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;" align = "right">
0.9947
    </td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;" align = "right">
0.9928
    </td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;" align = "right">
0.9960
    </td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;" align = "right">
0.3190
    </td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;" align = "right">
0.8825
    </td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;" align = "right">
0.9761
    </td>
</tr>
<tr>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;">
<strong>Cocoa</strong>: NIB v CC
    </td>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;" align = "right">
651
    </td>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;">
20080626
    </td>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;" align = "right">
0.9898
    </td>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;" align = "right">
0.9948
    </td>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;" align = "right">
0.9961
    </td>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;" align = "right">
0.9973
    </td>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;" align = "right">
0.8948
    </td>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;" align = "right">
0.9781
    </td>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;" align = "right">
0.9955
    </td>
</tr>
<tr>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;">
<strong>Crude Oil</strong>: DBO v CL
    </td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;" align = "right">
1024
    </td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;">
20070108
    </td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;" align = "right">
0.9232
    </td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;" align = "right">
0.9251
    </td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;" align = "right">
0.9212
    </td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;" align = "right">
0.9236
    </td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;" align = "right">
0.9080
    </td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;" align = "right">
0.9416
    </td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;" align = "right">
0.9606
    </td>
</tr>
<tr>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;">
<strong>Crude Oil</strong>: OIL v CL
    </td>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;" align = "right">
1120
    </td>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;">
20060817
    </td>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;" align = "right">
0.9989
    </td>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;" align = "right">
0.9994
    </td>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;" align = "right">
0.9993
    </td>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;" align = "right">
0.9994
    </td>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;" align = "right">
0.9568
    </td>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;" align = "right">
0.9900
    </td>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;" align = "right">
0.9973
    </td>
</tr>
<tr>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;">
<strong>Crude Oil</strong>: USO v CL
    </td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;" align = "right">
1208
    </td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;">
20060411
    </td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;" align = "right">
0.9971
    </td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;" align = "right">
0.9978
    </td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;" align = "right">
0.9976
    </td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;" align = "right">
0.9978
    </td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;" align = "right">
0.9536
    </td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;" align = "right">
0.9894
    </td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;" align = "right">
0.9982
    </td>
</tr>
<tr>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;">
<strong>Gold</strong>: GLD v GC
    </td>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;" align = "right">
1553
    </td>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;">
20041119
    </td>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;" align = "right">
0.9977
    </td>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;" align = "right">
0.9981
    </td>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;" align = "right">
0.9979
    </td>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;" align = "right">
0.9980
    </td>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;" align = "right">
0.8665
    </td>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;" align = "right">
0.9743
    </td>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;" align = "right">
0.9940
    </td>
</tr>
<tr>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;">
<strong>Japanese Yen</strong>: FXY v JY
    </td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;" align = "right">
996
    </td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;">
20070214
    </td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;" align = "right">
0.9948
    </td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;" align = "right">
0.9963
    </td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;" align = "right">
0.9958
    </td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;" align = "right">
0.9965
    </td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;" align = "right">
0.9405
    </td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;" align = "right">
0.9856
    </td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;" align = "right">
0.9951
    </td>
</tr>
<tr>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;">
<strong>Nasdaq100</strong>: QQQQ v NQ
    </td>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;" align = "right">
2991
    </td>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;">
19990311
    </td>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;" align = "right">
0.9752
    </td>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;" align = "right">
0.9762
    </td>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;" align = "right">
0.9740
    </td>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;" align = "right">
0.9752
    </td>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;" align = "right">
0.9817
    </td>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;" align = "right">
0.9957
    </td>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;" align = "right">
0.9989
    </td>
</tr>
<tr>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;">
<strong>Silver</strong>: PHAG-L v SI
    </td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;" align = "right">
932
    </td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;">
20070425
    </td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;" align = "right">
0.9964
    </td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;" align = "right">
0.9970
    </td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;" align = "right">
0.9964
    </td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;" align = "right">
0.9965
    </td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;" align = "right">
0.8223
    </td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;" align = "right">
0.9635
    </td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;" align = "right">
0.9929
    </td>
</tr>
<tr>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;">
<strong>Silver</strong>: SLV v SI
    </td>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;" align = "right">
1194
    </td>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;">
20060501
    </td>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;" align = "right">
0.9906
    </td>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;" align = "right">
0.9921
    </td>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;" align = "right">
0.9918
    </td>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;" align = "right">
0.9920
    </td>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;" align = "right">
0.8812
    </td>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;" align = "right">
0.9775
    </td>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;" align = "right">
0.9955
    </td>
</tr>
<tr>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;">
<strong>S&#038;P 500</strong>: SPY vs ES
    </td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;" align = "right">
4533
    </td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;">
19930201
    </td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;" align = "right">
0.8757
    </td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;" align = "right">
0.8765
    </td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;" align = "right">
0.8740
    </td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;" align = "right">
0.8751
    </td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;" align = "right">
0.9576
    </td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;" align = "right">
0.9637
    </td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;" align = "right">
0.9704
    </td>
</tr>
<tr>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;">
<strong>US T-Notes</strong>: IEF v TY
    </td>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;" align = "right">
2130
    </td>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;">
20020731
    </td>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;" align = "right">
0.9707
    </td>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;" align = "right">
0.9713
    </td>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;" align = "right">
0.9708
    </td>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;" align = "right">
0.9711
    </td>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;" align = "right">
0.9359
    </td>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;" align = "right">
0.9689
    </td>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3; padding:2px; font-size:0.7em;" align = "right">
0.9758
    </td>
</tr>
</table>
<p><em>Note: please make sure you view this post with your &#8220;browser zoom&#8221; at 100% for the numbers to be readable.</em></p>
<p>Most of the numbers are pretty close to 1, which seems to validate the idea of using the future contract as a proxy for ETF.</p>
<p>Some underlyings can be traded through different ETFs (or ETNs). Crude Oil, for example, has several ETFs aiming to capture its performance (I picked DBO, OIL and USO for this test). We can see that there are some differences between the correlation figures of these three ETFs. Not all ETFs seem to track the underlying as well&#8230;.</p>
<p>A more obvious case of divergence is between the two Cotton ETFs: BAL and COTN (traded in London). The COTN ETF has a low correlation reading on previous-day returns (0.319). Obviously, the fact that the two instruments are trading in different timezones (London vs. NY) will cause their daily performance returns to differ as the market still moves after the London close. This would be something to also keep in mind when choosing an ETF/future pair.</p>
<p><strong>Note on Correlation: Pearson vs. Spearman</strong></p>
<p>I have chosen the <a href="http://en.wikipedia.org/wiki/Pearson_product-moment_correlation_coefficient" target="_blank" rel="nofollow">Pearson correlation method</a> for these calculations, as the <strong>linear relationship</strong> between the variables under comparison was what I felt needed to be looked at. However there are several &#8220;limitations&#8221; of using this correlation calculation. One of them is the <strong>assumption of the data being normally distributed</strong>, resulting in the calculation being very <strong>sensitive to outliers</strong>.</p>
<p>This is best illustrated with the correlation of &#8220;t-1 Returns&#8221; between the COTN ETF and its corresponding Cotton future contract. Back in September 08, the ETF price dropped by 60% before gaining 75% the next day. I seem to remember this was related to a scare around AIG-backed ETFs/ETNs, when the insurance giant was rumoured to go bankrupt.</p>
<p>For the purpose of a test, I simply removed these 2 extreme returns from the file and re-ran the correlation calculation. The figure came in at 0.518. A large increase, obtained by simply removing two outliers. This highlights the point about Pearson correlation not being the most robust with regards to outlier data points.</p>
<p>There are other methods for calculating correlation, and <a href="http://en.wikipedia.org/wiki/Spearman's_rank_correlation_coefficient" target="_blank" rel="nofollow">Spearman&#8217;s rank</a> method does not make any assumptions on the distribution of the data. It can also detect <em>some</em> non-linear relationship (which we were not interested here). Nevertheless, I re-ran the whole set using this alternative method. The figures were approximately identical &#8211; except for the case of COTN.</p>
<p>The Spearman correlation coefficient for COTN v CT using both original and modified files were near-identical at around 0.61. No big jump by removing two outliers.</p>
<p><strong>Note on ETFs</strong></p>
<p><em>ETPs </em>(Exchange Traded Products), be they called <em>ETF</em>, <em>ETN </em>or <em>ETC</em> all come in different flavours. They can be structured in different ways and track different benchmarks, even when they are associated to the same market. They also add an extra layer and therefore additional counterparty risk on the intermediaries, costs/fees and tracking error.</p>
<p>A good example of the differences between some products can be found in this ETFdb article: <a href="http://etfdb.com/2010/uso-vs-oil-a-better-crude-oil-etf/" target="_blank">USO vs. OIL: A Better Crude Oil ETF?</a></p>
<p>Finally, it is not (yet?) possible to trade the equivalent of a fully diversified futures portfolio with ETFs, as all markets are not represented in the ETF universe.</p>
<h3>Appendix: R Code</h3>
<p>Once again, I used R to generate the various correlation calculations. The idea being that one it is coded up it can be applied very quickly to any data.</p>
<p>The code takes a parameter file containing the files to be compared (1st column = description, 2nd and 3rd columns = file names) and the correlation calculation type. See <a href="" target="_blank">sample here</a>.</p>
<p>Here is the code below. Hopefully the comments are clear enough to help you understand the logic. This might not be the most perfect way to implement this but it does the job:</p>
<p>First, it defines a function to perform the calculations on two files (ie ETF vs. future):</p>

<div class="wp_syntax"><div class="code"><pre class="r" style="font-family:monospace;"># Define correlETFFut function
correlETFFut &lt;- function(params, i, cor.method,...) {
&nbsp;
  colsFut &lt;- c(&quot;date&quot;, &quot;O&quot;, &quot;H&quot;, &quot;L&quot;, &quot;C&quot;, &quot;Vol&quot;, &quot;OI&quot;, &quot;Con&quot;, &quot;UC&quot;)
&nbsp;
  # Adding headers
  cols1 &lt;- colsFut
  cols2 &lt;- colsFut
&nbsp;
  # Read in data sets
  data.1 &lt;- read.csv(toString(params[i,2]), col.names=cols1)
  data.2 &lt;- read.csv(toString(params[i,3]), col.names=cols2)
&nbsp;
  # Join both data sets
  data.merged &lt;- merge(data.1, data.2, by.x=&quot;date&quot;, by.y=&quot;date&quot;)
&nbsp;
  #Calculate correlation on Open, High, Low and Close
  cor.O &lt;- cor.test(data.merged$O.x, data.merged$O.y,method=cor.method)
  cor.H &lt;- cor.test(data.merged$H.x, data.merged$H.y,method=cor.method)
  cor.L &lt;- cor.test(data.merged$L.x, data.merged$L.y,method=cor.method)
  cor.C &lt;- cor.test(data.merged$C.x, data.merged$C.y,method=cor.method)
&nbsp;
  #Calculate correlation on t-1 Rtn
  log.diffs1 &lt;- log( data.merged$C.x[2:sum ( !is.na ( data.merged$C.x ) )]/data.merged$C.x[1:(sum ( !is.na ( data.merged$C.x ) ) - 1)])
  log.diffs2 &lt;- log( data.merged$C.y[2:sum ( !is.na ( data.merged$C.y ) )]/data.merged$C.y[1:(sum ( !is.na ( data.merged$C.y ) ) - 1)])
&nbsp;
  cor.Rtn &lt;- cor.test(log.diffs1, log.diffs2,method=cor.method)
&nbsp;
  #Calculate correlation on t-5 Rtn
  log.diffs1W &lt;- log( data.merged$C.x[6:sum ( !is.na ( data.merged$C.x ) )]/data.merged$C.x[1:(sum ( !is.na ( data.merged$C.x ) ) - 5)])
  log.diffs2W &lt;- log( data.merged$C.y[6:sum ( !is.na ( data.merged$C.y ) )]/data.merged$C.y[1:(sum ( !is.na ( data.merged$C.y ) ) - 5)])
&nbsp;
  cor.RtnW &lt;- cor.test(log.diffs1W, log.diffs2W,method=cor.method)
&nbsp;
  #Calculate correlation on t-30 Rtn
  log.diffs1M &lt;- log( data.merged$C.x[31:sum ( !is.na ( data.merged$C.x ) )]/data.merged$C.x[1:(sum ( !is.na ( data.merged$C.x ) ) - 30)])
  log.diffs2M &lt;- log( data.merged$C.y[31:sum ( !is.na ( data.merged$C.y ) )]/data.merged$C.y[1:(sum ( !is.na ( data.merged$C.y ) ) - 30)])
&nbsp;
  cor.RtnM &lt;- cor.test(log.diffs1M, log.diffs2M,method=cor.method)
&nbsp;
  #Put it all into cor.all
  cor.all &lt;- c(sum ( !is.na ( data.merged$C.x )), data.merged$date[1], signif(cor.O$estimate,5), signif(cor.H$estimate,5), signif(cor.L$estimate,5), signif(cor.C$estimate,5), signif(cor.Rtn$estimate,5), signif(cor.RtnW$estimate,5), signif(cor.RtnM$estimate,5))
  return(cor.all)
&nbsp;
}</pre></div></div>

<p>Second, a function reads the parameter file of all files to be compared, iterates through it and call the first function for each pair of files, building an array of all results:</p>

<div class="wp_syntax"><div class="code"><pre class="r" style="font-family:monospace;"># Define fullCorrel function
fullCorrel &lt;- function(file, cor.method,...) {
&nbsp;
  # read input file
  comps &lt;- read.csv(file, header=F)
  for (i in 1:dim(comps[1])[1]){
    cor.tmp &lt;- correlETFFut(comps,i,cor.method)
    if (i==1) cor.full &lt;- cor.tmp else cor.full &lt;- cbind(cor.full, cor.tmp)
  }
&nbsp;
  rownames(cor.full) &lt;- c(&quot;Record Count&quot;, &quot; Start Date&quot;, &quot; cor Open&quot;, &quot; cor High&quot;, &quot; cor Low&quot;, &quot; cor Close&quot;, &quot; cor Rtn&quot;, &quot; cor RtnW&quot;, &quot; cor RtnM&quot;)
  colnames(cor.full) &lt;- t(comps[1])
 return(t(cor.full))
}</pre></div></div>

<p>Finally, set your working directory (where all the files are) and call the second function with the relevant parameters (here the function is called twice with the same parameter file and two different correlation methods (make sure to update the working dir to your own path):</p>

<div class="wp_syntax"><div class="code"><pre class="r" style="font-family:monospace;"># Set Working Dir - Replace with your own path!
setwd(&quot;D:/ATS/Blog/Posts/ETF v Futures/Data&quot;)
&nbsp;
# Run Pearson correlations
fullCorrel(&quot;ETFvFut.txt&quot;, &quot;pearson&quot;)
&nbsp;
# Run Spearman correlations
fullCorrel(&quot;ETFvFut.txt&quot;, &quot;spearman&quot;)</pre></div></div>

<p>Below are included some sample files to run the code above:<br />
<a href='http://www.automated-trading-system.com/wp-content/uploads/2011/02/Sample_Data.zip' target="_blank">Sample_Data</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.automated-trading-system.com/etf-v-futures-a-quantification/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Trade what you Test and Test what you Trade</title>
		<link>http://www.automated-trading-system.com/trade-what-you-test-and-test-what-you-trade/</link>
		<comments>http://www.automated-trading-system.com/trade-what-you-test-and-test-what-you-trade/#comments</comments>
		<pubDate>Thu, 20 Jan 2011 14:17:28 +0000</pubDate>
		<dc:creator>Jez Liberty</dc:creator>
				<category><![CDATA[Backtest]]></category>
		<category><![CDATA[Data]]></category>
		<category><![CDATA[CSI]]></category>
		<category><![CDATA[rollover]]></category>

		<guid isPermaLink="false">http://www.automated-trading-system.com/?p=3848</guid>
		<description><![CDATA[In order to avoid bad surprises in live trading, the maxim forming this post title should apply to as much of a trading system as possible. The goal is to ensure back-testing results are as realistic as they can. Input data is one component of a trading system and the area this post focuses on, [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.automated-trading-system.com/wp-content/uploads/2011/01/test-trade.jpg" alt="test-trade" title="test-trade" width="470" height="170" class="alignnone size-full wp-image-3849" /></p>
<p>In order to avoid bad surprises in live trading, the maxim forming this post title should apply to as much of a trading system as possible. The goal is to ensure <strong>back-testing results are as realistic</strong> as they can.</p>
<p><strong>Input data</strong> is one component of a trading system and the area this post focuses on, more specifically <strong>roll-over methodologies for futures contracts</strong>.</p>
<h3>Real Monthly Trading Also Means Monthly Roll-Over</h3>
<p>One of the triggers for this post was a comment on the <a href="http://www.automated-trading-system.com/trade-monthly-basis/">Monthly Trading post</a> with regards to the futures data used for the test. In order to have comparable results between the daily and monthly instances of the systems tested, I simply and mechanically reused the same portfolio of instruments&#8230;</p>
<p>However, futures contracts in the portfolio <strong>roll on Open Interest</strong>. What this practically means, is that a trader using this methodology would have to monitor OI every day to decide whether to roll to another contract. <em>Not much of a monthly process.</em></p>
<p>I still think that test had some value, but it is important to realise that the monthly instance in that test was not representative of a pure monthly process. Instead we were actually simulating a trading strategy with <strong>monthly signal taking</strong> but <strong>daily roll-over</strong> monitoring process.</p>
<p>It highlights the fact that it is important to understand what the data used for testing actually represents, and to roll futures contract data in the same way as they are rolled in real-life.</p>
<p>This post is a good opportunity to revisit the concepts of generating continuous futures data and some of the older posts I had written on the subject using CSI (<a href="http://www.automated-trading-system.com/what-everybody-ought-to-know-about-continous-futures-contracts/">here</a> and <a href="http://www.automated-trading-system.com/continuous-contract-options/">here</a>).<span id="more-3848"></span></p>
<h3>ETF: Outsource your Contract Rolling Process</h3>
<p>Another reason why I think that the monthly trading test has some value is because the individual monthly trader might decide to <strong>trade ETFs instead of futures</strong>.</p>
<p>ETFs can be seen as simple wrappers of futures contracts: they trade continuously and their managers take care of rolling their underlying positions with a predefined methodology and timing, charging you a fee in the process.</p>
<p>Of course, this is not futures Trend Following any more, and using ETFs lacks the inherent leverage embedded in futures instruments. But it is possible to obtain decent performance with Trend Following on ETFs (check <a href="http://www.automated-trading-system.com/practical-guide-to-etf-trading-systems-garner/">this ETF Trading book</a> by Anthony Garner for example). An assumption in that book (which I will attempt to verify in a next post) is that <strong>futures can act as proxies for ETFs/ETCs</strong>.</p>
<h3>Contract Rolling and Testing</h3>
<p>Rolling contracts is a process necessary to generate a continuous time-series for back-testing futures instruments. There are many different ways to perform this operation (some of which are covered just below). What is important is that <strong>the continuous contract should be a realistic representation of one&#8217;s trading</strong>.</p>
<h3>Proportional vs Point-Based Adjustments</h3>
<p>At the time of writing these posts on continuous contracts, I was leaning towards the idea that proportional adjustment was the way to go:</p>
<p>&#8220;<em>This ensures a constant relative (percentage-wise) relationship between any prices across the trading history</em>&#8220;, as opposed to the point-based adjustment, with which &#8220;<em>you lose relative price difference (shifting all prices by an absolute amount has that effect on percentage changes: 10 to 11 is +10% but add 100 to both for an extreme case and 110 to 111 becomes less than +1%)</em>&#8220;.</p>
<p>When back-testing with <strong>Trading Blox</strong>, the standard functionality expects the prices to be <strong>point-based adjusted</strong>, to calculate trade PnL:<br />
(ExitPrice &#8211; EntryPrice) * BigPointValue * NumberContracts<br />
With a point-based adjustment, the number of points between entry and exit will represent the actual points the market has moved during the life of the trade, as opposed to proportional adjustment (which would give wrong PnL calculations).</p>
<p>But point-based adjustments prevents us from using relative price difference, such as &#8220;check if close today is 5% higher than close yesterday&#8221; as an example. This might be an issue for some systems, but there are workarounds for this in Trading Blox though.</p>
<p>We do not <em>have to</em> limit ourselves to one or the other  methodology, but we have to understand what the rolling algorithm represents and which data best suit each test.</p>
<p>Of course, you can even go with a more fancy approach to rolling (if this represents what your trading is), like one we had covered here last year with a <a href="http://www.automated-trading-system.com/better-trend-following-improved-roll-yield/">rolling methodology attempting to optimize roll yield</a>.</p>
<h3>Back-Adjusted or Forward-Adjusted?</h3>
<p>Another switch on the rolling methodology dashboard (in CSI) is the possibility to perform <strong>back-adjustments or forward adjustments</strong>. This only determines which price is fixed and in which direction the &#8220;adjustment drift&#8221; will propagate through the time-series. Forward-adjustment picks the earliest price as the reference price and moves each following contract by the required adjustment amount/ratio to fill the &#8220;rolling gap&#8221;. Backward-adjustment is the opposite: reference price is last price and adjustment propagates backward.</p>
<p>In order to get recent prices in line with real price levels, most traders prefer back-adjustment. From a back-testing point of view, it should not have <em>much</em> impact. However, the chart time-series will look quite different.</p>
<p>To illustrate this, here is an example chart plotting the same underlying (Crude Oil) since 2007, with four different standard CSI rolling methodologies:</p>
<ul>
<li>Proportional, Forward Adjustment</li>
<li>Proportional, Backward Adjustment</li>
<li>Point-based, Forward Adjustment</li>
<li>Point-based, Backward Adjustment</li>
</ul>
<div id="attachment_3850" class="wp-caption alignnone" style="width: 480px"><img src="http://www.automated-trading-system.com/wp-content/uploads/2011/01/rolled-contracts.png" alt="Mix of Point and Proportional, Back and Forward Adjustments" title="rolled-contracts" width="470" height="380" class="size-full wp-image-3850" /><p class="wp-caption-text">Mix of Point and Proportional, Back and Forward Adjustments</p></div>
<p>Going back to the monthly trading test, I did take my data &#8220;for granted&#8221; as it works for most cases&#8230; but not really for this one. It does emphasise the point that &#8220;Trade what you Test and Test what you Trade&#8221; should also apply to data and rolling methodologies, which need to be checked/reviewed for each new system.<br />
&nbsp;<br />
&nbsp;</p>
<div style="font-size: 0.8em;">Credits: thanks to Pumpernickel for the comment pointing out the discrepancy in the previous post between daily roll-over and monthly signal taking (and for this post title contribution, as part of a comment on an earlier post).<br />
Picture Credits: Trading Blox screenshot and artemuestra@flickr(CC).</div>
]]></content:encoded>
			<wfw:commentRss>http://www.automated-trading-system.com/trade-what-you-test-and-test-what-you-trade/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>CSI &#8211; Au.Tra.Sy: A new Partnership for 2011</title>
		<link>http://www.automated-trading-system.com/csi-discount-coupon-code/</link>
		<comments>http://www.automated-trading-system.com/csi-discount-coupon-code/#comments</comments>
		<pubDate>Fri, 07 Jan 2011 08:27:45 +0000</pubDate>
		<dc:creator>Jez Liberty</dc:creator>
				<category><![CDATA[Data]]></category>
		<category><![CDATA[CSI]]></category>

		<guid isPermaLink="false">http://www.automated-trading-system.com/?p=3766</guid>
		<description><![CDATA[Just a quick note to let you know that CSI and Au.Tra.Sy have partnered to offer the readers of the blog a 10% discount on new subscriptions to CSI data and their software Unfair Advantage. Simply go to their order page and make sure to enter the coupon code LIBERTY. I use CSI as my [...]]]></description>
			<content:encoded><![CDATA[<p>Just a quick note to let you know that CSI and Au.Tra.Sy have partnered to offer the readers of the blog a <strong>10% discount</strong> on new subscriptions to CSI data and their software Unfair Advantage. Simply go to their <a href="http://www.automated-trading-system.com/csi" target="_blank" rel="nofollow">order page</a> and make sure to enter the <strong>coupon code LIBERTY</strong>.</p>
<p>I use CSI as my main source of data, including for all the research published on the blog and I have no problems recommending them.</p>
<p>So, when they approached me with a proposition for a &#8220;partnership&#8221;, which could also benefit the blog readers, I did not really hesitate.</p>
<p>I hope some of you can benefit from this offer &#8211; and unlike the January sale, it will be there all year.</p>
<p>Disclaimer (in the interest of transparency): any reader signing up to CSI using the coupon code would result in an affiliate commission &#8211; on top of your discount. A win-win proposition in a way. Note that I am a paying CSI customer and have been enjoying their data services for 2 years now (I use the Gold World Futures package and am about to get the Gold Stocks package).</p>
<p>For more info on CSI, please find below is a list of posts I ran a while ago on CSI data, their API, etc.:</p>
<ul>
<li><a href="http://www.automated-trading-system.com/unfair-advantage-csi/">I just got myself an Unfair Advantage&#8230;</a></li>
<li><a href="http://www.automated-trading-system.com/continuous-contract-options/">Continuous Contract options</a></li>
<li><a href="http://www.automated-trading-system.com/unfair-advantage-api-retrieve-back-adjusted-contracts-function/">Unfair Advantage API: Retrieve Back-Adjusted Contracts function</a></li>
<li><a href="http://www.automated-trading-system.com/unfair-advantage-api-code-c-extract-futures-continuous-data/">Unfair Advantage API Code (C#): Extract Futures Continuous data</a></li>
<li><a href="http://www.automated-trading-system.com/csi-raw-contract-data-extractor/">CSI Raw Contract Data Extractor</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.automated-trading-system.com/csi-discount-coupon-code/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Word of Caution on Statistics</title>
		<link>http://www.automated-trading-system.com/word-of-caution-on-statistics/</link>
		<comments>http://www.automated-trading-system.com/word-of-caution-on-statistics/#comments</comments>
		<pubDate>Wed, 20 Oct 2010 10:04:30 +0000</pubDate>
		<dc:creator>Jez Liberty</dc:creator>
				<category><![CDATA[Data]]></category>
		<category><![CDATA[anscombe]]></category>

		<guid isPermaLink="false">http://www.automated-trading-system.com/?p=3218</guid>
		<description><![CDATA[This is really a post where 1 picture = 1,000 words, so please consider the datasets charted below: Pretty different graphs, right? Yet, you might be surprised to hear that they are all identical in the light of common summary statistics: mean, variance, (Pearson) correlation and linear regression. Here are the exact figures: Property Value [...]]]></description>
			<content:encoded><![CDATA[<p>This is really a post where 1 picture = 1,000 words, so please consider the datasets charted below:</p>
<div id="attachment_3219" class="wp-caption aligncenter" style="width: 484px"><img src="http://www.automated-trading-system.com/wp-content/uploads/2010/10/500px-Anscombes_quartet_3.svg.png" alt="Anscombe&#039;s quartet" title="500px-Anscombe&#039;s_quartet_3.svg" width="474" height="347" class="size-full wp-image-3219" /><p class="wp-caption-text">Anscombe's quartet</p></div>
<p>Pretty different graphs, right?</p>
<p>Yet, you might be surprised to hear that <strong>they are all identical</strong> in the light of common summary statistics: mean, variance, (Pearson) correlation and linear regression.</p>
<p>Here are the exact figures:<span id="more-3218"></span></p>
<table style="border:1px solid #c3c3c3; border-collapse:collapse;">
<tr>
<th style="background-color:#e5eecc; border:1px solid #c3c3c3; padding:3px;">Property</th>
<th style="background-color:#e5eecc; border:1px solid #c3c3c3; padding:3px;">Value</th>
</tr>
<tr>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding:3px;">Mean of <i>x</i> in each case</td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding:3px;">9.0</td>
</tr>
<tr>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding:3px;">Variance of <i>x</i> in each case</td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding:3px;">11.0</td>
</tr>
<tr>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding:3px;">Mean of <i>y</i> in each case</td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding:3px;">7.5</td>
</tr>
<tr>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding:3px;">Variance of <i>y</i> in each case</td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding:3px;">4.12</td>
</tr>
<tr>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding:3px;">Correlation between <i>x</i> and <i>y</i> in each case</td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding:3px;">0.816</td>
</tr>
<tr>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding:3px;">Linear regression line in each case</td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding:3px;"><i>y</i> = 3 + 0.5<i>x</i></td>
</tr>
</table>
<p>&nbsp;<br />
Details of all dataset points are at the bottom of this post if you fancy double-checking this yourself.</p>
<p>Credits for this amusing and quite extraordinary illustration go to statistician Francis Anscombe, who created this <strong>Anscombe&#8217;s Quartet</strong> back in 1973 (more info on <a href="http://en.wikipedia.org/wiki/Anscombe%27s_quartet" target="_blank" rel="nofollow">wikipedia</a>).</p>
<p>I believe Anscombe&#8217;s main point was to prove that statistics <em>can be</em> misleading (a fact greatly abused by today&#8217;s media?) but also that outliers can have a strong impact on statistical properties. Surely two points that can impact your trading system design and testing conclusions.</p>
<h3>Exploratory Data Analysis</h3>
<p>Anscombe&#8217;s quartet is often used to highlight the importance of graphical exploration of the data for analysis. This concept is behind an area of statistics known as <strong>Exploratory Data Analysis</strong>. From <a href="http://en.wikipedia.org/wiki/Exploratory_data_analysis" target="_blank" rel="nofollow">wikipedia</a>:</p>
<blockquote><p>Exploratory data analysis (EDA) is an approach to analysing data for the purpose of formulating hypotheses worth testing, complementing the tools of conventional statistics for testing hypotheses. It was so named by John Tukey to contrast with Confirmatory Data Analysis, the term used for the set of ideas about hypothesis testing, p-values, confidence intervals etc. which formed the key tools in the arsenal of practising statisticians at the time.</p>
<p>The objectives of EDA are to:</p>
<ul>
<li>Suggest hypotheses about the causes of observed phenomena</li>
<li>Assess assumptions on which statistical inference will be based</li>
<li>Support the selection of appropriate statistical tools and techniques</li>
<li>Provide a basis for further data collection through surveys or experiments</li>
</ul>
</blockquote>
<p>&nbsp;<br />
&nbsp;<br />
In <a href="http://www.thehedgefundjournal.com/magazine/200509/interviews/simon-kerr-talks-to-david-harding.php" target="_blank" rel="nofollow">this interview</a>, David Harding, from Winton Capital Management, stresses the importance of research and statistical data analysis in his company. The two books he highlights cover Exploratory Data Analysis (<a href="http://www.amazon.com/exec/obidos/ASIN/0471384917/autotradblog-20" target="_blank" rel="nofollow">Understanding robust and exploratory data analysis</a> and <a href="http://www.amazon.com/exec/obidos/ASIN/0824786610/autotradblog-20" target="_blank" rel="nofollow">Nonparametric Statistical Inference</a>).</p>
<h3>Correlation</h3>
<p>Another topic that Anscombe&#8217;s quartet illustrates is correlation (and non-linearity).</p>
<p>The most common measure of correlation is <strong>Pearson product-moment correlation coefficient</strong>. Its calculation only derives the <strong>linear</strong> dependence between two variables. If a non-linear relationship exists between these variables, it will go undetected by the Pearson correlation.</p>
<p>To illustrate this, consider Anscombe&#8217;s top right dataset, exhibiting a perfect functional relationship between x and y. The correlation should be 1, yet the Pearson coefficient is irrelevant at 0.816.</p>
<p>Consider the following more extreme case (of the type y=(x-a)^2 + b), where a <strong>100% relationship</strong> translates in a <strong>zero</strong> linear/Pearson <strong>correlation</strong>:</p>
<p><img src="http://www.automated-trading-system.com/wp-content/uploads/2010/10/correlation0.0.png" alt="Correlation 0" title="correlation 0" width="200" height="178" class="size-full wp-image-3226" /></p>
<p>Taleb is probably a bit extreme when he says:</p>
<blockquote><p>Anything that relies on correlation is charlatanism.</p></blockquote>
<p>But using correlation on market data, typically described as non-linear, can have its pitfalls.<br />
I was re-reading Ralph Vince&#8217;s paper on <a href="http://www.automated-trading-system.com/vince-leverage-space-model/">Leverage Space Model</a> not long ago and he describes the <strong>fallacy of correlation</strong>:</p>
<blockquote><p>Correlation fails when you are counting on it the most – at the (fat) tails of the distribution. The point is evident throughout this study; big moves in one market amplify the correlation between other markets, and vice versa</p></blockquote>
<p>In the paper, he explains that correlation between two instruments becomes much stronger during periods of large standard-deviation moves (when potentially diversification/non-correlation would be required most).</p>
<h3>RIP Benoît Mandelbrot (20/11/1924 – 14/10/2010)</h3>
<table>
<tr>
<td><img src="http://www.automated-trading-system.com/wp-content/uploads/2010/10/MandelbrotSet.jpg" alt="MandelbrotSet" title="MandelbrotSet" width="160" height="120" class="alignleft size-full wp-image-3239" /></td>
<td><img src="http://www.automated-trading-system.com/wp-content/uploads/2010/10/Benoit_Mandelbrot.jpg" alt="Benoit_Mandelbrot" title="Benoit_Mandelbrot" width="120" height="120" class="alignleft size-full wp-image-3240" /></td>
<td><img src="http://www.automated-trading-system.com/wp-content/uploads/2010/10/Mandelbrot_zoom2.gif" alt="Mandelbrot_zoom2" title="Mandelbrot_zoom2" width="120" height="120" class="alignleft size-full wp-image-3241" /></td>
</tr>
</table>
<p>&nbsp;<br />
Finally, I would like to pay tribute to Benoît Mandelbrot, who passed away last week.</p>
<p>Mandelbrot has been dubbed &#8220;The Father of Fractals&#8221; and spent a big part of his life trying to understand how markets work. Looking at market data through the prism of <strong>fractal geometry</strong>, he tried to uncover non-linear, chaotic relationships in the data.</p>
<p>I&#8217;ll reiterate my recommendation to read his book, <a href="http://www.amazon.com/exec/obidos/ASIN/0465043577/autotradblog-20" target="_blank" rel="nofollow">The (Mis)Behavior of Markets</a> &#8211; one of the most enjoyable rebuttals of the Efficient Market Hypothesis. Although I have not (yet) found a practical application of the principles described in his book and papers, Mandelbrot&#8217;s attempt to define a new paradigm to understand the markets is interesting &#8211; and it is a book that reinforced my belief and understanding of Trend Following (despite not covering this topic explicitely).</p>
<p>One of his main finding is that price changes in financial markets do not follow a normal (Gaussian) distribution, but rather a fat-tailed distribution (Levy, Paretian or also called power-law distributions). This is potentially one of the main reasons for Trend Following to work (well that&#8217;s <a href="http://www.automated-trading-system.com/why-trend-following-works-look-at-the-distribution/">my interpretation</a>).</p>
<p>I might actually pick up that book again and read it soon (and write a summary post on it).<br />
&nbsp;<br />
&nbsp;</p>
<div style="font-size: 0.8em;">The Anscombe&#8217;s quartet illustration is from <a href="http://en.wikipedia.org/wiki/File:Anscombe%27s_quartet_3.svg" target="_blank" rel="nofollow">wikipedia</a>, under a <a href="http://creativecommons.org/licenses/by-sa/3.0/deed.en" target="_blank" rel="nofollow">CC</a> license.</div>
<h3>Appendix: Dataset point coordinates:</h3>
<table style="border:1px solid #c3c3c3; border-collapse:collapse;">
<tr>
<th style="background-color:#e5eecc; border:1px solid #c3c3c3; padding:1px;" colspan="2">I</th>
<th style="background-color:#e5eecc; border:1px solid #c3c3c3; padding:1px;" colspan="2">II</th>
<th style="background-color:#e5eecc; border:1px solid #c3c3c3; padding:1px;" colspan="2">III</th>
<th style="background-color:#e5eecc; border:1px solid #c3c3c3; padding:1px;" colspan="2">IV</th>
</tr>
<tr>
<td align="center" style="background-color:#ffffff; border:1px solid #c3c3c3; padding:1px;">x</td>
<td align="center" style="background-color:#ffffff; border:1px solid #c3c3c3; padding:1px;">y</td>
<td align="center" style="background-color:#ffffff; border:1px solid #c3c3c3; padding:1px;">x</td>
<td align="center" style="background-color:#ffffff; border:1px solid #c3c3c3; padding:1px;">y</td>
<td align="center" style="background-color:#ffffff; border:1px solid #c3c3c3; padding:1px;">x</td>
<td align="center" style="background-color:#ffffff; border:1px solid #c3c3c3; padding:1px;">y</td>
<td align="center" style="background-color:#ffffff; border:1px solid #c3c3c3; padding:1px;">x</td>
<td align="center" style="background-color:#ffffff; border:1px solid #c3c3c3; padding:1px;">y</td>
</tr>
<tr>
<td align="center" style="background-color:#ffffff; border:1px solid #c3c3c3; padding:1px;">10.0</td>
<td align="center" style="background-color:#ffffff; border:1px solid #c3c3c3; padding:1px;">8.04</td>
<td align="center" style="background-color:#ffffff; border:1px solid #c3c3c3; padding:1px;">10.0</td>
<td align="center" style="background-color:#ffffff; border:1px solid #c3c3c3; padding:1px;">9.14</td>
<td align="center" style="background-color:#ffffff; border:1px solid #c3c3c3; padding:1px;">10.0</td>
<td align="center" style="background-color:#ffffff; border:1px solid #c3c3c3; padding:1px;">7.46</td>
<td align="center" style="background-color:#ffffff; border:1px solid #c3c3c3; padding:1px;">8.0</td>
<td align="center" style="background-color:#ffffff; border:1px solid #c3c3c3; padding:1px;">6.58</td>
</tr>
<tr>
<td align="center" style="background-color:#ffffff; border:1px solid #c3c3c3; padding:1px;">8.0</td>
<td align="center" style="background-color:#ffffff; border:1px solid #c3c3c3; padding:1px;">6.95</td>
<td align="center" style="background-color:#ffffff; border:1px solid #c3c3c3; padding:1px;">8.0</td>
<td align="center" style="background-color:#ffffff; border:1px solid #c3c3c3; padding:1px;">8.14</td>
<td align="center" style="background-color:#ffffff; border:1px solid #c3c3c3; padding:1px;">8.0</td>
<td align="center" style="background-color:#ffffff; border:1px solid #c3c3c3; padding:1px;">6.77</td>
<td align="center" style="background-color:#ffffff; border:1px solid #c3c3c3; padding:1px;">8.0</td>
<td align="center" style="background-color:#ffffff; border:1px solid #c3c3c3; padding:1px;">5.76</td>
</tr>
<tr>
<td align="center" style="background-color:#ffffff; border:1px solid #c3c3c3; padding:1px;">13.0</td>
<td align="center" style="background-color:#ffffff; border:1px solid #c3c3c3; padding:1px;">7.58</td>
<td align="center" style="background-color:#ffffff; border:1px solid #c3c3c3; padding:1px;">13.0</td>
<td align="center" style="background-color:#ffffff; border:1px solid #c3c3c3; padding:1px;">8.74</td>
<td align="center" style="background-color:#ffffff; border:1px solid #c3c3c3; padding:1px;">13.0</td>
<td align="center" style="background-color:#ffffff; border:1px solid #c3c3c3; padding:1px;">12.74</td>
<td align="center" style="background-color:#ffffff; border:1px solid #c3c3c3; padding:1px;">8.0</td>
<td align="center" style="background-color:#ffffff; border:1px solid #c3c3c3; padding:1px;">7.71</td>
</tr>
<tr>
<td align="center" style="background-color:#ffffff; border:1px solid #c3c3c3; padding:1px;">9.0</td>
<td align="center" style="background-color:#ffffff; border:1px solid #c3c3c3; padding:1px;">8.81</td>
<td align="center" style="background-color:#ffffff; border:1px solid #c3c3c3; padding:1px;">9.0</td>
<td align="center" style="background-color:#ffffff; border:1px solid #c3c3c3; padding:1px;">8.77</td>
<td align="center" style="background-color:#ffffff; border:1px solid #c3c3c3; padding:1px;">9.0</td>
<td align="center" style="background-color:#ffffff; border:1px solid #c3c3c3; padding:1px;">7.11</td>
<td align="center" style="background-color:#ffffff; border:1px solid #c3c3c3; padding:1px;">8.0</td>
<td align="center" style="background-color:#ffffff; border:1px solid #c3c3c3; padding:1px;">8.84</td>
</tr>
<tr>
<td align="center" style="background-color:#ffffff; border:1px solid #c3c3c3; padding:1px;">11.0</td>
<td align="center" style="background-color:#ffffff; border:1px solid #c3c3c3; padding:1px;">8.33</td>
<td align="center" style="background-color:#ffffff; border:1px solid #c3c3c3; padding:1px;">11.0</td>
<td align="center" style="background-color:#ffffff; border:1px solid #c3c3c3; padding:1px;">9.26</td>
<td align="center" style="background-color:#ffffff; border:1px solid #c3c3c3; padding:1px;">11.0</td>
<td align="center" style="background-color:#ffffff; border:1px solid #c3c3c3; padding:1px;">7.81</td>
<td align="center" style="background-color:#ffffff; border:1px solid #c3c3c3; padding:1px;">8.0</td>
<td align="center" style="background-color:#ffffff; border:1px solid #c3c3c3; padding:1px;">8.47</td>
</tr>
<tr>
<td align="center" style="background-color:#ffffff; border:1px solid #c3c3c3; padding:1px;">14.0</td>
<td align="center" style="background-color:#ffffff; border:1px solid #c3c3c3; padding:1px;">9.96</td>
<td align="center" style="background-color:#ffffff; border:1px solid #c3c3c3; padding:1px;">14.0</td>
<td align="center" style="background-color:#ffffff; border:1px solid #c3c3c3; padding:1px;">8.10</td>
<td align="center" style="background-color:#ffffff; border:1px solid #c3c3c3; padding:1px;">14.0</td>
<td align="center" style="background-color:#ffffff; border:1px solid #c3c3c3; padding:1px;">8.84</td>
<td align="center" style="background-color:#ffffff; border:1px solid #c3c3c3; padding:1px;">8.0</td>
<td align="center" style="background-color:#ffffff; border:1px solid #c3c3c3; padding:1px;">7.04</td>
</tr>
<tr>
<td align="center" style="background-color:#ffffff; border:1px solid #c3c3c3; padding:1px;">6.0</td>
<td align="center" style="background-color:#ffffff; border:1px solid #c3c3c3; padding:1px;">7.24</td>
<td align="center" style="background-color:#ffffff; border:1px solid #c3c3c3; padding:1px;">6.0</td>
<td align="center" style="background-color:#ffffff; border:1px solid #c3c3c3; padding:1px;">6.13</td>
<td align="center" style="background-color:#ffffff; border:1px solid #c3c3c3; padding:1px;">6.0</td>
<td align="center" style="background-color:#ffffff; border:1px solid #c3c3c3; padding:1px;">6.08</td>
<td align="center" style="background-color:#ffffff; border:1px solid #c3c3c3; padding:1px;">8.0</td>
<td align="center" style="background-color:#ffffff; border:1px solid #c3c3c3; padding:1px;">5.25</td>
</tr>
<tr>
<td align="center" style="background-color:#ffffff; border:1px solid #c3c3c3; padding:1px;">4.0</td>
<td align="center" style="background-color:#ffffff; border:1px solid #c3c3c3; padding:1px;">4.26</td>
<td align="center" style="background-color:#ffffff; border:1px solid #c3c3c3; padding:1px;">4.0</td>
<td align="center" style="background-color:#ffffff; border:1px solid #c3c3c3; padding:1px;">3.10</td>
<td align="center" style="background-color:#ffffff; border:1px solid #c3c3c3; padding:1px;">4.0</td>
<td align="center" style="background-color:#ffffff; border:1px solid #c3c3c3; padding:1px;">5.39</td>
<td align="center" style="background-color:#ffffff; border:1px solid #c3c3c3; padding:1px;">19.0</td>
<td align="center" style="background-color:#ffffff; border:1px solid #c3c3c3; padding:1px;">12.50</td>
</tr>
<tr>
<td align="center" style="background-color:#ffffff; border:1px solid #c3c3c3; padding:1px;">12.0</td>
<td align="center" style="background-color:#ffffff; border:1px solid #c3c3c3; padding:1px;">10.84</td>
<td align="center" style="background-color:#ffffff; border:1px solid #c3c3c3; padding:1px;">12.0</td>
<td align="center" style="background-color:#ffffff; border:1px solid #c3c3c3; padding:1px;">9.13</td>
<td align="center" style="background-color:#ffffff; border:1px solid #c3c3c3; padding:1px;">12.0</td>
<td align="center" style="background-color:#ffffff; border:1px solid #c3c3c3; padding:1px;">8.15</td>
<td align="center" style="background-color:#ffffff; border:1px solid #c3c3c3; padding:1px;">8.0</td>
<td align="center" style="background-color:#ffffff; border:1px solid #c3c3c3; padding:1px;">5.56</td>
</tr>
<tr>
<td align="center" style="background-color:#ffffff; border:1px solid #c3c3c3; padding:1px;">7.0</td>
<td align="center" style="background-color:#ffffff; border:1px solid #c3c3c3; padding:1px;">4.82</td>
<td align="center" style="background-color:#ffffff; border:1px solid #c3c3c3; padding:1px;">7.0</td>
<td align="center" style="background-color:#ffffff; border:1px solid #c3c3c3; padding:1px;">7.26</td>
<td align="center" style="background-color:#ffffff; border:1px solid #c3c3c3; padding:1px;">7.0</td>
<td align="center" style="background-color:#ffffff; border:1px solid #c3c3c3; padding:1px;">6.42</td>
<td align="center" style="background-color:#ffffff; border:1px solid #c3c3c3; padding:1px;">8.0</td>
<td align="center" style="background-color:#ffffff; border:1px solid #c3c3c3; padding:1px;">7.91</td>
</tr>
<tr>
<td align="center" style="background-color:#ffffff; border:1px solid #c3c3c3; padding:1px;">5.0</td>
<td align="center" style="background-color:#ffffff; border:1px solid #c3c3c3; padding:1px;">5.68</td>
<td align="center" style="background-color:#ffffff; border:1px solid #c3c3c3; padding:1px;">5.0</td>
<td align="center" style="background-color:#ffffff; border:1px solid #c3c3c3; padding:1px;">4.74</td>
<td align="center" style="background-color:#ffffff; border:1px solid #c3c3c3; padding:1px;">5.0</td>
<td align="center" style="background-color:#ffffff; border:1px solid #c3c3c3; padding:1px;">5.73</td>
<td align="center" style="background-color:#ffffff; border:1px solid #c3c3c3; padding:1px;">8.0</td>
<td align="center" style="background-color:#ffffff; border:1px solid #c3c3c3; padding:1px;">6.89</td>
</tr>
</table>
]]></content:encoded>
			<wfw:commentRss>http://www.automated-trading-system.com/word-of-caution-on-statistics/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Roll Yield and Commodity Yield Curve</title>
		<link>http://www.automated-trading-system.com/roll-yield-commodity-yield-curve/</link>
		<comments>http://www.automated-trading-system.com/roll-yield-commodity-yield-curve/#comments</comments>
		<pubDate>Mon, 19 Jul 2010 06:54:33 +0000</pubDate>
		<dc:creator>Jez Liberty</dc:creator>
				<category><![CDATA[Data]]></category>
		<category><![CDATA[Futures]]></category>
		<category><![CDATA[roll yield]]></category>
		<category><![CDATA[yield curve]]></category>

		<guid isPermaLink="false">http://www.automated-trading-system.com/?p=2478</guid>
		<description><![CDATA[We have seen previously that backwardation and/or contango can induce a fairly large drift between the performance of an instrument&#8217;s spot market and its corresponding futures market. This phenomenon can be described as roll yield of futures trading and I suggested it was one of the four components in Trend Following returns. As per that [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.automated-trading-system.com/wp-content/uploads/2010/07/3d-yield-curves.png" alt="3d-yield-curves" title="3d-yield-curves" width="421" height="300" class="aligncenter size-full wp-image-2479" /></p>
<p>We have seen <a href="http://www.automated-trading-system.com/crude-oil-contango-and-roll-yield-for-commodity-trading/">previously</a> that <strong>backwardation</strong> and/or <strong>contango</strong> can induce a fairly large drift between the performance of an instrument&#8217;s spot market and its corresponding futures market.</p>
<p>This phenomenon can be described as <strong>roll yield of futures trading</strong> and I suggested it was one of the <a href="http://www.automated-trading-system.com/trend-following-returns-breakdown/">four components in Trend Following returns</a>. As per that last post&#8217;s conclusion, breaking down the returns should allow to focus, study and improve a trading system&#8217;s individual component &#8211; and this is what we are doing here with the roll yield, by looking into the <strong>Commodity Yield Curve</strong>.</p>
<p>The roll yield had a negative impact in the Crude Oil example, however let&#8217;s explore how it could be turned into an <strong>extra source of profit</strong>&#8230;</p>
<h3>Term Structure &#8211; or Yield Curve</h3>
<p><strong>Term structure</strong> best applies to interest rates analysis. If we take the example of US Treasuries; they cover a wide range of maturities, from T-Bills (one year or less maturity)  , T-Notes (one year to ten years) to T-Bonds (up to thirty years). For any given date, each treasury is priced depending on its maturity and an implied yield can be derived for each maturity. Charting these yields for each maturity gives the <strong>yield curve</strong>, also called <strong>term structure of interest rates</strong>.<span id="more-2478"></span></p>
<p>Below can be found a &#8220;normal&#8221; (upward sloping) yield curve for US Treasuries (from last Friday) showing that yields went slightly down  in the middle of the curve whereas the short and long ends of the curve did not change much:</p>
<p><img src="http://www.automated-trading-system.com/wp-content/uploads/2010/07/yield-cruve.png" alt="yield-cruve" title="yield-cruve" width="484" height="271" class="alignnone size-full wp-image-2480" /></p>
<p>The yield curve, or term structures of interest rates is a major economic indicator, closely watched by many traders to gain insights in the market. You can read more about it at <a href="http://www.investopedia.com/university/advancedbond/advancedbond4.asp" target="_blank" rel="nofollow">investopedia</a> and <a href="http://en.wikipedia.org/wiki/Yield_curve" target="_blank" rel="nofollow">wikipedia</a>.</p>
<h3>Application in Futures Trading</h3>
<p><strong>Term structure</strong> can be similarly transposed to <strong>futures trading</strong>, which deals with the same concept of trading the same instrument (i.e. where a commodity like Corn replaces <em>money</em> used in the case of the <em>classic</em> yield curve) with different maturities (all different contracts and their various expiry/delivery months).</p>
<p>Note that the term <strong>Commodity Yield Curve</strong> is a bit of misnomer as the concept could be applied to any instrument traded in different maturities (i.e. all futures for instance).</p>
<h3>Commodity/Futures Yield Curve: How to Build it?</h3>
<p>The <strong>futures yield curve</strong> is a representation of the <strong>backwardation/contango rate</strong> for the <strong>different maturities of futures contracts</strong>. The contango/backwardation rates are calculated by taking the price difference between the spot/cash market price and the futures contract price. This difference can be expressed as a percentage (for x number of days: time to expiration of the futures contract) and then annualised to calculate an annual contango or backwardation rate, representing an implied yield for the specific maturity.</p>
<p>For example, if the spot market trades at 70 and the October contract (expiring in 90 days) trades at 71, the yield can be calculated as follows:</p>
<ol>
<li>Price difference = 71 &#8211; 70 = 1</li>
<li>Percentage price difference = 1/70 = 1.43% (for 90 days)</li>
<li>Annualised contango rate (yield) = (1.43% + 1)^(365/90) &#8211; 1 = 5.92%</li>
</ol>
<p>Performing this calculation for each contract/maturity would allow to chart a futures yield curve.</p>
<h3>Volatility of the Yield Curve</h3>
<p>I calculated and charted the Crude Oil yield curve in order to analyse and visualise the evolution of the contango/backwardation rates, both across the historical timeline and the range of contract maturities. This was done as discussed above for all contracts available for a given date.</p>
<p>Here is a sample chart using data from December 03 to January 04 where Crude Oil was trading in <em>backwardation</em>:</p>
<p><img src="http://www.automated-trading-system.com/wp-content/uploads/2010/07/backwardation-yield-curve.png" alt="backwardation-yield-curve" title="backwardation-yield-curve" width="493" height="411" class="alignnone size-full wp-image-2495" /></p>
<p>Each &#8220;ribbon&#8221; on the chart represents the yields for all 18 different maturities (1=short, 18=long) for a given date: each ribbon represents the yield curve for that day. All yields are negative because of the backwardated aspect of Crude Oil at the time. Backwardation rates have <em>reasonable </em>values (-15%/+5%) and the associated yield curves vary slightly across time, albeit maintaining a similar pattern.</p>
<p>However this snapshot was taken at relatively quiet times in the market. Fast forward to 2009 and you can see that the market now exhibits contango, with rates spiking to much higher values:</p>
<p><img src="http://www.automated-trading-system.com/wp-content/uploads/2010/07/contango-yield-curve.png" alt="contango-yield-curve" title="contango-yield-curve" width="490" height="404" class="alignnone size-full wp-image-2496" /></p>
<p>Adding any more dates to this chart would make it hardly readable, but to give an idea of how the term structure of Crude Oil can vary over a longer period of time, I have simply plotted the shortest end of the curve (i.e. yields for the contract with closest maturity), which you can imagine as a &#8220;vertical slice&#8221; of the 3-D chart alongside the date axis, where maturity = 1. Here is the chart:</p>
<p><img src="http://www.automated-trading-system.com/wp-content/uploads/2010/07/short-term-yield.png" alt="short-term-yield" title="short-term-yield" width="496" height="321" class="alignnone size-full wp-image-2497" /></p>
<p>There are spikes, alternation between contango and backwardation. It clearly displays some volatility and, for lack of a better term, a <em>character of its own</em>.</p>
<p>Note that because the yield is calculated as an implied value based solely on the price difference between contracts, some discrepancies in these contract prices (for whatever reason) would impact the curve in a more volatile and &#8220;artificial&#8221; way than if it did purely represent the fundamental yield factors (cost of carry, supply/demand and shortage, convenience yield, etc.)</p>
<h3>Some Observations</h3>
<p>The main observations are:</p>
<ul>
<li>Yield curves and their associated contango and backwardation rates evolve in a fairly volatile fashion across time.</li>
<li>For any given date, different contracts and their associated maturities offer different yields, possibly within a wide range of values.</li>
</ul>
<p>This can add an extra dimension to your trading decisions. The yield curve offers other opportunities (than the traditional front-month contract) when wanting to buy or sell any instrument via futures trading. These extra opportunities can be turned into an extra source of profit.</p>
<p>This is really an introduction to a next post, in which we will look into how we can use this information and <strong>apply it to a trading system to improve its roll yield component and enhance its overall performance</strong>.<br />
Stay tuned&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.automated-trading-system.com/roll-yield-commodity-yield-curve/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>CSI Raw Contract Data Extractor</title>
		<link>http://www.automated-trading-system.com/csi-raw-contract-data-extractor/</link>
		<comments>http://www.automated-trading-system.com/csi-raw-contract-data-extractor/#comments</comments>
		<pubDate>Thu, 10 Jun 2010 09:34:38 +0000</pubDate>
		<dc:creator>Jez Liberty</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Data]]></category>
		<category><![CDATA[API]]></category>
		<category><![CDATA[CSI]]></category>
		<category><![CDATA[Unfair Advantage]]></category>

		<guid isPermaLink="false">http://www.automated-trading-system.com/?p=2374</guid>
		<description><![CDATA[I have mentioned before that I use CSI as my main provider for Futures data. Overall, I judge CSI&#8217;s service as good quality &#8211; however one drawback is the closed aspect of the data access. And I decided to write a utility to make it more &#8220;open&#8221;. To access the historical data, you have to [...]]]></description>
			<content:encoded><![CDATA[<div id="attachment_2376" class="wp-caption alignnone" style="width: 428px"><img src="http://www.automated-trading-system.com/wp-content/uploads/2010/06/CSIExtractor.png" alt="CSI Data Extractor: Utility tool to extract CSI data in plain text files" title="CSIExtractor" width="418" height="241" class="size-full wp-image-2376" /><p class="wp-caption-text">CSI Data Extractor: Utility tool to extract CSI data in plain text files</p></div>
<p>I have mentioned <a href="http://www.automated-trading-system.com/unfair-advantage-csi/">before</a> that I use CSI as my main provider for Futures data. Overall, I judge CSI&#8217;s service as good quality &#8211; however one drawback is the <em>closed</em> aspect of the data access. And I decided to write a utility to make it more &#8220;open&#8221;.</p>
<p>To access the historical data, you have to go through their software (Unfair Advantage), which extracts and decrypts it from their proprietary binary format. You can always &#8220;build&#8221; historical files to disk, but these are usually pre-processed with a special algorithm (ie. back-adjusted, etc.).</p>
<p>What more, if you decide to stop your subscription to CSI&#8217;s data services, you will not be able to access any data any more, even historical data downloaded under the subscription contract.</p>
<p>For some of the reasons above, it might be interesting to be able to extract/store CSI&#8217;s <em>raw data</em> in plain text files. This would allow for:</p>
<ul>
<li>Browsing the data outside of the CSI&#8217;s Unfair Advantage software</li>
<li>Applying back-adjustment or other manipulation algorithms not supported by CSI&#8217;s UA (such as calculating the <a href="http://www.automated-trading-system.com/crude-oil-contango-and-roll-yield-for-commodity-trading/">yield curve</a>)</li>
<li>Keep the historical data independently of your CSI subscription</li>
</ul>
<p><span id="more-2374"></span></p>
<p>Note: what I consider CSI raw data is the actual daily information for each contract traded on any day. For example, in the Corn market, there are currently 15 different contracts trading (with different maturities), each with their own Open, High, Low, Close, Volume and Open Interest.</p>
<h3>CSI API to the rescue</h3>
<p>Now, you could easily go to Unfair Advantage and pick every single historical contract that you want to extract&#8230; but this would be a fairly tedious job</p>
<p>Luckily for us, the API allows for programmatic access to CSI&#8217;s data to automate the process of extracting all contracts that we want &#8211; so I decided to write a little utility to do just that.  And now my data is really mine!</p>
<p>Below is a zip file containing the files to copy to &#8220;install&#8221; the utility:</p>
<p><a href='http://www.automated-trading-system.com/wp-content/uploads/2010/06/CSI-DataExtractor.zip'>CSI-DataExtractor.zip</a></p>
<p>Note that you need to have Unfair Advantage installed on the machine running this exe (which does not come with any guarantee by the way&#8230; but I have been using it fine so far).</p>
<p>The operation is very simple: just enter CSI&#8217;s number for the market you want to extract and choose which path the files need to be extracted to.</p>
<p>Hope you&#8217;re finding this tool useful&#8230;</p>
<p><strong>Note</strong>: You can receive a <a href="http://www.automated-trading-system.com/csi" target="_blank" rel="nofollow">10% discount on CSI data subscriptions</a> (use coupon code LIBERTY)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.automated-trading-system.com/csi-raw-contract-data-extractor/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>Data Pitfalls: a true Minefield?</title>
		<link>http://www.automated-trading-system.com/data-pitfalls/</link>
		<comments>http://www.automated-trading-system.com/data-pitfalls/#comments</comments>
		<pubDate>Tue, 04 May 2010 09:55:36 +0000</pubDate>
		<dc:creator>Jez Liberty</dc:creator>
				<category><![CDATA[Data]]></category>
		<category><![CDATA[Back-Adjusted]]></category>
		<category><![CDATA[CSI]]></category>
		<category><![CDATA[rollover]]></category>
		<category><![CDATA[Trading Blox]]></category>

		<guid isPermaLink="false">http://www.automated-trading-system.com/?p=2210</guid>
		<description><![CDATA[In my other job, at a big investment bank, one of our main focus on a daily basis is DATA. Making sure that the hundreds of feeds and millions of records get uploaded correctly and contain the right information is key to a smooth, successful day. There is surely not as much data to interact [...]]]></description>
			<content:encoded><![CDATA[<div id="attachment_2212" class="wp-caption alignnone" style="width: 510px"><img src="http://www.automated-trading-system.com/wp-content/uploads/2010/05/matrix-Pixelsior1.jpg" alt="Data - image by Pixelsior@flickr" title="matrix-Pixelsior" width="500" height="233" class="size-full wp-image-2212" /><p class="wp-caption-text">Data - image by Pixelsior@flickr</p></div>
<p>In my other job, at a big investment bank, one of our main focus <em>on a daily basis</em> is DATA. Making sure that the hundreds of feeds and millions of records get uploaded correctly and contain the right information is key to a smooth, successful day.</p>
<p>There is surely not as much data to interact with in <strong>automatic/systematic trading</strong> but getting data right is equally vital to ensure quality trading or backtesting results.</p>
<p>Even with the best data package, there can be <strong>many pitfalls</strong> to look out for when trading or backtesting a systematic trading strategy. Below is a non-exhaustive list<span id="more-2210"></span> &#8211; please let me know in the comments if you think of anything to add.</p>
<h3>Data Errors</h3>
<p>Despite CSI being deemed one of the <a href="http://www.automated-trading-system.com/unfair-advantage-csi/">most reliable End-Of-Day Data providers</a>, they still send you bogus data (albeit rarely) and you might want to run additional checks to see if the data is valid. Some ideas of checks to perform:</p>
<ul>
<li>Open, Low or Close above the High</li>
<li>Prices = 0</li>
<li>Price/Volume/Open Interest changes above tolerance</li>
<li>Gap in the dates</li>
<li>etc.</li>
</ul>
<p>Of course, this will not catch all errors, but will give a pointer on large data anomalies.</p>
<h3>Static Data</h3>
<p>Back in the bank job, part of the system data which changes infrequently (hence <em>static</em>) is subject to <em>4-eyes approval</em> (basically enforcing that another <em>pair of eyes</em> double-checks the correctness of the data). The idea is that, as this data drives the calculations in the system, any error would give flawed calculation results, and needs double-checking.</p>
<p>The equivalent in the automatic trading system world is the <strong>futures contract specifications and formats</strong> information (price quote type, decimal places, native currency, point value), contained in the <em>FuturesInfo</em> file in TradingBlox. Imagine an error of a factor 10 on the contract point value &#8211; this could have you get in a trade at 10 times the intended position size!</p>
<p>CSI appears to contain several of these errors (they seem to have less focus in getting this type of data right) and even official exchange websites have been seen to quote incorrect information. Reconciling both would be a starting point to getting the right information.</p>
<p>A possible solution to mitigate this problem (when starting trading a new, exotic instrument) is a quick in-and-out trade to double-check the actual information on your broker statement.</p>
<h3>Data History and Overrides</h3>
<p>The CSI data downloading process firstly retrieves all new prices to be stored in the Unfair Advantage database. It then applies potential corrections to past prices, in case errors were present. Rollover logic is applied and the full data history file is generated (to be used in the trading/backtesting software).</p>
<p>The change in data resulting from <strong>error corrections</strong> might change the outcome of past trade results. For example, a data correction in the recent past history might trigger a breakout and therefore a trade, now open. How would you handle this?</p>
<p>Additonally, if the historical data contains errors not corrected by your data provider, you might want to apply <strong>overrides</strong> to correct them yourself. However, since the price history gets re-written everyday, you need to have some form of automated overrides upload.</p>
<p>You might also want to make <strong>daily backups of price files</strong> to be able to compare when price corrections have taken place (and run your system with the exact data that was available on that day).</p>
<h3>Other Data</h3>
<p>Data such as historical FX/interest rates or Margin data are necessary to calculate some of the system statistics (including overall performance).</p>
<p>The <strong>FX rates</strong> are mostly used to convert the P&#038;L from the native contract currency to the main account currency.</p>
<p><strong>Interest rates</strong> would be used to calculate the interest earned on the account, which impact on the overall performance is not negligible for a long-term Trend Following system.</p>
<p>The <strong>Margin data</strong> is useful to determine the total amount of margin your system requires at any one time, with statistics such as the Margin-to-Equity ratio. Unfortunately, it is fairly hard to get hold of this type of data, which changes fairly often, at the discretion of the exchanges. Most backtesting platforms I have come across use a static margin number, which is fairly inaccurate.</p>
<p>To get more accurate results, you could run your backtesting simulations using historical (real or simulated) margin requirements. A method suggested on various forums to estimate historical margin requirements is to run a <strong>regression analysis</strong> between margin requirements (known history) and underlying instrument volatility (using different potential measurements such ATR, High-Low, Bollinger Bands, etc.). Finding a good-fit model would allow you to extrapolate past margin requirements based on volatility.</p>
<p><strong>Holidays</strong> are also useful data to collect, to be able to know which exchanges are open when (note that exchanges can have different holidays even when they are in the same country).</p>
<h3>Backup Provider</h3>
<p>Your main data provider might be down or unavailable (hopefully on rare occasisons only). A backup, alternative source of market data might come in very handy for those special days.</p>
<h3>Back-Adjustments and Rollovers</h3>
<p>There is unfortunately no ideal or universal solution to roll and back-adjust contracts. As discussed earlier, a <a href="http://www.automated-trading-system.com/what-everybody-ought-to-know-about-continous-futures-contracts/">proportional back-adjustment</a> allows for better representations of prices, keeping historical ratio values between all prices. However, backtesting systems usually require point-based back-adjustements in order to calculate the P&#038;L of each trade correctly. You might need to maintain several sets of back-adjusted prices to be used in your simulations.</p>
<p>Furthermore, different instruments might require different rolling logic. Different delivery months in agricultural futures, for example, might relate to different crops. It might not make as much sense to roll from one ot the other in the same way that could be done with equity index futures.</p>
<p><strong>Do you get the rollover information on rollover day?</strong><br />
Let&#8217;s assume that, on Thursday, you receive the data indicating that a roll should have occurred on Tuesday (ie. roll based on Open Interest or Volume shifts). Let&#8217;s also assume that an entry signal was triggered on the Wednesday and that the high volatility of the front contract would have prevented the system from entering the trade (risk management threshold breached) &#8211; whereas the next contract&#8217;s volatility, being much lower, would have allowed the trade. In real life, Wednesday&#8217;s trade would not take place (as the system does not know yet that the contract should have rolled on Tuesday). In backtested life however, Wednesday&#8217;s trade would take place, as the system would assume the roll has taken place on Tuesday. These things do actually happen!</p>
<p>You might want to test using the data as you would have received it, instead of a constructed back-adjusted series, potentially containing hindsight information.</p>
<h3>LME Data</h3>
<p>Some instruments deal in &#8220;strange fashion&#8221; and the London Metal Exchange is a perfect example of this. Trading on the LME is done by purchasing a forward contract with a given maturity (or prompt date). For instance, you might purchase a 3-month forward contract, which will run for the next 3 months gradually maturing to converge to the Cash price (at expiration), including the effect of contango or backwardation. However, the data quoted from CSI (and probably any other data provider) is a new daily quote for a new 3-month forward, which does not reflect real trading.</p>
<p>You would probably need to construct a custom price series with a bespoke algorithm to be able to reflect and backtest real-life trading. This topic was further discussed on a <a href="http://www.tradingblox.com/forum/viewtopic.php?t=7440&#038;start=0&#038;postdays=0&#038;postorder=asc&#038;highlight=" target="_blank">tradingblox forum post</a></p>
<h3>Need for an ETL layer?</h3>
<p>Drawing the parallel to the bank job again, where we use specialised tools/platforms to deal with data (Extract-Transform-Load = ETL); I believe that a similar layer between your data provider(s) and your trading/backtesting system, used to perform data checks, archive, roll and back-adjustments, etc. (all poinst discussed above) is necessary. It could also be used to add extra functionality such as creating spread time series to be traded/backtested as new instruments.</p>
<p>The data issue might not be as much of a trading problem as an IT one, nonetheless it is an important one that needs to be addressed &#8211; or it could impact your trading and backtesting results.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.automated-trading-system.com/data-pitfalls/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Detrending for Trend Following?</title>
		<link>http://www.automated-trading-system.com/detrending-for-trend-following/</link>
		<comments>http://www.automated-trading-system.com/detrending-for-trend-following/#comments</comments>
		<pubDate>Wed, 17 Mar 2010 13:47:27 +0000</pubDate>
		<dc:creator>Jez Liberty</dc:creator>
				<category><![CDATA[Backtest]]></category>
		<category><![CDATA[Data]]></category>
		<category><![CDATA[Trend Following]]></category>
		<category><![CDATA[detrending]]></category>

		<guid isPermaLink="false">http://www.automated-trading-system.com/?p=1923</guid>
		<description><![CDATA[We&#8217;re not rockers&#8230; but let&#8217;s look at detrending price series data for backtesting: Why, How and its relevance for Trend Following. Why Detrend? The main premise for detrending data is to remove the underlying trend effect on the strategy. This is due to the position bias that the strategy can have (eg being long more [...]]]></description>
			<content:encoded><![CDATA[<div><img src="http://www.automated-trading-system.com/wp-content/uploads/2010/03/detrend-seven_resist-2.jpg" alt="detrend-seven_resist-2" title="detrend-seven_resist-2" width="211" height="300" class="alignleft size-full wp-image-1928" style="margin-right:8px;"/>We&#8217;re not rockers&#8230; but let&#8217;s look at detrending price series data for backtesting: Why, How and its relevance for Trend Following.
</div>
<h3>Why Detrend?</h3>
<p>The main premise for <strong>detrending data</strong> is to remove the <strong>underlying trend</strong> effect on the strategy. This is due to the <strong>position bias</strong> that the strategy can have (eg being long more often than short).</p>
<p>Let&#8217;s say your strategy is <em>long</em> 70% of the time; and a <em>bull market</em> is currently taking place, there is a higher probability that you will be profitable. This could be due to the long position bias of your strategy &#8211; which might well become unprofitable during bear markets.</p>
<h3>How to Detrend price data?</h3>
<p>A simple way to detrend the data is to:<span id="more-1923"></span></p>
<ol>
<li>Calculate the underlying trend in your backtest data</li>
<li>Derive the &#8220;daily drift&#8221; from the underlying trend</li>
<li>For each trade in the backtest, adjust the trade return by subtracting the daily drift for each day in the trade</li>
</ol>
<p>For this it is easier to use <strong>log of price differences</strong>.</p>
<p>Step 1: The underlying trend is defined by the difference in price from the start to the end of the backtest:</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:monospace;">Trend = LOG(Price_end / Price_start)</pre></div></div>

<p>Step 2: Simply divide the underlying trend by the number of days in the backtest data:</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:monospace;">Daily Trend Drift (DTD) =
LOG(Price_end / Price_start) / NumDays</pre></div></div>

<p>Step3: For each trade, apply the detrending adjustment calculated above:</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:monospace;">LOG(TradeReturn) =
LOG(SellPrice / BuyPrice) - DTD x NumDaysTrade</pre></div></div>

<p>Note that the backtest is executed on normal, non-detrended data. It is the results that are adjusted by applying the detrending procedure.</p>
<p>Assuming a full reinvestment, the formula for the full detrended backtest result containing &#8220;n&#8221; trades would be as follows:</p>
<p><img src="http://www.automated-trading-system.com/wp-content/uploads/2010/03/Detrending-equation2a.png" alt="Detrending-equation2a" title="Detrending-equation2a" width="194" height="98" class="alignnone size-full wp-image-1926" /><br />
<img src="http://www.automated-trading-system.com/wp-content/uploads/2010/03/Detrending-equation2b.png" alt="Detrending-equation2b" title="Detrending-equation2b" width="536" height="98" class="alignnone size-full wp-image-1927" /></p>
<h3>Detrending for Trend Following</h3>
<p>It might sound paradoxal to remove the data component that is at the heart of the strategy (the trend)&#8230; On one hand, you realise  it might make sense, as the underlying trend is at a much higher timeframe than the trends identified by the strategy. On the other hand, the detrending concept assumes a <strong>dissociation of the position bias and the underlying trend</strong>.<br />
<em>Is it true for Trend Following?</em></p>
<p>We could argue that if the underlying trend is bullish, bullish trends will be prominent at a lower timeframe (vice-versa for bearish trends). By the nature of Trend Following, we would therefore expect the strategy to spend more time in long positions (long position bias). Because Trend Following is exactly that: it adapts and goes in the direction of the trend.</p>
<p>In short: <strong>Trend Following automatically generates position bias in the direction of the trend</strong></p>
<p>If these two variables (position bias and underlying trend) can not seem to be dissociated for Trend Following, it might not make sense to apply detrending for Trend Following.</p>
<h3>Other complications</h3>
<p>The principle of applying a linear/proportional detrending adjustment assumes that the position bias is constant over time. It seems to ignore the potential for cyclical variations, possibly in line with major trend cycles (as would be expected with Trend Following).</p>
<p>For futures data, the detrending impact would be dependent on the method used for <a href="http://www.automated-trading-system.com/continuous-contract-options/">back-adjusted contracts</a>. Point-based back-adjustment, for example, does not respect the proportional ratio between prices and would flaw the underlying trend calculation.</p>
<p>Finally, there are other factors that might need to be taken into account such as Contango and backwardation. The roll yield in futures trading, having possibly as strong an impact on the strategy&#8217;s return.</p>
<p>What are you thoughts on detrending for backtesting?&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.automated-trading-system.com/detrending-for-trend-following/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Why Trend Following works: Autocorrelation?</title>
		<link>http://www.automated-trading-system.com/why-trend-following-works-autocorrelation/</link>
		<comments>http://www.automated-trading-system.com/why-trend-following-works-autocorrelation/#comments</comments>
		<pubDate>Wed, 24 Feb 2010 11:46:09 +0000</pubDate>
		<dc:creator>Jez Liberty</dc:creator>
				<category><![CDATA[Data]]></category>
		<category><![CDATA[Strategies]]></category>
		<category><![CDATA[Trend Following]]></category>
		<category><![CDATA[autocorrelation]]></category>
		<category><![CDATA[distribution]]></category>
		<category><![CDATA[kurtosis]]></category>
		<category><![CDATA[options]]></category>
		<category><![CDATA[Stats]]></category>

		<guid isPermaLink="false">http://www.automated-trading-system.com/?p=1783</guid>
		<description><![CDATA[Is it important to understand why Trend Following works (ie what are the sources of its profitability)? &#160; I believe yes. Because markets are non-stationary (changing all the time), their characteristics &#8211; including those at the root of Trend Following profits &#8211; are changing too. &#160; Understanding these market characteristics is a first step towards [...]]]></description>
			<content:encoded><![CDATA[<p><div id="attachment_1785" class="wp-caption alignleft" style="width: 260px"><img src="http://www.automated-trading-system.com/wp-content/uploads/2010/02/autocorrelation-kylemcdonald-300x300.jpg" alt="some Autocorrelation representation by kylemcdonald@flickr (CC)" title="autocorrelation-kylemcdonald" width="250" height="250" class="size-medium wp-image-1785" /><p class="wp-caption-text">some Autocorrelation representation by kylemcdonald@flickr (CC)</p></div>Is it important to understand <strong>why Trend Following works</strong> (ie what are the sources of its profitability)?<br />
&nbsp;<br />
I believe yes. Because markets are <strong>non-stationary</strong> (changing all the time), their characteristics &#8211; including those at the root of Trend Following profits &#8211; are changing too.<br />
&nbsp;<br />
Understanding these market characteristics is a first step towards being able to <strong>identify and measure them</strong>. This, in turn should be a step to linking Trend Following performance to the state of these market characteristics. Finally, this might be a step towards devising a way for a Trend Following strategy to <strong>adapt to these changing market characteristics</strong> (this last point makes a very big assumption: market characteristic changes can be predicted with some degree of accuracy).</p>
<h3>Kurtosis only?</h3>
<p>In an earlier post, I discussed how <a href="http://www.automated-trading-system.com/why-trend-following-works-look-at-the-distribution/">fat-tails are a reason for Trend Following success</a> (or in technical terms: the <strong>excess kurtosis</strong> of price distributions).</p>
<p>However, there is something unsatisfying in that explanation: if the kurtosis was the sole source of Trend Following success:<span id="more-1783"></span></p>
<ul>
<li>Random entries should work as well as any other entries</li>
<li>Strategies such as buying Out-of-The-Money (OTM) options (think Nassim Taleb for example) should exhibit similar performance to Trend Following (with the advantage of being a rather simpler strategy)</li>
</ul>
<h3>Something Extra?</h3>
<p>I recently came across <a href="http://www.automated-trading-system.com/wp-content/uploads/2010/02/AIMA.pdf" target="_blank" rel="nofollow">this paper (PDF)</a> explaining that Trend Following and OTM options buying are strategies exhibiting similar performance profiles. However, the conclusion of this paper was that <strong>Trend Following showed superior performance</strong>.</p>
<p>Additionally, there is definitely a measurable <strong>edge to Trend Following entries</strong> (such as this <a href="http://www.automated-trading-system.com/e-ratio-trading-edge/#e-ratio-filter-chart">Donchian breakout e-ratio calculation</a> shows). Random entries would not show such an edge.</p>
<p>So, there must be something extra to the kurtosis story explaining Trend Following success&#8230;</p>
<h3>Autocorrelation</h3>
<p>One hypothesis that I want to investigate further is <a href="http://en.wikipedia.org/wiki/Autocorrelation" target="_blank">autocorrelation</a> (also referred to serial correlation).</p>
<p>One of the main principles of Trend Following entries &#8211; in the face of conventional wisdom &#8211; is:</p>
<blockquote><p>Buy High and Sell Low</p></blockquote>
<p>Well, it should really say &#8220;Buy High, Sell Higher and Sell Short Low, Buy Back Lower&#8221;. The point is that <strong>Trend Following entries are made at extremes, in the direction of the extremes</strong>.</p>
<p>If market exhibit positive <strong>autocorrelation at extremes</strong>, it can be derived that following the direction of the extreme moves should provide an edge (positive expectancy). This would explain why Trend Following entries perform better than random entries and why Trend Following is a superior strategy to buying Out-of-The-Money options.</p>
<h3>Calculation Project</h3>
<p>Now, this sounds all well and fine <em>in theory</em> but does this stack up to verification?</p>
<p>To check this, I am planning to run some calculations on historical prices and see if markets exhibit such autocorrelation at extremes. Another aspect that will be interesting to look into is whether this autocorrelation evolves over time and whether these autocorrelation levels are autocorrelated themselves (ie is there some degree of predictability in the autocorrelation evolution).</p>
<p>Now, please note that I am stepping out of my comfort zone here: my &#8220;heavy maths&#8221; days are quite far behind me and I know that using statistics can be a minefield (because it is so easy to use it in an incorrect manner). For example, the &#8220;standard&#8221; correlation calculation (Pearson&#8217;s correlation coefficient) only determines linear dependence &#8211; although market data is non-linear. Might set myself up for some hardship but as we say in French: &#8220;Qui ne risque rien n&#8217;a rien&#8221; (no pain, no gain).</p>
<p>I am also thinking of getting <a href="http://www.amazon.com/exec/obidos/ASIN/0199280967/autotradblog-20" target="_blank" rel="nofollow">one</a> or <a href="http://www.amazon.com/exec/obidos/ASIN/0071276254/autotradblog-20" target="_blank" rel="nofollow">two</a> Econometrics books to give me a headstart on this. But if any of you clever readers have any suggestions or tips on any of the above, please let me know.</p>
<p>Please bear with me and stay tuned.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.automated-trading-system.com/why-trend-following-works-autocorrelation/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
	</channel>
</rss>

