<?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; Code</title>
	<atom:link href="http://www.automated-trading-system.com/category/code/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>Mon, 23 Jan 2012 11:58:45 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Trendpot Indicator: Transtrend Measure of Market Trendiness</title>
		<link>http://www.automated-trading-system.com/trendpot-indicator-transtrend-measure-of-market-trendiness/</link>
		<comments>http://www.automated-trading-system.com/trendpot-indicator-transtrend-measure-of-market-trendiness/#comments</comments>
		<pubDate>Mon, 28 Feb 2011 15:47:18 +0000</pubDate>
		<dc:creator>Jez Liberty</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Transtrend]]></category>
		<category><![CDATA[trendpot]]></category>

		<guid isPermaLink="false">http://www.automated-trading-system.com/?p=4049</guid>
		<description><![CDATA[In a previous post, I mentioned and linked to a presentation by Transtrend: &#8220;Potential Profitability by Trend Following Systems&#8221;, where the Trendpot Indicator is introduced. Trendpot is a backward looking measure that indicates for an individual market whether a medium to long-term trend following system could potentially have been profitable when applied on that particular [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.automated-trading-system.com/wp-content/uploads/2011/02/trendy-bixentro.jpg" alt="" title="trendy-bixentro" width="432" height="124" class="alignnone size-full wp-image-4054" /></p>
<p>In a previous post, I mentioned and linked to a presentation by Transtrend: <a href="http://trendfollowing.com/whitepaper/Transtrend_Presentation.pdf" target="_blank" rel="nofollow">&#8220;Potential Profitability by Trend Following Systems&#8221;</a>, where the <strong>Trendpot Indicator</strong> is introduced.</p>
<p><a href="http://trendfollowing.com/whitepaper/Transtrend_Presentation.pdf" target="_blank" rel="nofollow"><img src="http://www.automated-trading-system.com/wp-content/uploads/2011/02/Transtrend-PDF.png" alt="link to Transtrend presentation" title="link to Transtrend presentation" width="283" height="201" class="alignnone size-full wp-image-4045" /></a></p>
<blockquote><p>Trendpot is a backward looking measure that indicates for an individual market whether a medium to long-term trend following system could potentially have been profitable when applied on that particular market during the preceding month.</p>
<p>Trendpot is a number between 0 and 1: </p>
<ul>
<li>0 indicates a very low chance for a trend following system to have been profitable.</li>
<li>1 indicates a very high chance for a trend following system to have been profitable.</li>
</ul>
</blockquote>
<p>The concept is an interesting way of identifying how much a market/portfolio has been in trending vs. non-trending mode and I decided to implement the indicator in Trading Blox &#8211; with a twist:</p>
<p>The original Trendpot calculation uses a fixed one-month lookback period, to evaluate the trend potential for that month (and therefore only considers potential performance for a &#8220;medium to long-term trend following system&#8221;). I <strong>parameterized the formula</strong> to look at different periods and be able to evaluate the trend potential on different timeframes on a daily basis.</p>
<p>For those interested in the code only, please see the end of this post for details. The formula code is Trading Blox specific, but simple enough to be derived easily for any back-testing language.<span id="more-4049"></span></p>
<h3>Trendpot Usage</h3>
<p>Transtrend describes the indicator&#8217;s goal as a help to <strong>explain the performance of a trend following system</strong>. In effect, Trend Followers performance is subject to the behaviour of the market: ranging markets are not nearly as conducive to good Trend Following performance as trending ones.</p>
<p>Being able to back this argument with a quantitative measure of the trendiness of markets is probably a good way to reassure investors during expected periods of system under-performance. In 2009 for example, markets might have seemed to offer trends (with &#8220;headlines&#8221; markets such as Gold or S&#038;P 500 &#8220;trending&#8221; up by more than 50% after their respective lows at beginning of the year), yet <a href="http://www.automated-trading-system.com/trend-following-wizards-december-09/">Trend Following Wizards performance was mostly negative in 2009</a>.</p>
<p>In the presentation, Transtrend provides some explanation in the form of the Trendpot calculation for a diversified portfolio: 2009 displayed the lowest Trendpot value (i.e. lowest trend potential) of the last 20 years.</p>
<p>I used the indicator to perform a near-identical study on the portfolio used in the <a href="http://www.automated-trading-system.com/resources/state-trend-following/">State of Trend Following report</a> and measured the Trendpot values for years 2008, 2009 and 2010 (which were respectively, very good, negative and rather positive for the Trend Following Wizards &#8211; or to avoid subjective adjectives: +29.9%, -7.3% and +19.1% respectively).</p>
<p>The average values for the 30-day Trendpot were:</p>
<ul>
<li>2008: 0.331</li>
<li>2009: 0.203</li>
<li>2010: 0.245</li>
</ul>
<p>Note: to put these numbers in perspective, the average monthly Trendpot values per year calculated by Transtrend for the last 20 years varies between 0.24 (obtained in 2009) and 0.39 (obtained in 2008).<br />
It seems that the value calculated by their version generates slightly higher numbers, which could be for a number of reasons such as:</p>
<ul>
<li>Different portfolio (Transtrend portfolio contains more markets, including spreads)</li>
<li>Different price representation (Transtrend use one price series for every market representing a liquidity-weighted combination of tradable active months, whereas I used a simple back-adjusted contract) </li>
<li>Type of price used (I considered High, Low and Close whereas Transtrend only considers daily closing prices).</li>
</ul>
<p>Nevertheless, the pattern in calculated indicator values is identical: 2008 displays a much higher value than 2009.<br />
Graphically, this is also illustrated by the frequency histogram of the Trendpot values for the whole portfolio for these three different years:</p>
<p><img src="http://www.automated-trading-system.com/wp-content/uploads/2011/02/Trendpot-2008-20101.png" alt="" title="Trendpot-2008-2010" width="477" height="293" class="alignnone size-full wp-image-4053" /></p>
<p>2008 shows a larger tendency of markets to be in trending mode, with the frequency of the Trendpot value maxing out at 1 being nearly three times as large as that of 2009, and the histogram being generally &#8220;heavier&#8221; on the right-hand side (which is expected, as the overall average value is higher).</p>
<h3>Trendiness of Different Timeframes</h3>
<p>By updating the value of the period used in the indicator calculation, we can look at different timeframes, going from shorter-term trend following (i.e. 5 to 10 days) to much longer periods.</p>
<p>Below are two histograms, for 2008 and 2009, showing the distribution of Trendpot values for 4 period values, ranging from 5 days to 50 days:</p>
<p><img src="http://www.automated-trading-system.com/wp-content/uploads/2011/02/Trendpot-2008.png" alt="" title="Trendpot-2008" width="479" height="270" class="alignnone size-full wp-image-4050" /></p>
<p><img src="http://www.automated-trading-system.com/wp-content/uploads/2011/02/Trendpot-2009.png" alt="" title="Trendpot-2009" width="478" height="279" class="alignnone size-full wp-image-4051" /></p>
<p>And the average values:</p>
<ul>
<li>5-day Trendpot Average Value: 2008= 0.247, 2009= 0.2226</li>
<li>10-day Trendpot Average Value: 2008= 0.266, 2009= 0.203</li>
<li>30-day Trendpot Average Value: 2008= 0.331, 2009= 0.203</li>
<li>50-day Trendpot Average Value: 2008= 0.352, 2009= 0.242</li>
</ul>
<p>It might be interesting to look at a longer set of historical values and compare the standard deviation of Trendpot values. A lower standard deviation number might indicate a better <em>robustness</em> for a specific timeframe (robust meaning here that the potential &#8211; good or bad &#8211; of a specific timeframe is less affected by market conditions).</p>
<h3>Trendiness of Different Instruments</h3>
<p>Another potential use for the indicator is to look at isolated markets and their average Trendpot values to derive their trending potential.</p>
<p>I have run such a calculation for the instruments in the State of Trend Following portfolio over the period 2008-2010.  The average value for an instrument is 0.267, with a standard deviation of 0.083.</p>
<p>Here are the top and bottom values:</p>
<p>Top Trendpot values:</p>
<table style="border:1px solid #c3c3c3; border-collapse:collapse;">
<tr>
<th style="background-color:#e5eecc; border:1px solid #c3c3c3; padding:5px;">
      CSI<br />Symbol
    </th>
<th style="background-color:#e5eecc; border:1px solid #c3c3c3; padding:5px;">
      Instrument Description
    </th>
<th style="background-color:#e5eecc; border:1px solid #c3c3c3; padding:5px;">
      Trendpot<br />Value
    </th>
</tr>
<tr>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding:5px;">
JRB
    </td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding:5px;">
Azuki Beans-Red-TGE
    </td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding:5px;" align = "right">
0.600
    </td>
</tr>
<tr>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3; padding:5px;">
JR2
    </td>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3; padding:5px;">
Rubber (Combined Sessions)-TCE
    </td>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3; padding:5px;" align = "right">
0.484
    </td>
</tr>
<tr>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding:5px;">
FFI
    </td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding:5px;">
FTSE 100 Index-EURONEXT(LIFFE)
    </td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding:5px;" align = "right">
0.371
    </td>
</tr>
<tr>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3; padding:5px;">
NG2
    </td>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3; padding:5px;">
Natural Gas-Henry Hub-NYMEX
    </td>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3; padding:5px;" align = "right">
0.363
    </td>
</tr>
<tr>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding:5px;">
ICL
    </td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding:5px;">
Crude Oil-WTI-ICE
    </td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding:5px;" align = "right">
0.354
    </td>
</tr>
</table>
<p>&nbsp;<br />
Bottom Trendpot values:</p>
<table style="border:1px solid #c3c3c3; border-collapse:collapse;">
<tr>
<th style="background-color:#e5eecc; border:1px solid #c3c3c3; padding:5px;">
      CSI<br />Symbol
    </th>
<th style="background-color:#e5eecc; border:1px solid #c3c3c3; padding:5px;">
      Instrument Description
    </th>
<th style="background-color:#e5eecc; border:1px solid #c3c3c3; padding:5px;">
      Trendpot<br />Value
    </th>
</tr>
<tr>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding:5px;">
  JY
      </td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding:5px;">
  Japanese Yen-CME
      </td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding:5px;" align = "right">
  0.174
      </td>
</tr>
<tr>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3; padding:5px;">
  KC
      </td>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3; padding:5px;">
  Coffee-CSCE
      </td>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3; padding:5px;" align = "right">
  0.172
      </td>
</tr>
<tr>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding:5px;">
  SXE
      </td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding:5px;">
  DJ Euro STOXX 50 Index-EUREX
      </td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding:5px;" align = "right">
  0.165
      </td>
</tr>
<tr>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3; padding:5px;">
  CD
      </td>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3; padding:5px;">
  Canadian Dollar-CME
      </td>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3; padding:5px;" align = "right">
  0.124
      </td>
</tr>
<tr>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding:5px;">
  JP6
      </td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding:5px;">
  Palladium (Combined Sessions)-TCE
      </td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding:5px;" align = "right">
  0.071
      </td>
</tr>
</table>
<p>&nbsp;<br />
An interesting next step &#8211; possibly in a follow-up post &#8211; would be to calculate the correlation between the Trendpot value for an instrument and its contribution to the system performance.</p>
<h3>Postdictive or Predictive Indicator?</h3>
<p>Transtrend specify that &#8220;<em>Trendpot is a measure, not an indicator: No predictive value!</em>&#8220;.</p>
<p>As a monitoring tool, Trendpot looks like a useful addition to the box. However I wonder whether it could not be used as an input to over/under-weigh timeframes or instruments based on their past Trendpot values.<br />
This would rely on the assumption that futures values are somehow function of past values.<br />
We know that some market characteristics are not independent of past values (serial correlation for example), perhaps the trendiness of markets is one such characteristic&#8230;</p>
<h3>Code</h3>
<p>Trading Blox owners should be able to download the blox code, which I uploaded on the <a href="http://www.tradingblox.com/forum/viewtopic.php?p=46685#46685" target="_blank" rel="nofollow">Blox Marketplace</a> section of the Trading Blox formula. This is a simple implementation, which simply plots on the chart and outputs in a file the value of the Trendpot indicator for each instrument in the portfolio.</p>
<p>For those readers not having access to this section of the Trading Blox forum, I include below the main part of the code, which merely implements Transtrend formula, with an additional <em>period</em> parameter:</p>

<div class="wp_syntax"><div class="code"><pre class="r" style="font-family:monospace;">Ht = Highest(instrument.High, Period)
Ht_1 = Highest(instrument.High, Period, Period)
Ht_2 = Highest(instrument.High, Period, 2*Period)
Lt = Lowest(instrument.Low, Period)
Lt_1 = Lowest(instrument.Low, Period, Period)
Lt_2 = Lowest(instrument.Low, Period, 2*Period)
Ct = instrument.Close
Ct_1 = instrument.Close[Period]
Ct_2 = instrument.Close[2*Period]
&nbsp;
NewHigh = Ht - max(Ht_1,Ht_2)
HighEnd = Ct - Ht_1
Upmove = min(Newhigh, HighEnd)
SmoothUp = min(Ht - Ht_1, Lt - Lt_1, Ct - Ct_1)
TrendUp = max(0, (Upmove+Smoothup)/2)
Decline = max(Ht_2 - Lt, Ht_2 - Lt_1, Ht_1 - Lt, Ht - Ct)
ScaleUp = max(Decline, trendUp)
TrendpotUp = TrendUp / ScaleUp
&nbsp;
NewLow = min(Lt_1, Lt_2) - Lt
LowEnd = Lt_1 - Ct
Downmove = min(NewLow, LowEnd)
SmoothDown = min(Ht_1 - Ht, Lt_1 - Lt, Ct_1 - Ct)
TrendDown = max(0, (Downmove+SmoothDown)/2)
Rise = max(Ht - Lt_2, Ht_1 - Lt_2, Ht - Lt_1, Ct - Lt)
ScaleDown = max(Rise, trendDown)
TrendpotDown = TrendDown / ScaleDown
&nbsp;
Trendpot = IfThenElse(Ct - Ct_1 &gt; 0, TrendpotUp, IfThenElse(Ct - Ct_1 &lt; 0, TrendpotDown, 0))</pre></div></div>

<p><em>Note/Update</em>: The functions Highest/Lowest use a Trading Blox-specific notation. The second argument is the number of bars over which to find the value while third argument is the &#8220;offset&#8221; (ie number of recent bars to skip).</p>
<p>Syntax:<br />
<em>Highest( series, bars, [offset] )</em></p>
<p>Parameters:<br />
<em>series</em>: the name of the series<br />
<em>bars</em>: the number of bars over which to find the value<br />
<em>offset</em>: the number of bars to offset before finding the value</p>
<p>returns:<br />
the highest value</p>
<p>For example:<br />
<em>Ht = Highest(instrument.High, Period)</em> is the highest High over the last 30 bars (if Period = 30), i.e. roughly last month&#8217;s high<br />
<em>Ht_1 = Highest(instrument.High, Period, Period)</em> is the highest High over the 30 bars, starting 30 bars ago (if Period = 30), basically between bar 31 and 60 in the past, i.e. roughly the previous month&#8217;s high.<br />
&nbsp;<br />
&nbsp;</p>
<div style="font-size: 0.8em;">Picture credits: bixentro via flickr (CC)</div>
]]></content:encoded>
			<wfw:commentRss>http://www.automated-trading-system.com/trendpot-indicator-transtrend-measure-of-market-trendiness/feed/</wfw:commentRss>
		<slash:comments>2</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>R Code for Walk-Forward LSPM</title>
		<link>http://www.automated-trading-system.com/r-code-walk-forward-lspm/</link>
		<comments>http://www.automated-trading-system.com/r-code-walk-forward-lspm/#comments</comments>
		<pubDate>Thu, 23 Dec 2010 09:35:50 +0000</pubDate>
		<dc:creator>Jez Liberty</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[lspm]]></category>
		<category><![CDATA[R]]></category>
		<category><![CDATA[walk-forward]]></category>

		<guid isPermaLink="false">http://www.automated-trading-system.com/?p=3688</guid>
		<description><![CDATA[At the same time as Josh Ulrich was making some very good points on why to use R, over on his FOSS Trading blog, I was coming to the same realisation that it is a very neat, useful tool indeed. In this post, I&#8217;ll present the code I used for the last post on running [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.automated-trading-system.com/wp-content/uploads/2010/12/Rlogo.jpg" alt="Rlogo" title="Rlogo" width="100" height="76" class="alignnone size-full wp-image-3691" /></p>
<p>At the same time as Josh Ulrich was making some very good points on why to use R, over on his <a href="http://blog.fosstrading.com/" target="_blank">FOSS Trading blog</a>, I was coming to the same realisation that it is a very neat, useful tool indeed. In this post, I&#8217;ll present the code I used for the last post on running a <a href="http://www.automated-trading-system.com/practical-leverage-space-model-more-realistic/">Walk-Forward test of the LSPM</a>. Hopefully this can serve as an introduction to R to readers who do not use it yet.</p>
<h3>Getting into R</h3>
<p>The LSPM java app distributed by Ralph Vince during his seminar did not seem very robust &#8211; and in any case, I could not manage to get it to generate the Joint-Probability Table (JPT) for 6 market-systems over a 20-year history of monthly returns. It would simply hang after 4 of them.</p>
<p>I then decided to write my own JPT tool. Did not take me too long, an hour or two and about 200 lines of C# code. It did the job ok and I could run it in an automated/batch mode. But I had forgotten that Josh had posted some <a href="http://blog.fosstrading.com/2010/05/lspm-joint-probability-tables.html" target="_blank">R code to do exactly that</a> (Rats! A couple of hours wasted&#8230;). On top of that the code was about 30 lines long. Impressed by this, I decided that the study on the last post was a good opportunity to try and learn R and I attempted to automate the test using R only.</p>
<h3>What the Code Does</h3>
<p>At a high level, the code<span id="more-3688"></span> reads several files each containing the history of monthly returns for a market-system. The format of the files is as follows:</p>

<div class="wp_syntax"><div class="code"><pre class="r" style="font-family:monospace;">19900201,-0.5
19900301,-1.16
19900401,2.24
19900501,3.3</pre></div></div>

<p>First column = date, second column = percentage return</p>
<p>This is a <a href="http://www.automated-trading-system.com/walk-forward-testing/">Walk-Forward test</a>, so the optimization runs on a sliding window of past returns, and results are applied to the walk-forward window of returns. The cycle is repeated as many times as necessary.</p>
<p>For each cycle, the return data from the optimization window is extracted from the full set of returns, passed to the LSPM optimization, and calculated leveraged returns (using f amounts from the optimization) are stored for the corresponding walk-forward window. The full results of the test consists of a concatenation of all leveraged returns in each walk-forward window.</p>
<p>The code below is my first forray in R and its robustness could be &#8220;enhanced&#8221; (it contains several assumptions such as file formats, number of market-systems) but it should be fairly easy to adapt to run different scenarios or make it more generic.<br />
R is quite different from the programming languages I am used to, so some of the syntax might seem a bit hacked &#8211; but it does the job (I appreciate any corrections/pointers on better practices from experienced R readers&#8230;).</p>
<p>Hopefully, it is a useful example for readers wanting to get started with R. Readers might want to check my initial post on using <a href="http://www.automated-trading-system.com/vinces-optimal-f-and-the-leverage-space-model-take-1/">R to run the LSPM optimization</a> as this code expands on some aspects of it.</p>
<h3>The Code</h3>
<p>The first part of the code sets the walk-forward parameters, here: 10 years for the optimization window and one year for the walk-forward window:</p>

<div class="wp_syntax"><div class="code"><pre class="r" style="font-family:monospace;"># Set Walk-Forward parameters (number of periods)
optim&lt;-120 #10 years = 120 monthly returns
wf&lt;-12 #1 year = 12 monthly returns</pre></div></div>

<p>Open the market-system files:</p>

<div class="wp_syntax"><div class="code"><pre class="r" style="font-family:monospace;"># Open files
setwd(&quot;C:/MyPath&quot;)
a &lt;- read.csv(&quot;TMA-20-50-200.csv&quot;, header = FALSE, as.is = TRUE, sep = &quot;,&quot;, dec=&quot;.&quot;);
b &lt;- read.csv(&quot;MA-50-200.csv&quot;, header = FALSE, as.is = TRUE, sep = &quot;,&quot;, dec=&quot;.&quot;)
c &lt;- read.csv(&quot;BBO-20.csv&quot;, header = FALSE, as.is = TRUE, sep = &quot;,&quot;, dec=&quot;.&quot;)
d &lt;- read.csv(&quot;Donchian-200.csv&quot;, header = FALSE, as.is = TRUE, sep = &quot;,&quot;, dec=&quot;.&quot;)
e &lt;- read.csv(&quot;Donchian-20.csv&quot;, header = FALSE, as.is = TRUE, sep = &quot;,&quot;, dec=&quot;.&quot;)
f &lt;- read.csv(&quot;BBO-50.csv&quot;, header = FALSE, as.is = TRUE, sep = &quot;,&quot;, dec=&quot;.&quot;)</pre></div></div>

<p>Calculate the number of Walk-Forward cycles:</p>

<div class="wp_syntax"><div class="code"><pre class="r" style="font-family:monospace;"># Calculate number of WF cycles
numCycles = ceiling((nrow(a)-optim)/wf)</pre></div></div>

<p>Below is the code mentioned earlier, which can be found on Josh Ulrich&#8217;s blog &#8211; used to create the LSPM JPT:</p>

<div class="wp_syntax"><div class="code"><pre class="r" style="font-family:monospace;"># Define JPT function
jointProbTable &lt;- function(x, n=3, FUN=median, ...) {
&nbsp;
  # Load LSPM
  if(!require(LSPM,quietly=TRUE)) stop(warnings())
&nbsp;
  # Function to bin data
  quantize &lt;- function(x, n, FUN=median, ...) {
    if(is.character(FUN)) FUN &lt;- get(FUN)
    bins &lt;- cut(x, n, labels=FALSE)
    res &lt;- sapply(1:NROW(x), function(i) FUN(x[bins==bins[i]], ...))
  }
&nbsp;
  # Allow for different values of 'n' for each system in 'x'
  if(NROW(n)==1) {
    n &lt;- rep(n,NCOL(x))
  } else
  if(NROW(n)!=NCOL(x)) stop(&quot;invalid 'n'&quot;)
&nbsp;
  # Bin data in 'x'
  qd &lt;- sapply(1:NCOL(x), function(i) quantize(x[,i],n=n[i],FUN=FUN,...))
&nbsp;
  # Aggregate probabilities
  probs &lt;- rep(1/NROW(x),NROW(x))
  res &lt;- aggregate(probs, by=lapply(1:NCOL(qd), function(i) qd[,i]), sum)
&nbsp;
  # Clean up output, return lsp object
  colnames(res) &lt;- colnames(x)
  res &lt;- lsp(res[,1:NCOL(x)],res[,NCOL(res)])
  return(res)
}</pre></div></div>

<p>Loop through each Walk-Forward cycle:</p>

<div class="wp_syntax"><div class="code"><pre class="r" style="font-family:monospace;">for (i in 1:numCycles) {</pre></div></div>

<p>Extract the relevant set of past returns for the optimization:</p>

<div class="wp_syntax"><div class="code"><pre class="r" style="font-family:monospace;">	# Define cycle boundaries
	start&lt;-1+(i*wf)
	end&lt;-optim+(i*wf)
&nbsp;
	# Get returns for optimization cycle and create the JPT
	rtn &lt;- cbind(a$V2[start:end],b$V2[start:end],c$V2[start:end],d$V2[start:end],e$V2[start:end],f$V2[start:end])</pre></div></div>

<p>Create the JPT and run the actual LSPM optimization (note that the case above is the &#8220;simple&#8221; optimization, only taking optimal geometric growth rate into account &#8211; no consideration for probability of drawdown. This was mostly to ensure the run did not take hours and hours):</p>

<div class="wp_syntax"><div class="code"><pre class="r" style="font-family:monospace;">	jpt &lt;- jointProbTable(rtn,n=c(20,20,20,20,20,20))
	outcomes&lt;-jpt[[1]]
	probs&lt;-jpt[[2]]
	port&lt;-lsp(outcomes,probs)
&nbsp;
	# DEoptim parameters (see ?DEoptim)
	np=60       # 10 * number of mktsys
	imax=1000       #maximum number of iterations
	crossover=0.6       #probability of crossover
&nbsp;
	NR &lt;- NROW(port$f)
	DEctrl &lt;- list(NP=np,itermax=imax, CR=crossover, trace=TRUE)
&nbsp;
	# Optimize
	res &lt;- optimalf(port,control=DEctrl)</pre></div></div>

<p>Retrieve the leverage amounts from the optimization as well as the set of returns from the Walk-Forward window. Apply the leverage amounts to these returns and add the data to the full set of leveraged returns:</p>

<div class="wp_syntax"><div class="code"><pre class="r" style="font-family:monospace;">	# Save leverage amounts
	lev&lt;-c(100/(-jpt$maxLoss[1]/res$f[1]),  100/(-jpt$maxLoss[2]/res$f[2]),  100/(-jpt$maxLoss[3]/res$f[3]),  100/(-jpt$maxLoss[4]/res$f[4]),  100/(-jpt$maxLoss[5]/res$f[5]),  100/(-jpt$maxLoss[6]/res$f[6]))
	levmat&lt;-c(rep(1,wf)) %o% lev #so that we can multiply with the wfrtn
&nbsp;
	# Get the returns for the next Walk-Forward period
	wfrtn &lt;- cbind(a$V2[(end+1):(end+wf)],b$V2[(end+1):(end+wf)],c$V2[(end+1):(end+wf)],d$V2[(end+1):(end+wf)],e$V2[(end+1):(end+wf)],f$V2[(end+1):(end+wf)])
	wflevrtn &lt;- wfrtn*levmat #apply leverage to the returns
&nbsp;
	if (i==0) fullrtns&lt;-cbind(t(wflevrtn)) else fullrtns&lt;-cbind(fullrtns,t(wflevrtn))
}</pre></div></div>

<p>After the loop is finished, print the full set of leveraged returns</p>

<div class="wp_syntax"><div class="code"><pre class="r" style="font-family:monospace;">t(fullrtns)</pre></div></div>

<h3>In Closing</h3>
<p>Despite my very limited experience, I can really see some of the potential in using R for any sort of data manipulation.</p>
<p>If you want to get started in R and test this code, the following links will be useful:</p>
<p><a href="http://www.r-project.org/" target="_blank" rel="nofollow">R homepage</a>, which contains link to a download page. The installation is very simple and quick. Make sure you also check the docs as they are good.</p>
<p>The <a href="http://r-forge.r-project.org/projects/lspm/" target="_blank" rel="nofollow">R LSPM package</a> maintained by Josh Ulrich, the real meat of the code above &#8211; credits to him for making this!</p>
<p>The <a href="http://www.automated-trading-system.com/wp-content/uploads/2010/12/test2.r" target="_blank" rel="nofollow">R code</a> included in the post above</p>
<p>And a <a href="http://www.automated-trading-system.com/wp-content/uploads/2010/12/R.bat" target="_blank" rel="nofollow">batch file</a> to run the above code from a command prompt.</p>
<p>Finally, if you want to re-run the same test, here are the return files that were used in the code above:<br />
<a href='http://www.automated-trading-system.com/wp-content/uploads/2010/12/ReturnDataFiles.zip'>Return Data Files (zipped)</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.automated-trading-system.com/r-code-walk-forward-lspm/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Bootstrap &#8211; Take 2: Data Mining bias, Code and using geometric mean</title>
		<link>http://www.automated-trading-system.com/bootstrap-take-2-data-mining-bias-code-and-using-geometric-mean/</link>
		<comments>http://www.automated-trading-system.com/bootstrap-take-2-data-mining-bias-code-and-using-geometric-mean/#comments</comments>
		<pubDate>Fri, 13 Aug 2010 06:45:53 +0000</pubDate>
		<dc:creator>Jez Liberty</dc:creator>
				<category><![CDATA[Backtest]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[aronson bootstrap data mining]]></category>

		<guid isPermaLink="false">http://www.automated-trading-system.com/?p=2714</guid>
		<description><![CDATA[In part 1 of this bootstrap post, we looked at how to apply the method to establish the statistical significance of a single trading rule. In Part 2, we&#8217;ll look at how to deal with the data mining bias, the impact of geometric vs. arithmetic mean return. The code implementing the bootstrap test is available [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.automated-trading-system.com/wp-content/uploads/2010/08/bootstrap2.png" alt="bootstrap2" title="bootstrap2" width="411" height="119" class="aligncenter size-full wp-image-2715" /></p>
<p>In part 1 of this <a href="http://www.automated-trading-system.com/bootstrap-test/">bootstrap post</a>, we looked at how to apply the method to establish the statistical significance of a single trading rule. In Part 2, we&#8217;ll look at how to deal with the <strong>data mining bias</strong>, the impact of <strong>geometric vs. arithmetic</strong> mean return. The <strong>code</strong> implementing the bootstrap test is <strong>available for download</strong> at the bottom of this post.</p>
<h3>Dealing with Data Mining Bias</h3>
<p>The approach described in the single rule test is not valid when performing data mining (whether testing different rules or different parameter values of the same rule). As per the <strong>data mining bias</strong> (<a href="http://www.automated-trading-system.com/evidence-based-technical-analysis-aronson-book/#DataMining">explained previously</a>), the (best) rule selected from the data mining process will invariably owe a large part of its over-performance to random (good) luck.</p>
<p>The way the bootstrap test deals with the data mining bias is by implementing a concept introduced in <strong>White&#8217;s Reality Check</strong>. The Reality Check derives the <span id="more-2714"></span>sampling distribution appropriate to test the statistical significance of the <strong>best rule</strong> found by data mining.</p>
<p>In effect, the concept is fairly simple &#8211; and similar to the single-rule bootstrap: assuming N rules have been tested in the data mining process, each resample iteration will perform a resample with replacement for each rule and the best mean return will be kept as this resample iteration&#8217;s test statistic:</p>
<ol>
<li><em>N </em>back-tests are  run on detrended data. The mean daily return, based on <em>x observations</em>, is calculated for each back-tested rule.</li>
<li>Each rule&#8217;s mean daily return is substracted from the rule&#8217;s set of daily returns (zero-centering), This gives a set of adjusted returns for each rule.</li>
<li>For each &#8220;higher-level&#8221; resample (to form the sampling distribution of the best-performing rule in a universe of N rules), perform a &#8220;lower-level&#8221; resample with replacement on every rule. For each rule select <em>x instances</em> of adjusted returns at random and calculate their mean daily return (rule bootstrapped mean). Compare each rule bootstrapped mean and select the highest one: this is the test statistic of this &#8220;higher level&#8221; resample (bootstrapped best mean).</li>
<li>Perform a large number of &#8220;higher level&#8221; resamples to generate a large number of bootstrapped best means.</li>
<li>Form the sampling distribution of the best means generated in the step above.</li>
<li>Derive the p-value of the best back-test mean return (non zero-centered) based on the sampling distribution derived above</li>
</ol>
<p>In effect: <strong>for each iteration, resample each rule, take the best return, keep it as this iteration test statistic and move on to the next iteration. The sampling distribution is formed of each iteration&#8217;s best return</strong>.</p>
<h3>White Reality Check Related Papers</h3>
<p>I have not yet <del datetime="2010-08-13T00:10:57+00:00">found</del> searched <em>hard </em>for White&#8217;s paper on the Reality Check but I did find the two following papers which seem to be worth a read:<br />
<a href="http://papers.ssrn.com/sol3/papers.cfm?abstract_id=563209" target="_blank">Stepwise Multiple Testing as Formalized Data Snooping &#8211; Romano &#038; Wolf</a></p>
<p><strong>Abstract</strong>:</p>
<blockquote><p>It is common in econometric applications that several hypothesis tests are carried out at the same time. The problem then becomes how to decide which hypotheses to reject, accounting for the multitude of tests. In this paper, we suggest a stepwise multiple testing procedure which asymptotically controls the familywise error rate at a desired level. Compared to related single-step methods, our procedure is more powerful in the sense that it often will reject more false hypotheses.</p>
<p>Unlike some stepwise methods, our method implicitly captures the joint dependence structure of the test statistics, which results in increased ability to detect alternative hypotheses. We prove our method asymptotically controls the familywise error rate under minimal assumptions. Some simulation studies show the improvements of our methods over previous proposals. We also provide an application to a set of real data. </p></blockquote>
<p><a href="http://papers.ssrn.com/sol3/papers.cfm?abstract_id=685361" target="_blank">Re-Examining the Profitability of Technical Analysis with White&#8217;s Reality Check and Hansen&#8217;s SPA Test</a><br />
<strong>Abstract</strong>:<br />
<blockquote>
In this paper, we re-examine the profitability of technical analysis using White&#8217;s Reality Check and Hansen&#8217;s SPA test that correct the data snooping bias. Comparing to previous studies, we study a more complete universe of trading techniques, including not only simple rules but also investor&#8217;s strategies, and we test the profitability of these rules and strategies with four main indices. It is found that significantly profitable simple rules and investor&#8217;s strategies do exist in the data from relatively young markets (NASDAQ Composite and Russell 2000) but not in the data from relatively mature markets (DJIA and S&#038;P 500). Moreover, after taking transaction costs into account, we find that the best rules for NASDAQ Composite and  Russell 2000 outperform the buy-and-hold strategy in most in- and out-of-sample periods. Our results thus suggest that the degree of market efficiency may be related to market maturity. It is also found that investor&#8217;s strategies are able to improve on the profits of simple rules and may even generate significant profits from unprofitable simple rules.</p></blockquote>
<h3>Geometric or Arithmetic Mean?</h3>
<p>In part 1, I introduced the idea that the mean arithmetic return being positive is not equivalent to the strategy being profitable (ie. this is not a <em>sufficient</em> condition). On the other hand, the <strong>mean geometric return being positive is a necessary and sufficient condition to the strategy being profitable</strong> (ie. both conditions are <em>equivalent</em>).</p>
<p>Therefore <strong>bootstrapping using the mean geometric return as the test statistic</strong> should provide a better evaluation of the system&#8217;s profitability statistical siginificance.</p>
<p>I will not go into detail of how the calculation is done as it is very similar to the arithmetic mean return, but using <strong>log of returns</strong> instead. Note that the geometric mean will be a stricter test than the arithmetic mean (a rules can have a significantly positive arithmetic return but a negative geometric return).</p>
<p>To illustrate the multiple applications of the bootstrapping methodology, I decided to run the test on one of the <a href="http://www.automated-trading-system.com/resources/trend-following-wizards-fund-performance/">Trend Following Wizards</a> track record (set of monthly returns). I picked <strong>Chesapeake </strong>and ran the monthly returns (from 1988 to 2009) through the bootstrap test.</p>
<p>The <strong>p-value</strong> calculated using the <strong>arithmetic </strong>mean is <strong>0.000098</strong> (less than 1 chance in 10,000 that this kind of results are due to random luck). Using the <strong>geometric </strong>mean, the <strong>p-value</strong> is <strong>0.00022</strong>. The values are extremely low, which is not surprising given Jerry Parker&#8217;s 20-year track record with only one losing year and a monthly average return of 1.7%.</p>
<p>Many people would point out that survivorship bias should be considered, and obviously it depends on how you look at it. The main point of this dual test is that the <strong>geometric p-value is higher than the arithmetic p-value</strong>, verifying that it is a stricter test of statistical significance.</p>
<h3>Bootstrap Code</h3>
<p>Finally, here is a tool coded to implement the bootstrap test for a single strategy &#8211; available for download. Note that this is distributed &#8220;as is&#8221;, with no guarantee (but that&#8217;s the one I have been using so I still think it does the job&#8230;). It should run on any Windows machine with the .Net framework installed (XP or higher should do fine).</p>
<p>It simply takes three parameters (separated by space):</p>
<ol>
<li>Returns file path and name</li>
<li>Number of resamples</li>
<li>Flag for Arithmetic (A) or Geometric (G) mean calculation</li>
</ol>
<p>It also generates a file in the same directory with all of the resamples test-statistic values (to draw the histogram).</p>
<p>Simply place the bootstrap.exe in your directory of choice and run it from the command prompt as below:</p>
<div id="attachment_2716" class="wp-caption alignnone" style="width: 502px"><img src="http://www.automated-trading-system.com/wp-content/uploads/2010/08/cmd.png" alt="Run the bootstrap.exe from the command line" title="cmd" width="492" height="176" class="size-full wp-image-2716" /><p class="wp-caption-text">Run the bootstrap.exe from the command line</p></div>
<p>Download here:<br />
<a href="http://www.automated-trading-system.com/wp-content/uploads/2010/08/Bootstrap.exe">bootstrap.exe</a><br />
<a href="http://www.automated-trading-system.com/wp-content/uploads/2010/08/Bootstrap.exe"><img src="http://www.automated-trading-system.com/wp-content/uploads/2010/08/bootstrap.exe.png" alt="bootstrap.exe" title="bootstrap.exe" width="104" height="122" class="alignnone size-full wp-image-2720" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.automated-trading-system.com/bootstrap-take-2-data-mining-bias-code-and-using-geometric-mean/feed/</wfw:commentRss>
		<slash:comments>34</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>New: Free Code section &#8211; and improved Vortex</title>
		<link>http://www.automated-trading-system.com/free-code-improved-vortex/</link>
		<comments>http://www.automated-trading-system.com/free-code-improved-vortex/#comments</comments>
		<pubDate>Wed, 17 Feb 2010 11:27:38 +0000</pubDate>
		<dc:creator>Jez Liberty</dc:creator>
				<category><![CDATA[Backtest]]></category>
		<category><![CDATA[Blog]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Strategies]]></category>
		<category><![CDATA[avx]]></category>
		<category><![CDATA[Trading Blox]]></category>
		<category><![CDATA[vortex]]></category>

		<guid isPermaLink="false">http://www.automated-trading-system.com/?p=1693</guid>
		<description><![CDATA[&#160; I have been sharing code throughout the blog in various posts. Although there is a &#8220;Code&#8221; category in the blog, a dedicated page is probably the best way to organise this, before it starts getting messy. I have therefore added a main page (free code) in the nav bar. &#160; Hope you find it [...]]]></description>
			<content:encoded><![CDATA[<div><div id="attachment_1694" class="wp-caption alignleft" style="width: 210px"><img src="http://www.automated-trading-system.com/wp-content/uploads/2010/02/freeforall_almccon2.png" alt="CC picture by almccon@flickr" title="freeforall_almccon2" width="200" height="298" class="size-full wp-image-1694" /><p class="wp-caption-text">CC picture by almccon@flickr</p></div><br />
&nbsp;<br />
I have been sharing code throughout the blog in various posts. Although there is a &#8220;Code&#8221; category in the blog, a <a href="http://www.automated-trading-system.com/free-code/">dedicated page</a> is probably the best way to organise this, before it starts getting messy. I have therefore added a main page (free code) in the nav bar.<br />
&nbsp;<br />
Hope you find it useful. It has been updated with all pieces of code published so far and I will continue to do so with all further code.<br />
&nbsp;<br />
&nbsp;<br />
&nbsp;
</div>
<h3>Improved Vortex indicator</h3>
<p>As mentioned in the original Vortex indicator post, I thought there were some flaws that needed to be corrected in the original version published by the authors (Etienne Botes &#038; Douglas Siepman). I have since heard from them .</p>
<p>They gave me a detailed explanation regarding the logic of their design. The most important consideration is that <strong>they are using their indicator on Forex</strong> &#8211; which is a 24-hour market and therefore exhibits virtually no gap. Moreover, I believe they favoured a simple moving average (to Wilder&#8217;s exponential one) to add extra lag / beneficial noise filtering.</p>
<p>Anyhow, I still thought that the indicator could be improved for non-Forex markets. I also thought that the process could be taken further by creating the <strong>AVX: the Average Vortex Index</strong> (similarly to Welles Wilder&#8217;s ADX, based on the DMI). Well, I coded that up as well.<span id="more-1693"></span></p>
<p>Trading Blox blocks for all this code can be downloaded at the end of the article (or in the new <a href="http://www.automated-trading-system.com/free-code/">free code</a> section).</p>
<h3>Updated calculation logic</h3>
<p>I started prototyping the calculations in Excel for the original Wilder DMI and ADX, the original Vortex indicator and my improved version. Please find the <a href="http://www.automated-trading-system.com/wp-content/uploads/2010/02/ImprovedVortexCalcs.xls" target="_blank">Excel spreadsheet</a> for your perusal.</p>
<p>As mentioned in the initial <a href="http://www.automated-trading-system.com/vortex-indicator/">Vortex indicator post</a>, the original calculation did not handle gap days appropriately (in my opinion) and was not replicating the smoothing implemented in Wilder&#8217;s DMI by the use of an exponential Moving Average (Wilder&#8217;s to be precise) for the VI/TR calculation.</p>
<p>The logic implemented is as follows:</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:monospace;">VM+ = High - Low[1]</pre></div></div>

<p>(VM+ is today&#8217;s High minus yesterdays&#8217; Low, can be negative, in case of down gaps)</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:monospace;">VM- = High[1] - Low</pre></div></div>

<p>(VM- is yesterday&#8217;s High minus today&#8217; Low, can be negative, in case of up gaps)</p>
<p>True Range (TR) is calculated as per the <a href="http://www.csidata.com/studies/True_Range_(TR).html" target="_blank" rel="nofollow">standard formula</a>.</p>
<p>These 3 daily indicators are then smoothed using the &#8220;Wilder&#8221; <a href="http://en.wikipedia.org/wiki/Moving_average#Exponential_moving_average" target="_blank">exponential moving average</a> (alpha = 1 / N ). These give us AVM+, AVM- and ATR.</p>
<p>Normalise AVM+ and AVM- by ATR to obtain the improved VI+ and VI-.</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:monospace;">VI+ =AVM+/ATR
VI- =AVM-/ATR</pre></div></div>

<p>Building upon these calculations, we can just replicate the ADX logic to create the AVX indicator:</p>
<p>Calculate the VX:</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:monospace;">VX = (VI+ - VI-) / (VI+ + VI-) x 100</pre></div></div>

<p>VX is then smoothed (using Wilder moving average) to produce the AVX.</p>
<p><strong>Now we&#8217;re talking!</strong></p>
<p><em>Note that because VM and VI both have higher values than the original DM and DMI, VX and AVX,which express the relative difference of VI+ and VI-) will not register values as high as the ADX. But that&#8217;s ok &#8211; it just means we work on a different scale (where AVX>15 might be similar to ADX>60).</em></p>
<h3>Vortex to the test</h3>
<p>The vortex indicator can be used as an entry signal (go long when VMI+ crosses above VMI- and go short with the opposite cross). In addition, the AVX can be thought of as a measure of the strength of a directional vortex movement. The entry signal could be enhanced by only taking the signals where the AVX breaches a specific strength threshold (note: this is a very similar logic to the ADX system that ships with Trading Blox).</p>
<p><a href="http://www.automated-trading-system.com/e-ratio-trading-edge/">Calculating the e-ratio</a> for the VMI/AVX entry is a great way to measure the edge of that specific entry.</p>
<p>Another great thing is the <em>Blox marketplace</em> where Trading Blox users share their custom code. And guess what? There was a block available for e-ratio calculation. Great! I love it when I can leverage existing code&#8230;</p>
<p>With a bit of updating of the system I managed to run the e-ratio calc on 3 different entry signals:</p>
<ul>
<li>Simple VMI cross </li>
<li>VMI cross with AVX threshold filter (threshold = 10)</li>
<li>VMI cross with AVX threshold filter (threshold = 15)</li>
</ul>
<p>Below are the charts for each of the entries:</p>
<div id="attachment_1716" class="wp-caption alignnone" style="width: 418px"><img src="http://www.automated-trading-system.com/wp-content/uploads/2010/02/chartAVX.png" alt="caption: e-ratio plotted for length of 1 to 100 days" title="chartAVX" width="408" height="361" class="size-full wp-image-1716" /><p class="wp-caption-text">e-ratio plotted for length of 1 to 100 days</p></div>
<p>Notice how the AVX threshold does not seem to help and is completely counter-productive in the &#8220;AVX>15&#8243; case. In a classic example of <em>curve-fitting / data snooping</em>, we could decide to turn around the AVX threshold logic and only take signals for which the AVX is below 15. But we will not do that. Bad practice ;-)</p>
<h3>Conclusion</h3>
<p>I was not expecting much out of this study. I was mostly using it as material for getting to use Trading Blox. I was not surprised by either: I found Trading Blox easy to get a handle on. Definitely a productivity boost compared to TradersStudio, both in terms of development and simulation running time.</p>
<p>With regards to the vortex indicator, it does seem to provide a (small) edge when used as the authors intended to (albeit in a modified form). The AVX filtering, on the other hand, did not seem to improve anything at all. Maybe the edge would have been better, had I not &#8220;messed up&#8221; with the indicator&#8230;</p>
<h4>Code download</h4>
<p>Please find below the individual components (blocks) for download:<br />
<a href="http://www.automated-trading-system.com/wp-content/uploads/2010/02/Au.Tra.Sy-Vortex-AVX-Indicator.tbx">improved Vortex Indicator &#038; AVX auxiliary block file</a> (tbx)<br />
<a href="http://www.automated-trading-system.com/wp-content/uploads/2010/02/AVX-Entry-Exit.tbx">AVX Entry Exit block</a> (tbx)<br />
<a href="http://www.automated-trading-system.com/wp-content/uploads/2010/02/AVX-System.tbs">AVX System</a> (tbs)<br />
<a href="http://www.automated-trading-system.com/wp-content/uploads/2010/02/Au.Tra.Sy-imrpoved-Vortex-AVX.zip">The lot in a zip file</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.automated-trading-system.com/free-code-improved-vortex/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Vortex indicator</title>
		<link>http://www.automated-trading-system.com/vortex-indicator/</link>
		<comments>http://www.automated-trading-system.com/vortex-indicator/#comments</comments>
		<pubDate>Mon, 15 Feb 2010 10:59:02 +0000</pubDate>
		<dc:creator>Jez Liberty</dc:creator>
				<category><![CDATA[Backtest]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[ADX]]></category>
		<category><![CDATA[DMI]]></category>
		<category><![CDATA[IPV]]></category>
		<category><![CDATA[Trading Blox]]></category>
		<category><![CDATA[vortex]]></category>
		<category><![CDATA[Welles Wilder]]></category>

		<guid isPermaLink="false">http://www.automated-trading-system.com/?p=1600</guid>
		<description><![CDATA[I recently came across the Vortex Indicator, which aims to leverage the chaotic science of fluid mechanics (vortices) into a new indicator. I decided to code up this interesting concept in Trading Blox. The indicator logic is described in the January issue of TASC (Technical Analysis of Stocks and Commodities) and sounds intriguing (link to [...]]]></description>
			<content:encoded><![CDATA[<p>I recently came across the <strong>Vortex Indicator</strong>, which aims to leverage the chaotic science of fluid mechanics (vortices) into a new indicator. I decided to code up this interesting concept in Trading Blox.</p>
<div id="attachment_1612" class="wp-caption aligncenter" style="width: 490px"><img src="http://www.automated-trading-system.com/wp-content/uploads/2010/02/VortexbyNASA.png" alt="Vortex is present in chaotic movements such as fluid mechanics - picture courtesy of NASA" title="VortexbyNASA" width="480" height="367" class="size-full wp-image-1612" /><p class="wp-caption-text">Vortex is present in chaotic movements such as fluid mechanics - picture courtesy of NASA</p></div>
<p>The indicator logic is described in the January issue of TASC (Technical Analysis of Stocks and Commodities) and sounds intriguing (<a href="http://www.traders.com/Reprints/PDF_reprints/VFX_VORTEX.PDF" target="_blank" rel="nofollow">link to PDF article</a>). Without rehashing the details of the indicator calculation, it is very similar to Welles Wilder&#8217;s <a href="http://www.csidata.com/studies/Directional_Movement_Index_(DI_and_-DI).html" target="_blank" rel="nofollow">Directional Movement Index Calculation (DMI)</a> except that Wilder&#8217;s Directional Movement (largest part of today&#8217;s range outside of yesterday&#8217;s range) is replaced by calculating the differences between today&#8217;s High and yesterday&#8217;s Low (positive Vortex Movement) and today&#8217;s Low and yesterday&#8217;s High (negative Vortex Movement).</p>
<p><img src="http://www.automated-trading-system.com/wp-content/uploads/2010/02/vortex.png" alt="vortex" title="vortex" width="354" height="164" class="alignnone size-full wp-image-1613" /><br />
<span id="more-1600"></span><br />
TASC provides the Vortex indicator implementations in a wide collection of backtesting platforms (<a href="http://www.traders.com/Documentation/FEEDbk_docs/2010/01/TradersTips.html" target="_blank" rel="nofollow">here</a>). <del datetime="2010-02-14T22:28:05+00:00">Unfortunately</del> the <strong>Trading Blox</strong> implementation is not provided, which provided me a perfect opportunity to test and learn my new &#8220;backtesting toy&#8221; out.<br />
<a name="flaw"></a></p>
<h3>System Logic Flaw?</h3>
<p>The authors of the indicator provide a sample Excel spreadsheet to illustrate their calculation. By replicating the logic in Excel to get a handle on it (<a href="http://www.automated-trading-system.com/wp-content/uploads/2010/02/VortexCalcs0.xls" target="_blank">link to Excel spreadsheet</a>), I uncovered what I think is a flaw in the logic of the indicator of the calculation.</p>
<p>The VM calculations take the absolute value of the difference of opposite price extremes (High and Low) between today and yesterday. The screenshot of this <a href="http://www.automated-trading-system.com/wp-content/uploads/2010/02/VortexFlaws.xls" target="_blank">Excel spreadsheet</a> below clearly illustrates that this is a problem when dealing with gaps.</p>
<p><img src="http://www.automated-trading-system.com/wp-content/uploads/2010/02/Vortex-Flaws.png" alt="Vortex Flaws" title="Vortex Flaws" width="476" height="784" class="alignnone size-full wp-image-1614" /></p>
<p>Additionally, one could argue that the simple summation/averaging of the VMs is different from the original DMI calculations which use <a href="http://www.csidata.com/studies/Welles_Wilder_Moving_Average.html" target="_blank" rel="nofollow">Wilder Moving Averages</a>.</p>
<p>I have emailed the authors of the indicator with a suggestion for a fix. I&#8217;ll relay their answer here.</p>
<h3>Trading Blox implementation</h3>
<p>First and foremost, this is a Trading Blox coding exercise so I was not too concerned about these flaws (although I might be tempted to implement my own version addessing both flaws later).</p>
<p>I suggest you follow the calculation logic on the PDF article or the Excel spreadsheet. Here is how I implemented the Vortex Indicator in Trading Blox:</p>
<h4>1: Create Auxiliary Block</h4>
<p>This will hold all indicators and implement their calculations. Call it Vortex Indicator.</p>
<h4>2: Create parameters</h4>
<p>There is one parameter: the period for the Vortex indicator (VI) calculation:</p>
<p><img src="http://www.automated-trading-system.com/wp-content/uploads/2010/02/viDaysParam.png" alt="viDaysParam" title="viDaysParam" width="399" height="309" class="alignnone size-full wp-image-1615" /></p>
<h4>3: Create Indicators</h4>
<p>These are the first-level calculations: the daily True Range (TR), and VM+ (plusVM) and VM- (minusVM).</p>
<div id="attachment_1616" class="wp-caption alignnone" style="width: 460px"><img src="http://www.automated-trading-system.com/wp-content/uploads/2010/02/plusVM.png" alt="VM+ indicator using a calculated formula" title="plusVM" width="450" height="306" class="size-full wp-image-1616" /><p class="wp-caption-text">VM+ indicator using a calculated formula</p></div>
<p>The code for each of these indicators is:</p>
<p>plusVM (VM+ is the difference between today&#8217;s High and yesterday&#8217;s Low):</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:monospace;">Abs(instrument.High - instrument.Low[1])</pre></div></div>

<p>minusVM (VM- is the difference between today&#8217;s Low and yesterday&#8217;s High):</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:monospace;">Abs(instrument.High[1]-instrument.Low)</pre></div></div>

<p>TR (standard True Range calculation):</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:monospace;">Max(instrument.High-instrument.Low,Abs(instrument.High-instrument.<span style="color: #8D38C9; font-weight: bold;">Close</span>[1]), Abs(instrument.Low-instrument.<span style="color: #8D38C9; font-weight: bold;">Close</span>[1]))</pre></div></div>

<h4>4: Create Instrument Permanent Variables (IPV)</h4>
<p>This is for next-level calculations (Sum of TR, Sum of VM+ and VM-, VI+ and VI-). Setting these up as IPV allow for their values to be made available to other blocks (such the Entry block of a system).</p>
<div id="attachment_1618" class="wp-caption alignnone" style="width: 470px"><img src="http://www.automated-trading-system.com/wp-content/uploads/2010/02/plusVI_IPV1.png" alt="Notice how the variable scope has been updated to &quot;System&quot;" title="plusVI_IPV" width="460" height="357" class="size-full wp-image-1618" /><p class="wp-caption-text">Notice how the variable scope has been updated to System</p></div>
<p>The values for these IPVs are updated in the block <em>Update Indicators</em> script:</p>
<p><img src="http://www.automated-trading-system.com/wp-content/uploads/2010/02/UpdateIndicators.png" alt="UpdateIndicators" title="UpdateIndicators" width="480" height="447" class="alignnone size-full wp-image-1619" /></p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:monospace;">plusVMSum=Sum(plusVM,viDays,0)
minusVMSum=Sum(minusVM,viDays,0)
TRSum=Sum(TR,viDays,0)
plusVI=plusVMSum/TRSum
minusVI=minusVMSum/TRSum</pre></div></div>

<h3>Use in Trading Blox</h3>
<p>Adding the auxiliary block to any System will enable it to access the values of the vortex indicators.</p>
<p>Here is how it could be done for a simple reversal system switching from Short to Long when VI+ crosses with VI- (and vice-versa).</p>
<h4>Create an Entry Exit block</h4>
<p>The system will have the Vortex Indicator Auxiliary block and our new Entry Exit block.</p>
<h4>Add VI+ and VI- as IPV to the Entry Exit block</h4>
<p>This is just a declaration to indicate that the values of these indicators are calculated in another block (our Vortex Indicator Auxiliary block).</p>
<div id="attachment_1620" class="wp-caption alignnone" style="width: 470px"><img src="http://www.automated-trading-system.com/wp-content/uploads/2010/02/IPV_External.png" alt="The IPV is defined externally in another block (Vortex indicator)" title="IPV_External" width="460" height="241" class="size-full wp-image-1620" /><p class="wp-caption-text">The IPV is defined externally in another block (Vortex indicator)</p></div>
<p>The other parameters and indicators in this block are standard ATR Stop elements.</p>
<h4>Code up the entry formula</h4>
<p>Simple logic to enter long when VI+ is above VI- and no long position are in and opposite for short entry:</p>
<p><img src="http://www.automated-trading-system.com/wp-content/uploads/2010/02/Entry.png" alt="Entry" title="Entry" width="480" height="343" class="alignnone size-full wp-image-1621" /></p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:monospace;">VARIABLES: pvi <span style="color: #151B8D; font-weight: bold;">TYPE</span>: Floating
pvi = plusVI
VARIABLES: nvi <span style="color: #151B8D; font-weight: bold;">TYPE</span>: Floating
nvi = minusVI
VARIABLES: pos <span style="color: #151B8D; font-weight: bold;">TYPE</span>: <span style="color: #F660AB; font-weight: bold;">String</span>
pos = instrument.position
&nbsp;
<span style="color: #8D38C9; font-weight: bold;">IF</span> 	plusVI &gt; minusVI <span style="color: #8D38C9; font-weight: bold;">AND</span>
	instrument.position &lt;&gt; <span style="color: #F660AB; font-weight: bold;">LONG</span> <span style="color: #8D38C9; font-weight: bold;">THEN</span>
&nbsp;
	<span style="color: #8D38C9; font-weight: bold;">IF</span> useATRStops <span style="color: #8D38C9; font-weight: bold;">THEN</span>
		broker.EnterLongOnOpen( instrument.<span style="color: #8D38C9; font-weight: bold;">close</span> - averageTrueRange * atrStop )
	<span style="color: #8D38C9; font-weight: bold;">ELSE</span>
		broker.EnterLongOnOpen
	ENDIF
&nbsp;
ENDIF
&nbsp;
<span style="color: #8D38C9; font-weight: bold;">IF</span>	plusVI &lt; minusVI <span style="color: #8D38C9; font-weight: bold;">AND</span>
	instrument.position &lt;&gt; SHORT <span style="color: #8D38C9; font-weight: bold;">THEN</span>
&nbsp;
	<span style="color: #8D38C9; font-weight: bold;">IF</span> useATRStops <span style="color: #8D38C9; font-weight: bold;">THEN</span>
		broker.EnterShortOnOpen( instrument.<span style="color: #8D38C9; font-weight: bold;">close</span> + averageTrueRange * atrStop )
	<span style="color: #8D38C9; font-weight: bold;">ELSE</span>
		broker.EnterShortOnOpen
	ENDIF
&nbsp;
ENDIF</pre></div></div>

<h3>Trading Blox test</h3>
<p>Although I would like to do a more complete test to compare the Vortex Indicator to the DMI, all I have time left for today is a simple run of the system described above. I arbitrarily chose 39 for the VI period and here is the result:</p>
<table style="border:1px solid #c3c3c3; border-collapse:collapse;">
<tr>
<th style="background-color:#e5eecc; border:1px solid #c3c3c3; padding:5px;">
      CAGR
    </th>
<th style="background-color:#e5eecc; border:1px solid #c3c3c3; padding:5px;">
      Sharpe ratio
    </th>
<th style="background-color:#e5eecc; border:1px solid #c3c3c3; padding:5px;">
      Max DD
    </th>
</tr>
<tr>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding:2px;">
5.80%
    </td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding:2px;" align = "right">
<div style="color:black">0.10</div>
</td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding:2px;" align = "right">
<div style="color:black">42.4%</div>
</td>
</tr>
</table>
<p>&nbsp;<br />
<div id="attachment_1627" class="wp-caption alignnone" style="width: 500px"><img src="http://www.automated-trading-system.com/wp-content/uploads/2010/02/LogarithmicEquityGraph_vortex11.png" alt="Logarithmic Equity curve from Vortex indicator system" title="LogarithmicEquityGraph_vortex1" width="490" height="295" class="size-full wp-image-1627" /><p class="wp-caption-text">Logarithmic Equity curve from Vortex indicator system</p></div></p>
<p>And as a side note of caution when dealing with backtest results, I&#8217;ll show you a quick trick that will allow me to nearly double the CAGR (Compounded Annual Growth Rate) by not touching the system at all:</p>
<table style="border:1px solid #c3c3c3; border-collapse:collapse;">
<tr>
<th style="background-color:#e5eecc; border:1px solid #c3c3c3; padding:5px;">
      CAGR
    </th>
<th style="background-color:#e5eecc; border:1px solid #c3c3c3; padding:5px;">
      Sharpe ratio
    </th>
<th style="background-color:#e5eecc; border:1px solid #c3c3c3; padding:5px;">
      Max DD
    </th>
</tr>
<tr>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding:2px;">
10.93%
    </td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding:2px;" align = "right">
<div style="color:black">0.26</div>
</td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding:2px;" align = "right">
<div style="color:black">33.0%</div>
</td>
</tr>
</table>
<p>&nbsp;<br />
<div id="attachment_1628" class="wp-caption alignnone" style="width: 500px"><img src="http://www.automated-trading-system.com/wp-content/uploads/2010/02/LogarithmicEquityGraph_vortex2.png" alt="Logarithmic Equity curve from Vortex indicator system (truncated period)" title="LogarithmicEquityGraph_vortex2" width="490" height="295" class="size-full wp-image-1628" /><p class="wp-caption-text">Logarithmic Equity curve from Vortex indicator system (truncated period)</p></div></p>
<p>Notice what happened there: I just dropped years 1996 to 1999 from the backtests. Et voila! Surely a trick employed by more than one dubious trading systems salesmen&#8230;</p>
<h3>Conclusion</h3>
<p><del datetime="2010-02-17T00:25:39+00:00">The authors claim that the Vortex indicator improve on the DMI invented by Welles Wilder</del> Update: the authors have sent me an email to clarify that they have not made such claim (I was merely interpolating, given the ressemblance of the Vortex indicator with the DMI). It would be interesting to test this as the idea of mixing chaos/fluid mechanics concepts to price movements is appealing. Fixing the indicator flaws would be good too. More to come&#8230; (update: on the <a href="http://www.automated-trading-system.com/free-code-improved-vortex/">next post</a>, I also explain the authors response to my claim of the indicator having flaws).</p>
<h4>Code download</h4>
<p>Please find below the individual components (blocks) for download:<br />
<a href="http://www.automated-trading-system.com/wp-content/uploads/2010/02/Vortex-Indicator.tbx">link to Vortex indicator block file</a> (tbx)<br />
<a href="http://www.automated-trading-system.com/wp-content/uploads/2010/02/VI-Entry-Exit.tbx">link to VI sample Entry Exit block</a> (tbx)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.automated-trading-system.com/vortex-indicator/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Amibroker e-ratio code</title>
		<link>http://www.automated-trading-system.com/e-ratio-amibroker-code/</link>
		<comments>http://www.automated-trading-system.com/e-ratio-amibroker-code/#comments</comments>
		<pubDate>Mon, 09 Nov 2009 12:30:53 +0000</pubDate>
		<dc:creator>Jez Liberty</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[afl]]></category>
		<category><![CDATA[amibroker]]></category>
		<category><![CDATA[e-ratio]]></category>
		<category><![CDATA[edge]]></category>
		<category><![CDATA[optimisation]]></category>
		<category><![CDATA[tradersstudio]]></category>

		<guid isPermaLink="false">http://www.automated-trading-system.com/?p=901</guid>
		<description><![CDATA[I recently posted about the e-ratio as a tool to measure parts of a trading system (the code files to compute the e-ratio in TradersStudio and Excel are also available). The e-ratio is supposed to be a quick tool to check how signals might add some edge to a trading system. However computing the e-ratio [...]]]></description>
			<content:encoded><![CDATA[<p>I recently posted about the <a href="http://www.automated-trading-system.com/e-ratio-trading-edge/">e-ratio</a> as a tool to measure parts of a trading system (the <a href="http://www.automated-trading-system.com/e-ratio-tradersstudio-excel/">code files to compute the e-ratio in TradersStudio and Excel</a> are also available). The e-ratio is supposed to be a quick tool to check how signals might add some edge to a trading system. However computing the e-ratio in TradersStudio is slow (4+ hours for one signal over 100 different durations).</p>
<p>So I decided to give the &#8220;legendary fast&#8221; Amibroker a test to see if it could better TradersStudio&#8217;s performance. After some &#8220;playing and learning&#8221;, I have finalised the code to compute the e-ratio. My big thanks go to the <a href="http://theasxgorilla.blogspot.com/2007/07/how-to-compute-edge-ratio-in-amibroker.html" target="_blank" rel="nofollow">ASX gorilla</a> whose own version forms a large part of my code.<span id="more-901"></span></p>
<p>Below is the code explanation and downloadable <a href="http://www.automated-trading-system.com/wp-content/uploads/2009/11/e-ratio-gorilla.afl" target="_blank">afl file</a>.</p>
<p>Directly from the ASX Gorilla&#8217;s website as a prelude to the code:</p>
<blockquote><p>My implementation of the Edge Ratio involves two profound Amibroker fudges. The first is the use of the AddToComposite function to create a composite ticker symbol in which to hold the ATR array of a given stock for later retrieval within the Custom Back Tester via the Foreign function.</p></blockquote>
<blockquote><p>The second fudge is the use of the VarSet/VarGet function to create a quasi array. This was necessary to overcome the limitation where array elements cannot exceed in number the value of barcount-1.</p></blockquote>
<p>The first part is to actually code up your Buy signal (in our case a Donchian Channel Breakout). The Sell signals are tested separately:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #11740a; font-style: italic;">//BUY RULES: implemented with Buy Stop on Upper Donchian Channel(17)</span>
BuyStop <span style="color: #002200;">=</span> Ref<span style="color: #002200;">&#40;</span>HHV<span style="color: #002200;">&#40;</span>High, <span style="color: #2400d9;">17</span><span style="color: #002200;">&#41;</span>,<span style="color: #002200;">-</span><span style="color: #2400d9;">1</span><span style="color: #002200;">&#41;</span>;
Buy <span style="color: #002200;">=</span> Cross<span style="color: #002200;">&#40;</span> High, BuyStop <span style="color: #002200;">&#41;</span>;
BuyPrice <span style="color: #002200;">=</span> Max<span style="color: #002200;">&#40;</span> BuyStop, Low <span style="color: #002200;">&#41;</span>; <span style="color: #11740a; font-style: italic;">// make sure buy price &gt;= Low</span></pre></div></div>

<p>Exiting positions is done on a fixed duration basis:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #11740a; font-style: italic;">//Never Sell so that the position is stopped out after N bar instead</span>
Sell <span style="color: #002200;">=</span> <span style="color: #2400d9;">3</span> &gt; <span style="color: #2400d9;">5</span>;
<span style="color: #11740a; font-style: italic;">//Stop the positon and close it after N bars</span>
<span style="color: #11740a; font-style: italic;">//(eratio = N that we step from 1 to 100 in optimisation)</span>
ApplyStop<span style="color: #002200;">&#40;</span> stopTypeNBar, stopModeBars, eratio <span style="color: #002200;">&#41;</span>;</pre></div></div>

<p>The first fudge mentioned above to store the ATR:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">Normaliser <span style="color: #002200;">=</span> ATR<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">17</span><span style="color: #002200;">&#41;</span>;
AddToComposite<span style="color: #002200;">&#40;</span>Normaliser, <span style="color: #bf1d1a;">&quot;~atr_&quot;</span><span style="color: #002200;">+</span>Name<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#41;</span>, <span style="color: #bf1d1a;">&quot;C&quot;</span>, <span style="color: #2400d9;">1</span><span style="color: #002200;">+</span><span style="color: #2400d9;">2</span><span style="color: #002200;">+</span><span style="color: #2400d9;">8</span><span style="color: #002200;">&#41;</span>;</pre></div></div>

<p>And the &#8220;meat&#8221; of the code: the chunk that implements the custom back-testing to:</p>
<ol>
<li>Loop through the signals and store the Entry ATR value.</li>
<li>Loop through all trades and retrieve MFE, MAE and ATR.</li>
<li>Compute the e-ratio based on values from all trades.</li>
</ol>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">SetCustomBacktestProc<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">&quot;&quot;</span><span style="color: #002200;">&#41;</span>; <span style="color: #11740a; font-style: italic;">//activate the custom backtester</span>
<span style="color: #a61390;">if</span><span style="color: #002200;">&#40;</span>Status<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">&quot;action&quot;</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">==</span> actionPortfolio<span style="color: #002200;">&#41;</span> <span style="color: #11740a; font-style: italic;">//called when backtesting/optimising</span>
<span style="color: #002200;">&#123;</span>
	bo <span style="color: #002200;">=</span> GetBacktesterObject<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#41;</span>;
	bo.PreProcess<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#41;</span>; <span style="color: #11740a; font-style: italic;">// run default backtest procedure</span>
	TradeATR <span style="color: #002200;">=</span> NumTrades <span style="color: #002200;">=</span> ATRArr <span style="color: #002200;">=</span> <span style="color: #2400d9;">0</span>; <span style="color: #11740a; font-style: italic;">//init variables</span>
	<span style="color: #a61390;">for</span><span style="color: #002200;">&#40;</span> bar<span style="color: #002200;">=</span><span style="color: #2400d9;">0</span>; bar &lt; BarCount<span style="color: #002200;">-</span><span style="color: #2400d9;">1</span>; bar<span style="color: #002200;">++</span><span style="color: #002200;">&#41;</span>
	<span style="color: #002200;">&#123;</span>
		bo.ProcessTradeSignals<span style="color: #002200;">&#40;</span>bar<span style="color: #002200;">&#41;</span>;
&nbsp;
		<span style="color: #a61390;">for</span> <span style="color: #002200;">&#40;</span> sig<span style="color: #002200;">=</span>bo.GetFirstSignal<span style="color: #002200;">&#40;</span>bar<span style="color: #002200;">&#41;</span>; sig; sig<span style="color: #002200;">=</span>bo.GetNextSignal<span style="color: #002200;">&#40;</span>bar<span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#41;</span>
		<span style="color: #002200;">&#123;</span>
			<span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>sig.isEntry<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#41;</span>
			<span style="color: #002200;">&#123;</span>
				NumTrades<span style="color: #002200;">++</span>;
				ATRArr <span style="color: #002200;">=</span> Foreign<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">&quot;~atr_&quot;</span><span style="color: #002200;">+</span>sig.Symbol, <span style="color: #bf1d1a;">&quot;C&quot;</span><span style="color: #002200;">&#41;</span>;
				VarSet<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">&quot;TradeATR&quot;</span> <span style="color: #002200;">+</span> NumTrades, ATRArr<span style="color: #002200;">&#91;</span>bar<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span>;
&nbsp;
				_TRACE<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">&quot;Symbol &quot;</span> <span style="color: #002200;">+</span> sig.Symbol <span style="color: #002200;">+</span> <span style="color: #bf1d1a;">&quot; ATR: &quot;</span> <span style="color: #002200;">+</span> VarGet<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">&quot;TradeATR&quot;</span> <span style="color: #002200;">+</span> NumTrades<span style="color: #002200;">&#41;</span><span style="color: #002200;">&#41;</span>;
			<span style="color: #002200;">&#125;</span>
		<span style="color: #002200;">&#125;</span>
	<span style="color: #002200;">&#125;</span>
&nbsp;
	AvgMAE <span style="color: #002200;">=</span> AccumMAE <span style="color: #002200;">=</span> AvgMFE <span style="color: #002200;">=</span> AccumMFE <span style="color: #002200;">=</span> NumTrades <span style="color: #002200;">=</span> <span style="color: #2400d9;">0</span>;
&nbsp;
	<span style="color: #11740a; font-style: italic;">// iterate through closed trades</span>
	<span style="color: #a61390;">for</span><span style="color: #002200;">&#40;</span> trade <span style="color: #002200;">=</span> bo.GetFirstTrade<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#41;</span>; trade; trade <span style="color: #002200;">=</span> bo.GetNextTrade<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#41;</span>
	<span style="color: #002200;">&#123;</span>
		NumTrades<span style="color: #002200;">++</span>;
		EntryATR <span style="color: #002200;">=</span> VarGet <span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">&quot;TradeATR&quot;</span> <span style="color: #002200;">+</span> NumTrades<span style="color: #002200;">&#41;</span>;
		<span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span> EntryATR <span style="color: #002200;">!=</span> <span style="color: #2400d9;">0</span> <span style="color: #002200;">&#41;</span>
		<span style="color: #002200;">&#123;</span>
			_TRACE<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">&quot;EntryATR: &quot;</span> <span style="color: #002200;">+</span> WriteVal<span style="color: #002200;">&#40;</span>EntryATR<span style="color: #002200;">&#41;</span><span style="color: #002200;">&#41;</span>;
			_TRACE<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">&quot;AccumMAE : &quot;</span> <span style="color: #002200;">+</span> WriteVal<span style="color: #002200;">&#40;</span>AccumMAE<span style="color: #002200;">&#41;</span><span style="color: #002200;">&#41;</span>;
			AccumMAE <span style="color: #002200;">=</span> AccumMAE <span style="color: #002200;">+</span> <span style="color: #002200;">&#40;</span>trade.GetMAE<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">*</span>trade.EntryPrice<span style="color: #002200;">/</span><span style="color: #002200;">&#40;</span><span style="color: #2400d9;">100</span><span style="color: #002200;">*</span>EntryATR<span style="color: #002200;">&#41;</span><span style="color: #002200;">&#41;</span>;
			AccumMFE <span style="color: #002200;">=</span> AccumMFE <span style="color: #002200;">+</span> <span style="color: #002200;">&#40;</span>trade.GetMFE<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">*</span>trade.EntryPrice<span style="color: #002200;">/</span><span style="color: #002200;">&#40;</span><span style="color: #2400d9;">100</span><span style="color: #002200;">*</span>EntryATR<span style="color: #002200;">&#41;</span><span style="color: #002200;">&#41;</span>;
		<span style="color: #002200;">&#125;</span>
&nbsp;
		trade.AddCustomMetric<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">&quot;My MAE&quot;</span>, trade.GetMAE<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">*</span>trade.EntryPrice<span style="color: #002200;">/</span><span style="color: #2400d9;">100</span><span style="color: #002200;">&#41;</span>;
		trade.AddCustomMetric<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">&quot;My MFE&quot;</span>, trade.GetMFE<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">*</span>trade.EntryPrice<span style="color: #002200;">/</span><span style="color: #2400d9;">100</span><span style="color: #002200;">&#41;</span>;
		trade.AddCustomMetric<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">&quot;Entry ATR&quot;</span>, EntryATR<span style="color: #002200;">*</span><span style="color: #2400d9;">10000</span><span style="color: #002200;">&#41;</span>;
	<span style="color: #002200;">&#125;</span>
&nbsp;
	AvgMAE <span style="color: #002200;">=</span> AccumMAE <span style="color: #002200;">/</span> NumTrades;
	AvgMFE <span style="color: #002200;">=</span> AccumMFE <span style="color: #002200;">/</span> NumTrades;
&nbsp;
	_TRACE<span style="color: #002200;">&#40;</span>WriteVal<span style="color: #002200;">&#40;</span>AccumMAE <span style="color: #002200;">&#41;</span><span style="color: #002200;">&#41;</span>;
	_TRACE<span style="color: #002200;">&#40;</span>WriteVal<span style="color: #002200;">&#40;</span>NumTrades<span style="color: #002200;">&#41;</span><span style="color: #002200;">&#41;</span>;
	_TRACE<span style="color: #002200;">&#40;</span>WriteVal<span style="color: #002200;">&#40;</span>AvgMAE<span style="color: #002200;">&#41;</span><span style="color: #002200;">&#41;</span>;
&nbsp;
	Eratio <span style="color: #002200;">=</span> <span style="color: #a61390;">abs</span><span style="color: #002200;">&#40;</span>AvgMFE<span style="color: #002200;">/</span>AvgMAE<span style="color: #002200;">&#41;</span>;
&nbsp;
	_TRACE<span style="color: #002200;">&#40;</span>WriteVal<span style="color: #002200;">&#40;</span>Eratio<span style="color: #002200;">&#41;</span><span style="color: #002200;">&#41;</span>;
&nbsp;
	bo.AddCustomMetric<span style="color: #002200;">&#40;</span> <span style="color: #bf1d1a;">&quot;Avg MAE&quot;</span>, AvgMAE <span style="color: #002200;">&#41;</span>;
	bo.AddCustomMetric<span style="color: #002200;">&#40;</span> <span style="color: #bf1d1a;">&quot;Avg MFE&quot;</span>, AvgMFE <span style="color: #002200;">&#41;</span>;
	bo.AddCustomMetric<span style="color: #002200;">&#40;</span> <span style="color: #bf1d1a;">&quot;Eratio&quot;</span>, Eratio<span style="color: #002200;">&#41;</span>;
&nbsp;
	bo.PostProcess<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#41;</span>;
<span style="color: #002200;">&#125;</span></pre></div></div>

<p>If you want to run this code, you can download the <a href="http://www.automated-trading-system.com/wp-content/uploads/2009/11/e-ratio-gorilla.afl" target="_blank">e-ratio &#8220;gorilla&#8221; afl file</a> and simply update the BUY signals to whatever you fancy testing.</p>
<p>The next post will be a direct speed comparison between TradersStudio and Amibroker for computing the e-ratio on the same underlying data and with the same signal. I expect Amibroker to <em>win the fight</em> hands-down as it appeared &#8220;way&#8221; faster!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.automated-trading-system.com/e-ratio-amibroker-code/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
		<item>
		<title>e-ratio calculation in TradersStudio and Excel</title>
		<link>http://www.automated-trading-system.com/e-ratio-tradersstudio-excel/</link>
		<comments>http://www.automated-trading-system.com/e-ratio-tradersstudio-excel/#comments</comments>
		<pubDate>Mon, 02 Nov 2009 10:31:48 +0000</pubDate>
		<dc:creator>Jez Liberty</dc:creator>
				<category><![CDATA[Backtest]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[e-ratio]]></category>
		<category><![CDATA[edge]]></category>
		<category><![CDATA[excel]]></category>
		<category><![CDATA[tradersstudio]]></category>

		<guid isPermaLink="false">http://www.automated-trading-system.com/?p=810</guid>
		<description><![CDATA[Here is one method to implement an e-ratio calculation. As we say in developerspeak, the following is a quick and dirty approach to calculating the e-ratio. But as far as I am concerned, it does the job! It can probably be programmed more elegantly in TradersStudio but I still have to climb some of that [...]]]></description>
			<content:encoded><![CDATA[<p>Here is one method to implement an <a href="http://www.automated-trading-system.com/e-ratio-trading-edge/">e-ratio</a> calculation.<br />
As we say in <em>developerspeak</em>, the following is a <em>quick and dirty</em> approach to calculating the e-ratio. But as far as I am concerned, it does the job! It can probably be programmed more elegantly in TradersStudio but I still have to climb some of that software learning curve&#8230;</p>
<p>I will show you how I calculated the e-ratio for a 17-day Donchian Channel breakout coupled with <span id="more-810"></span>a 108-day moving average filter (the red curve on <a href="http://www.automated-trading-system.com/e-ratio-trading-edge#e-ratio-filter-chart">this chart</a>). All the code referenced is provided at the end of this post.</p>
<p>As we saw in the <a href="http://www.automated-trading-system.com/e-ratio-trading-edge/">last post about the e-ratio</a>, you need to run the same signal over multiple fixed trade durations and record trade data. For this the TradersStudio optimisation and custom reports functionalities fit the bill.</p>
<h3>System Code</h3>
<h4>Step 1: code up the system to test in TraderStudio</h4>
<p>As you can not have simultaneous open Buy and Sell positions, there are actually 2 systems (long-only and short-only). The below will be based on the Buy-only system.<br />
The entry signal is a breakout of the Donchian channel if the MA filter conditions are met (price > MA and MA rising).<br />
In TradersStudio this translates to:</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:monospace;">MA = ScriptAve(<span style="color: #8D38C9; font-weight: bold;">Close</span>, MALength,0)
<span style="color: #8D38C9; font-weight: bold;">If</span> MA &gt; MA[1] <span style="color: #8D38C9; font-weight: bold;">And</span> <span style="color: #8D38C9; font-weight: bold;">Close</span> &gt; MA <span style="color: #8D38C9; font-weight: bold;">Then</span>
    Buy(EntryName,1,donchianHigh+MinMove ,<span style="color: #151B8D; font-weight: bold;">Stop</span>,Day)
<span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #8D38C9; font-weight: bold;">If</span></pre></div></div>

<p>The exit is simple: close the trade after <em>n</em> days (tradeLength):</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:monospace;"><span style="color: #8D38C9; font-weight: bold;">If</span> BarsSinceEntry=tradeLength <span style="color: #8D38C9; font-weight: bold;">And</span> MarketPosition=1 <span style="color: #8D38C9; font-weight: bold;">Then</span>
    ExitLong(<span style="color: #800000;">&quot;ExitLong&quot;</span>,EntryName,1,0,CloseExit,Day)
<span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #8D38C9; font-weight: bold;">If</span></pre></div></div>

<h4>Step 2: retrieve trade data in custom report</h4>
<p>As discussed in the e-ratio post we need to get MAE, MFE and ATR for each trade. For this we use a TradersStudio custom report. The report code is executed at the end of the system test and retrieve trade info with the following command:</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:monospace;">GetInfoAboutTrades(Info, i + 1)</pre></div></div>

<p>we are interested in the MAE and MFE which can be derived off the Maximum Profit and Maximum Loss of each trade:</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:monospace;">SetCell(row, 13, 2, 10, Info[16]) <span style="color: #008000;">'Max Pos Profit
</span>SetCell(row, 14, 2, 10, Info[17]) 'Max Pos Loss</pre></div></div>

<p>For the ATR value, we need to use a little trick as it is not directly available. We record it as part of the entry name which can be output to the report.<br />
In the system code we have:</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:monospace;">EntryName = <span style="color: #800000;">&quot;DonchianBreakoutBuy&quot;</span> + <span style="color: #800000;">&quot;|&quot;</span> + indLength + <span style="color: #800000;">&quot;|&quot;</span> + tradeLength  + <span style="color: #800000;">&quot;|&quot;</span> + avgtruerange(indLength)</pre></div></div>

<p>which concatenates the entry name with the ATR value as well as the length of the indicator (Donchian Channel) and trade duration &#8211; this will come in handy when we do the e-ratio calculation.</p>
<h4>Step 3: run the system through the optimizer</h4>
<p>The system is called DonchianChanBrkoutFiltBuy and has 3 parameters:</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:monospace;"><span style="color: #E56717; font-weight: bold;">Sub</span> DonchianChanBrkoutFiltBuy(indLength, tradeLength, MALength)</pre></div></div>

<p>In the optimization process, step through all values of trade duration required (e.g from 1 to 100 in increments of 1) &#8211; warning TradersStudio will take a few hours to do this (sic!).<br />
This will generate a custom trade report for all trades containing all the data required.</p>
<h4>Step 4: paste data in Excel</h4>
<p>Once you run the long-only and short-only systems, we are done with TradersStudio. We need to move the data over to Excel for analysis and the e-ratio computation.<br />
Copy the custom trade report from the short-only system run to one sheet and from the long-only run to another sheet (watch out for the number of rows: if you have more than 65,536 and a version of Excel earlier than 2007 you will need to do that in several chunks).</p>
<h4>Step 5: Run e-ratio macro</h4>
<p>Copy the macro code from the text file, create a new VBA module in Excel and paste the code in it.<br />
Go back to both sheets and run the macro. This should manipulate the data and create an aggregation pivot table on a separate sheet.</p>
<h4>Step 6: Compute the e-ratio</h4>
<p>On a brand new sheet, copy both pivot tables (I recommend a paste/special &#8211; values only) side by side so that each trade length values corespond with each other. Sum each Total value (column D and J) together for the same Buy and Sell parameters (in column N in example file). Divide each Sum of MFE by Sum of MAE: this gives you the e-ratio for the given trade length.</p>
<h3>THE CODE</h3>
<p>Please find below code files to support the example below (all txt files except the Excel workbook). This should be easily portable to any system (i.e. just change entry criteria in the system).<br />
<a href="http://www.automated-trading-system.com/wp-content/uploads/2009/10/e-ratio/DonchianChannel.txt" target="_blank">Donchian Channel Indicator</a><br />
<a href="http://www.automated-trading-system.com/wp-content/uploads/2009/10/e-ratio/MyCustomTBT.txt" target="_blank">Custom trade Report</a><br />
<a href="http://www.automated-trading-system.com/wp-content/uploads/2009/10/e-ratio/DonchianChanBrkoutFiltBuy.txt" target="_blank">Buy System</a><br />
<a href="http://www.automated-trading-system.com/wp-content/uploads/2009/10/e-ratio/DonchianChanBkoutFiltSell.txt" target="_blank">Sell System</a><br />
<a href="http://www.automated-trading-system.com/wp-content/uploads/2009/10/e-ratio/e-ratio XL macro.txt" target="_blank">Excel e-ratio macro (text file)</a><br />
<a href="http://www.automated-trading-system.com/wp-content/uploads/2009/10/e-ratio/Sample e-ratio calc.xls" target="_blank">Excel example workbook</a> (does not contain underlying raw data as it is 60MB!)</p>
<p>Or if you prefer a zipped version of all files &#8211; <a href="http://www.automated-trading-system.com/wp-content/uploads/2009/10/e-ratio/e-ratio.zip" target="_blank">here it is</a>.</p>
<p>Any questions, clarifications, etc. please let me know how I can help.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.automated-trading-system.com/e-ratio-tradersstudio-excel/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Are you reading the essential books?</title>
		<link>http://www.automated-trading-system.com/essential-trading-books/</link>
		<comments>http://www.automated-trading-system.com/essential-trading-books/#comments</comments>
		<pubDate>Tue, 13 Oct 2009 11:06:37 +0000</pubDate>
		<dc:creator>Jez Liberty</dc:creator>
				<category><![CDATA[Backtest]]></category>
		<category><![CDATA[Blog]]></category>
		<category><![CDATA[Books]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Data]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Money Management]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Strategies]]></category>
		<category><![CDATA[Trend Following]]></category>
		<category><![CDATA[library]]></category>

		<guid isPermaLink="false">http://www.automated-trading-system.com/?p=386</guid>
		<description><![CDATA[I am bit of a geek and this is especially true when it comes to books. I firmly believe in self-development and I think books are a great medium to learn many things. Ok, the internet is so great to learn about new things; but nothing beats a good in-depth book(s) to really learn a [...]]]></description>
			<content:encoded><![CDATA[<p>I am bit of a geek and this is especially true when it comes to books. I firmly believe in self-development and I think books are a great medium to learn many things. Ok, the internet is so great to learn <em>about</em> new things; but nothing beats a good in-depth book(s) to really learn a subject by yourself.</p>
<p>This is the list of my real-life library dedicated to building automated trading systems. This is not the exhaustive list: I have more specialised books which I will add at a later stage (some I have not read yet&#8230;). But the collection below is a decent starting list:</p>
<p>Please feel free to suggest your book recommendations or any additional info using the comments section below.</p>
<p>Please find below the Library organised in several sections:</p>
<ul>
<li><a href="http://www.automated-trading-system.com/essential-trading-books/#TradingSystems" style="text-decoration:none; color:black;"><strong>TRADING SYSTEMS</strong></a></li>
<li><a href="http://www.automated-trading-system.com/essential-trading-books/#MoneyManagement" style="text-decoration:none; color:black;"><strong>MONEY MANAGEMENT</strong></a></li>
<li><a href="http://www.automated-trading-system.com/essential-trading-books/#TrendFollowing" style="text-decoration:none; color:black;"><strong>TREND FOLLOWING</strong></a></li>
<li><a href="http://www.automated-trading-system.com/essential-trading-books/#TradersInsights" style="text-decoration:none; color:black;"><strong>TRADERS INSIGHTS</strong></a></li>
<li><a href="http://www.automated-trading-system.com/essential-trading-books/#MarketsRiskChance" style="text-decoration:none; color:black;"><strong>MARKETS, RISK AND CHANCE</strong></a></li>
<li><a href="http://www.automated-trading-system.com/essential-trading-books/#Other" style="text-decoration:none; color:black;"><strong>OTHER</strong></a></li>
</ul>
<p><span id="more-386"></span></p>
<div style="line-height:125%;">
<table>
<tr>
<td colspan="2" style="padding-left:10px; padding-top:20px; padding-bottom:20px; font-size:1.4em;">
      <a name="TradingSystems" style="text-decoration:none; color:grey;"><strong>&#8211; TRADING SYSTEMS &#8211;</strong></a>
    </td>
</tr>
<tr>
<td valign="top" align="center">
      <img src="http://www.automated-trading-system.com/wp-content/uploads/library/images/book-covers/small/new-trading-systems-and-methods-kaufman_small.jpg">
    </td>
<td valign="top">
      <strong>New Trading Systems and Methods &#8211; Perry Kaufman</strong><br />
      <em>An encyclopedic (1,000+ pages) review of Systems Ideas and Methods</em><br />
      <span style="line-height:200%;">&#8211;No review/summary yet&#8211;<br /></span>Look up on Amazon <a href="http://www.amazon.com/exec/obidos/ASIN/047126847X/autotradblog-20" target="_blank" rel="nofollow">US</a> | <a href="http://www.amazon.ca/exec/obidos/ASIN/047126847X/autotradblo02-20" target="_blank" rel="nofollow">CA</a> | <a href="http://www.amazon.co.uk/exec/obidos/ASIN/047126847X/autotradblo01-21" target="_blank" rel="nofollow">UK</a>
    </td>
</tr>
<tr height="10">
<td colspan="2"></td>
</tr>
<tr>
<td valign="top" align="center">
      <img src="http://www.automated-trading-system.com/wp-content/uploads/library/images/book-covers/small/quality-money-management-vanvliet-kumiega_small.jpg">
    </td>
<td valign="top">
      <strong>Quality Money Management &#8211; Benjamin Van Vliet &#038; Andrew Kumiega</strong><br />
      <em>Best practices in Systematic Trading Technology. Build it with Quality!</em><br />
      <span style="line-height:200%;">&#8211;No review/summary yet&#8211;<br /></span>Look up on Amazon <a href="http://www.amazon.com/exec/obidos/ASIN/0123725496/autotradblog-20" target="_blank" rel="nofollow">US</a> | <a href="http://www.amazon.ca/exec/obidos/ASIN/0123725496/autotradblo02-20" target="_blank" rel="nofollow">CA</a> | <a href="http://www.amazon.co.uk/exec/obidos/ASIN/0123725496/autotradblo01-21" target="_blank" rel="nofollow">UK</a>
    </td>
</tr>
<tr height="10">
<td colspan="2"></td>
</tr>
<tr>
<td valign="top" align="center">
      <img src="http://www.automated-trading-system.com/wp-content/uploads/library/images/book-covers/small/Trading-Systems-Money-Management-Stridsman_small.jpg">
    </td>
<td valign="top">
      <strong>Trading Systems and Money Management &#8211; Thomas Stridsman</strong><br />
      <em>Presents a strong approach to developing Trading Systems integrating Money Management concepts</em><br />
      <span style="line-height:200%;">&#8211;No review/summary yet&#8211;<br /></span>Look up on Amazon <a href="http://www.amazon.com/exec/obidos/ASIN/0071400192/autotradblog-20" target="_blank" rel="nofollow">US</a> | <a href="http://www.amazon.com/exec/obidos/ASIN/0071400192/autotradblog-20" target="_blank" rel="nofollow">CA</a> | <a href="http://www.amazon.co.uk/exec/obidos/ASIN/0071400192/autotradblo01-21" target="_blank" rel="nofollow">UK</a>
    </td>
</tr>
<tr>
<td colspan="2" style="padding-left:10px; padding-top:20px; padding-bottom:20px; font-size:1.4em;">
      <a name="MoneyManagement" style="text-decoration:none; color:grey;"><strong>&#8211; MONEY MANAGEMENT &#8211;</strong></a>
    </td>
</tr>
<tr>
<td valign="top" align="center">
      <img src="http://www.automated-trading-system.com/wp-content/uploads/library/images/book-covers/small/balsara_small.jpg">
    </td>
<td valign="top">
      <strong>Money Management Strategies for Futures Traders &#8211; Nauzer Balsara</strong><br />
      <em>Complete introduction to the essential concept of Money Management.</em><br />
      <span style="line-height:200%;"><a href="http://www.automated-trading-system.com/balsara-money-management-strategies-for-futures-traders/">Check my review/summary</a><br /></span>Look up on Amazon <a href="http://www.amazon.com/exec/obidos/ASIN/0471522155/autotradblog-20" target="_blank" rel="nofollow">US</a> | <a href="http://www.amazon.ca/exec/obidos/ASIN/0471522155/autotradblo02-20" target="_blank" rel="nofollow">CA</a> | <a href="http://www.amazon.co.uk/exec/obidos/ASIN/0471522155/autotradblo01-21" target="_blank" rel="nofollow">UK</a>
    </td>
</tr>
<tr height="10">
<td colspan="2"></td>
</tr>
<tr>
<td valign="top" align="center">
      <img src="http://www.automated-trading-system.com/wp-content/uploads/library/images/book-covers/small/handbook-portfolio-mathematics-vince_small.jpg">
    </td>
<td valign="top">
      <strong>The Handbook of Portfolio Mathematics &#8211; Ralph Vince</strong><br />
      <em>Essential reading for Optimal Allocations and Leverage!</em><br />
      <span style="line-height:200%;">&#8211;No review/summary yet&#8211;<br /></span>Look up on Amazon <a href="http://www.amazon.com/exec/obidos/ASIN/0471757683/autotradblog-20" target="_blank" rel="nofollow">US</a> | <a href="http://www.amazon.ca/exec/obidos/ASIN/0471757683/autotradblo02-20" target="_blank" rel="nofollow">CA</a> | <a href="http://www.amazon.co.uk/exec/obidos/ASIN/0471757683/autotradblo01-21" target="_blank" rel="nofollow">UK</a>
    </td>
</tr>
<tr>
<td colspan="2" style="padding-left:10px; padding-top:20px; padding-bottom:20px; font-size:1.4em;">
      <a name="TrendFollowing" style="text-decoration:none; color:grey;"><strong>&#8211; TREND FOLLOWING &#8211;</strong></a>
    </td>
</tr>
<tr>
<td valign="top" align="center">
      <img src="http://www.automated-trading-system.com/wp-content/uploads/library/images/book-covers/small/trend-following-covel_small.jpg">
    </td>
<td valign="top">
      <strong>Trend Following &#8211; Michael Covel</strong><br />
      <em>See Why and How Trend Following works. Over a dozen of top CTAs covered.</em><br />
      <span style="line-height:200%;">&#8211;No review/summary yet&#8211;<br /></span>Look up on Amazon <a href="http://www.amazon.com/exec/obidos/ASIN/013702018X/autotradblog-20" target="_blank" rel="nofollow">US</a> | <a href="http://www.amazon.ca/exec/obidos/ASIN/013702018X/autotradblo02-20" target="_blank" rel="nofollow">CA</a> | <a href="http://www.amazon.co.uk/exec/obidos/ASIN/013702018X/autotradblo01-21" target="_blank" rel="nofollow">UK</a>
    </td>
</tr>
<tr height="10">
<td colspan="2"></td>
</tr>
<tr>
<td valign="top" align="center">
      <img src="http://www.automated-trading-system.com/wp-content/uploads/library/images/book-covers/small/The-Complete-Turtle-Trader-Covel_small.jpg">
    </td>
<td valign="top">
      <strong>The Complete Turtle Trader &#8211; Michael Covel</strong><br />
      <em>The Turtle story and their complete rules</em><br />
      <span style="line-height:200%;">&#8211;No review/summary yet&#8211;<br /></span>Look up on Amazon <a href="http://www.amazon.com/exec/obidos/ASIN/0061241717/autotradblog-20" target="_blank" rel="nofollow">US</a> | <a href="http://www.amazon.ca/exec/obidos/ASIN/0061241709/autotradblo02-20" target="_blank" rel="nofollow">CA</a> | <a href="http://www.amazon.co.uk/exec/obidos/ASIN/0061241709/autotradblo01-21" target="_blank" rel="nofollow">UK</a>
    </td>
</tr>
<tr height="10">
<td colspan="2"></td>
</tr>
<tr>
<td valign="top" align="center">
      <img src="http://www.automated-trading-system.com/wp-content/uploads/library/images/book-covers/small/Way-of-the-Turtle-Faith_small.jpg">
    </td>
<td valign="top">
      <strong>Way of the Turtle &#8211; Curtis Faith</strong><br />
      <em>The Turtle experiment from the inside &#8211; told by a Turtle!</em><br />
      <span style="line-height:200%;">&#8211;No review/summary yet&#8211;<br /></span>Look up on Amazon <a href="http://www.amazon.com/exec/obidos/ASIN/007148664X/autotradblog-20" target="_blank" rel="nofollow">US</a> | <a href="http://www.amazon.ca/exec/obidos/ASIN/007148664X/autotradblo02-20" target="_blank" rel="nofollow">CA</a> | <a href="http://www.amazon.co.uk/exec/obidos/ASIN/007148664X/autotradblo01-21" target="_blank" rel="nofollow">UK</a>
    </td>
</tr>
<tr>
<td colspan="2" style="padding-left:10px; padding-top:20px; padding-bottom:20px; font-size:1.4em;">
      <a name="TradersInsights" style="text-decoration:none; color:grey;"><strong>&#8211; TRADERS INSIGHTS &#8211;</strong></a>
    </td>
</tr>
<tr>
<td valign="top" align="center">
      <img src="http://www.automated-trading-system.com/wp-content/uploads/library/images/book-covers/small/Market-Wizards-Schwager_small.jpg">
    </td>
<td valign="top">
      <strong>Market Wizards &#8211; Jack Schwager</strong><br />
      <em>Legendary interviews of top traders. Inspirational and &#8220;motivation-kicker&#8221;!</em><br />
      <span style="line-height:200%;">&#8211;No review/summary yet&#8211;<br /></span>Look up on Amazon <a href="http://www.amazon.com/exec/obidos/ASIN/1592802974/autotradblog-20" target="_blank" rel="nofollow">US</a> | <a href="http://www.amazon.ca/exec/obidos/ASIN/1592802974/autotradblo02-20" target="_blank" rel="nofollow">CA</a> | <a href="http://www.amazon.co.uk/exec/obidos/ASIN/1592802974/autotradblo01-21" target="_blank" rel="nofollow">UK</a>
    </td>
</tr>
<tr height="10">
<td colspan="2"></td>
</tr>
<tr>
<td valign="top" align="center">
      <img src="http://www.automated-trading-system.com/wp-content/uploads/library/images/book-covers/small/New-Market-Wizards-Schwager_small.jpg">
    </td>
<td valign="top">
      <strong>The New Market Wizards &#8211; Jack Schwager</strong><br />
      <em>Schwager strikes back! You&#8217;ll re-read him often.</em><br />
      <span style="line-height:200%;">&#8211;No review/summary yet&#8211;<br /></span>Look up on Amazon <a href="http://www.amazon.com/exec/obidos/ASIN/1592803377/autotradblog-20" target="_blank" rel="nofollow">US</a> | <a href="http://www.amazon.ca/exec/obidos/ASIN/1592803377/autotradblo02-20" target="_blank" rel="nofollow">CA</a> | <a href="http://www.amazon.co.uk/exec/obidos/ASIN/0887306675/autotradblo01-21" target="_blank" rel="nofollow">UK</a>
    </td>
</tr>
<tr>
<td colspan="2" style="padding-left:10px; padding-top:20px; padding-bottom:20px; font-size:1.4em;">
      <a name="MarketsRiskChance" style="text-decoration:none; color:grey;"><strong>&#8211; MARKETS, RISK AND CHANCE &#8211;</strong></a>
    </td>
</tr>
<tr>
<td valign="top" align="center">
      <img src="http://www.automated-trading-system.com/wp-content/uploads/library/images/book-covers/small/(mis)behavior-of-markets-mandelbrot_small.jpg">
    </td>
<td valign="top">
      <strong>The (mis)behavior of Markets &#8211; Benoit Mandelbrot</strong><br />
      <em>A fractal view of Risk, Ruin and Reward</em><br />
      <span style="line-height:200%;">&#8211;No review/summary yet&#8211;<br /></span>Look up on Amazon <a href="http://www.amazon.com/exec/obidos/ASIN/0465043577/autotradblog-20" target="_blank" rel="nofollow">US</a> | <a href="http://www.amazon.ca/exec/obidos/ASIN/0465043577/autotradblo02-20" target="_blank" rel="nofollow">CA</a> | <a href="http://www.amazon.co.uk/exec/obidos/ASIN/0465043550/autotradblo01-21" target="_blank" rel="nofollow">UK</a>
    </td>
</tr>
<tr height="10">
<td colspan="2"></td>
</tr>
<tr>
<td valign="top" align="center">
      <img src="http://www.automated-trading-system.com/wp-content/uploads/library/images/book-covers/small/black-swan-taleb_small.jpg">
    </td>
<td valign="top">
      <strong>The Black Swan &#8211; Nasim Taleb</strong><br />
      <em>Taleb re-writes the rules of risk. An excellent perspective on conventionally accepted concepts</em><br />
      <span style="line-height:200%;">&#8211;No review/summary yet&#8211;<br /></span>Look up on Amazon <a href="http://www.amazon.com/exec/obidos/ASIN/1400063515/autotradblog-20" target="_blank" rel="nofollow">US</a> | <a href="http://www.amazon.ca/exec/obidos/ASIN/1400063515/autotradblo02-20" target="_blank" rel="nofollow">CA</a> | <a href="http://www.amazon.co.uk/exec/obidos/ASIN/0141034599/autotradblo01-21" target="_blank" rel="nofollow">UK</a>
    </td>
</tr>
<tr height="10">
<td colspan="2"></td>
</tr>
<tr>
<td valign="top" align="center">
      <img src="http://www.automated-trading-system.com/wp-content/uploads/library/images/book-covers/small/fooled-by-randomness-taleb_small.jpg">
    </td>
<td valign="top">
      <strong>Fooled by Randomness &#8211; Nasim Taleb</strong><br />
      <em>The hidden role of Chance in Life and the Markets</em><br />
      <span style="line-height:200%;">&#8211;No review/summary yet&#8211;<br /></span>Look up on Amazon <a href="http://www.amazon.com/exec/obidos/ASIN/1400067936/autotradblog-20" target="_blank" rel="nofollow">US</a> | <a href="http://www.amazon.ca/exec/obidos/ASIN/0812975219/autotradblo02-20" target="_blank" rel="nofollow">CA</a> | <a href="http://www.amazon.co.uk/exec/obidos/ASIN/0141031484/autotradblo01-21" target="_blank" rel="nofollow">UK</a>
    </td>
</tr>
<tr height="10">
<td colspan="2"></td>
</tr>
<tr>
<td valign="top" align="center">
      <img src="http://www.automated-trading-system.com/wp-content/uploads/library/images/book-covers/small/drunkards-walk-mlodinow_small.jpg">
    </td>
<td valign="top">
      <strong>The Drunkard&#8217;s Walk &#8211; Leonard Mlodinow</strong><br />
      <em>The hidden role of Chance in Life and the Markets</em><br />
      <span style="line-height:200%;">&#8211;No review/summary yet&#8211;<br /></span>Look up on Amazon <a href="http://www.amazon.com/exec/obidos/ASIN/0307275175/autotradblog-20" target="_blank" rel="nofollow">US</a> | <a href="http://www.amazon.ca/exec/obidos/ASIN/0307275175/autotradblo02-20" target="_blank" rel="nofollow">CA</a> | <a href="http://www.amazon.co.uk/exec/obidos/ASIN/0141026472/autotradblo01-21" target="_blank" rel="nofollow">UK</a>
    </td>
</tr>
<tr height="10">
<td colspan="2"></td>
</tr>
<tr>
<td valign="top" align="center">
      <img src="http://www.automated-trading-system.com/wp-content/uploads/library/images/book-covers/small/random-walk-down-wall-street-malkiel_small.jpg">
    </td>
<td valign="top">
      <strong>A Random Walk Down Wall Street &#8211; Burton Malkiel</strong><br />
      <em>The original classic claiming Efficiency in the Markets</em><br />
      <span style="line-height:200%;">&#8211;No review/summary yet&#8211;<br /></span>Look up on Amazon <a href="http://www.amazon.com/exec/obidos/ASIN/0393330338/autotradblog-20" target="_blank" rel="nofollow">US</a> | <a href="http://www.amazon.ca/exec/obidos/ASIN/0393330338/autotradblo02-20" target="_blank" rel="nofollow">CA</a> | <a href="http://www.amazon.co.uk/exec/obidos/ASIN/0393062457/autotradblo01-21" target="_blank" rel="nofollow">UK</a>
    </td>
</tr>
<tr height="10">
<td colspan="2"></td>
</tr>
<tr>
<td valign="top" align="center">
      <img src="http://www.automated-trading-system.com/wp-content/uploads/library/images/book-covers/small/non-random-walk-down-wall-street-lo-mackinlay_small.jpg">
    </td>
<td valign="top">
      <strong>A Non-Random Walk Down Wall Street &#8211;  Andrew lo &#038; Craig MacKinlay</strong><br />
      <em>Collection of academic papers on Efficiency Market Theory</em><br />
      <span style="line-height:200%;">&#8211;No review/summary yet&#8211;<br /></span>Look up on Amazon <a href="http://www.amazon.com/exec/obidos/ASIN/0691092567/autotradblog-20" target="_blank" rel="nofollow">US</a> | <a href="http://www.amazon.ca/exec/obidos/ASIN/0691092567/autotradblo02-20" target="_blank" rel="nofollow">CA</a> | <a href="http://www.amazon.co.uk/exec/obidos/ASIN/0691092567/autotradblo01-21" target="_blank" rel="nofollow">UK</a>
    </td>
</tr>
<tr height="10">
<td colspan="2"></td>
</tr>
<tr>
<td valign="top" align="center">
      <img src="http://www.automated-trading-system.com/wp-content/uploads/library/images/book-covers/small/when-genius-failed-lowenstein_small.jpg">
    </td>
<td valign="top">
      <strong>When Genius Failed &#8211; Roger Lowenstein</strong><br />
      <em>How mis-understanding of Risk and Money Management drove LTCM to their graves. Fascinating!</em><br />
      <span style="line-height:200%;">&#8211;No review/summary yet&#8211;<br /></span>Look up on Amazon <a href="http://www.amazon.com/exec/obidos/ASIN/0375758259/autotradblog-20" target="_blank" rel="nofollow">US</a> | <a href="http://www.amazon.ca/exec/obidos/ASIN/0375758259/autotradblo02-20" target="_blank" rel="nofollow">CA</a> | <a href="http://www.amazon.co.uk/exec/obidos/ASIN/1841155047/autotradblo01-21" target="_blank" rel="nofollow">UK</a>
    </td>
</tr>
<tr>
<td colspan="2" style="padding-left:10px; padding-top:20px; padding-bottom:20px; font-size:1.4em;">
      <a name="Other" style="text-decoration:none; color:grey;"><strong>&#8211; OTHER &#8211;</strong></a>
    </td>
</tr>
<tr>
<td valign="top" align="center">
      <img src="http://www.automated-trading-system.com/wp-content/uploads/library/images/book-covers/small/Schwager-on-Futures-Managed-Trading_small.jpg">
    </td>
<td valign="top">
      <strong>Schwager on Futures Managed Trading &#8211; Jack Schwager</strong><br />
      <em>In-depth investigation into the Managed Futures/CTA industry</em><br />
      <span style="line-height:200%;">&#8211;No review/summary yet&#8211;<br /></span>Look up on Amazon <a href="http://www.amazon.com/exec/obidos/ASIN/0471020575/autotradblog-20" target="_blank" rel="nofollow">US</a> | <a href="http://www.amazon.ca/exec/obidos/ASIN/0471020575/autotradblo02-20" target="_blank" rel="nofollow">CA</a> | <a href="http://www.amazon.co.uk/exec/obidos/ASIN/0471020575/autotradblo01-21" target="_blank" rel="nofollow">UK</a>
    </td>
</tr>
<tr height="10">
<td colspan="2"></td>
</tr>
<tr>
<td valign="top" align="center">
      <img src="http://www.automated-trading-system.com/wp-content/uploads/library/images/book-covers/small/starting-out-in-futures-trading-powers_small.jpg">
    </td>
<td valign="top">
      <strong>Starting Out in Futures Trading &#8211; Mark Powers</strong><br />
      <em>Learn the ropes of Futures Trading: a Beginner&#8217;s reference.</em><br />
      <span style="line-height:200%;">&#8211;No review/summary yet&#8211;<br /></span>Look up on Amazon <a href="http://www.amazon.com/exec/obidos/ASIN/0071363904/autotradblog-20" target="_blank" rel="nofollow">US</a> | <a href="http://www.amazon.ca/exec/obidos/ASIN/0071363904/autotradblo02-20" target="_blank" rel="nofollow">CA</a> | <a href="http://www.amazon.co.uk/exec/obidos/ASIN/0071363904/autotradblo01-21" target="_blank" rel="nofollow">UK</a>
    </td>
</tr>
<tr height="10">
<td colspan="2"></td>
</tr>
<tr>
<td valign="top" align="center">
      <img src="http://www.automated-trading-system.com/wp-content/uploads/library/images/book-covers/small/demark-indicators-perl_small.jpg">
    </td>
<td valign="top">
      <strong>DeMark Indicators Jason Perl</strong><br />
      <em>The clearest presentation of all TD indicators</em><br />
      <span style="line-height:200%;">&#8211;No review/summary yet&#8211;<br /></span>Look up on Amazon <a href="http://www.amazon.com/exec/obidos/ASIN/1576603148/autotradblog-20" target="_blank" rel="nofollow">US</a> | <a href="http://www.amazon.ca/exec/obidos/ASIN/1576603148/autotradblo02-20" target="_blank" rel="nofollow">CA</a> | <a href="http://www.amazon.co.uk/exec/obidos/ASIN/1576603148/autotradblo01-21" target="_blank" rel="nofollow">UK</a>
    </td>
</tr>
</table>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.automated-trading-system.com/essential-trading-books/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

