<?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; Trading Blox</title>
	<atom:link href="http://www.automated-trading-system.com/tag/trading-blox/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.automated-trading-system.com</link>
	<description>Systematic Trading research and development, with a flavour of Trend Following</description>
	<lastBuildDate>Tue, 07 Feb 2012 09:58:33 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Volatility Filters</title>
		<link>http://www.automated-trading-system.com/volatility-filters/</link>
		<comments>http://www.automated-trading-system.com/volatility-filters/#comments</comments>
		<pubDate>Thu, 23 Sep 2010 16:47:12 +0000</pubDate>
		<dc:creator>Jez Liberty</dc:creator>
				<category><![CDATA[Backtest]]></category>
		<category><![CDATA[Trend Following]]></category>
		<category><![CDATA[Trading Blox]]></category>
		<category><![CDATA[volatility]]></category>

		<guid isPermaLink="false">http://www.automated-trading-system.com/?p=2971</guid>
		<description><![CDATA[I have touched on trading regimes before; and looking at volatility-based regime switching was in my research stack since then. Today, I&#8217;m looking at a practical example: Trend Following results based on entry vs. past volatility. System Code Concept I developed a simple Trading Blox filter, which calculates the current volatility (via the Average True [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.automated-trading-system.com/wp-content/uploads/2010/09/filter-noortje.jpg" alt="filter-noortje" title="filter-noortje" width="240" height="300" class="alignleft size-full wp-image-2990" />I have touched on <a href="http://www.automated-trading-system.com/trading-regimes-strategy-filters/">trading regimes</a> before; and looking at <strong>volatility-based regime switching</strong> was in my research stack since then. Today, I&#8217;m looking at a practical example: <strong>Trend Following</strong> results based on <strong>entry vs. past volatility</strong>.</p>
<div></div>
<h3>System Code Concept</h3>
<p>I developed a simple Trading Blox filter, which calculates the <strong>current volatility</strong> (via the Average True Range) and its <a href="http://en.wikipedia.org/wiki/Percentile_rank" target="_blank" rel="nofollow"><strong>percentile rank</strong></a> over the past data.</p>
<p>The filter defines a range of accepted volatility ranking values, for which a trade can be taken. This would allow for a system to reject all trades for which volatility is too high (eg. in the top decile) or too low, or a mix of both.</p>
<p>The filter code is available for download at the end of this article. The parameters I used were 39 days for the (exponential) ATR and a lookback of 250 days for the percentile ranking.</p>
<p>The actual system tested here is a classic 20/50 <strong>Moving Average cross-over</strong> used in the <a href="http://www.automated-trading-system.com/category/trend-following/the-state-of-trend-following/">State of TF report</a>, using the same <a href="http://www.automated-trading-system.com/wp-content/uploads/2010/05/Instruments.html" target="_blank">diversified portfolio</a>.</p>
<h3>Volatility: Good or Bad?</h3>
<p>Trend Following is often thought of as a <strong>&#8220;long volatility&#8221;</strong> strategy, but could high volatility prior to trade entry be detrimental?<span id="more-2971"></span></p>
<p>In effect, Trend Following usually generates lots of small losers balanced out by small and medium winners, the positive performance coming from some large winners (from the <a href="http://www.automated-trading-system.com/why-trend-following-works-look-at-the-distribution/">fat-tails</a>). That&#8217;s one way of looking at it &#8211; which can be illustrated with this distribution of R-multiples for the 20/50 MA cross-over system:</p>
<p><img src="http://www.automated-trading-system.com/wp-content/uploads/2010/09/R-multiple.png" alt="R-multiple" title="R-multiple" width="480" height="486" class="aligncenter size-full wp-image-2974" /></p>
<p>All winning trades from 0R to 7R can be seen as balancing out the losing trades (mostly between 0R and 1R), whereas the &#8220;big hitter&#8221; trades (8R+) make up the profitability of the system.</p>
<p>If using a classic <strong>fixed fractional money management</strong> based on volatility (for example R = trade entry risk = 3 ATR = 1% equity), the R-multiple is akin to a volatility multiple. And with relatively high entry volatility, it is less likely that the volatility multiple can reach high values, and therefore the system is less likely to generate &#8220;big hitting&#8221; trades.</p>
<p>This is what we&#8217;re going to check.</p>
<h3>System Test Results</h3>
<p>In order to test the impact of trade entry volatility levels on <strong>trade profitability</strong>, I ran the system in steps, with the volatility filter boundaries covering each distinct decile (ie.  between 0 and 10%, 10% and 20%, etc.)</p>
<p>The results are below:</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.8em;">
      ATR Rank
    </th>
<th style="background-color:#e5eecc; border:1px solid #c3c3c3;  padding:2px; font-size: 0.8em;">
      # Trades
    </th>
<th style="background-color:#e5eecc; border:1px solid #c3c3c3;  padding:2px; font-size: 0.8em;">
      Win %
    </th>
</th>
<th style="background-color:#e5eecc; border:1px solid #c3c3c3;  padding:2px; font-size: 0.8em;">
      Pct Profit factor
    </th>
</th>
<th style="background-color:#e5eecc; border:1px solid #c3c3c3;  padding:2px; font-size: 0.8em;">
      R-multiple
    </th>
</tr>
<tr>
<td style="background-color:#ffffff; border:1px solid #c3c3c3;  padding:2px; font-size: 0.8em;">
0-10
    </td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3;  padding:2px; font-size: 0.8em;" align = "right">
1511
    </td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3;  padding:2px; font-size: 0.8em;" align = "right">
0.234
    </td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3;  padding:2px; font-size: 0.8em;" align = "right">
1.76
    </td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3;  padding:2px; font-size: 0.8em;" align = "right">
0.47
    </td>
</tr>
<tr>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3;  padding:2px; font-size: 0.8em;">
10-20
    </td>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3;  padding:2px; font-size: 0.8em;" align = "right">
1615
    </td>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3;  padding:2px; font-size: 0.8em;" align = "right">
0.272
    </td>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3;  padding:2px; font-size: 0.8em;" align = "right">
1.82
    </td>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3;  padding:2px; font-size: 0.8em;" align = "right">
0.52
    </td>
</tr>
<tr>
<td style="background-color:#ffffff; border:1px solid #c3c3c3;  padding:2px; font-size: 0.8em;">
20-30
    </td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3;  padding:2px; font-size: 0.8em;" align = "right">
1671
    </td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3;  padding:2px; font-size: 0.8em;" align = "right">
0.281
    </td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3;  padding:2px; font-size: 0.8em;" align = "right">
1.67
    </td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3;  padding:2px; font-size: 0.8em;" align = "right">
0.42
    </td>
</tr>
<tr>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3;  padding:2px; font-size: 0.8em;">
30-40
    </td>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3;  padding:2px; font-size: 0.8em;" align = "right">
1676
    </td>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3;  padding:2px; font-size: 0.8em;" align = "right">
0.262
    </td>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3;  padding:2px; font-size: 0.8em;" align = "right">
1.55
    </td>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3;  padding:2px; font-size: 0.8em;" align = "right">
0.36
    </td>
</tr>
<tr>
<td style="background-color:#ffffff; border:1px solid #c3c3c3;  padding:2px; font-size: 0.8em;">
40-50
    </td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3;  padding:2px; font-size: 0.8em;" align = "right">
1698
    </td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3;  padding:2px; font-size: 0.8em;" align = "right">
0.276
    </td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3;  padding:2px; font-size: 0.8em;" align = "right">
1.48
    </td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3;  padding:2px; font-size: 0.8em;" align = "right">
0.31
    </td>
</tr>
<tr>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3;  padding:2px; font-size: 0.8em;">
50-60
    </td>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3;  padding:2px; font-size: 0.8em;" align = "right">
1663
    </td>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3;  padding:2px; font-size: 0.8em;" align = "right">
0.283
    </td>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3;  padding:2px; font-size: 0.8em;" align = "right">
1.53
    </td>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3;  padding:2px; font-size: 0.8em;" align = "right">
0.34
    </td>
</tr>
<tr>
<td style="background-color:#ffffff; border:1px solid #c3c3c3;  padding:2px; font-size: 0.8em;">
60-70
    </td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3;  padding:2px; font-size: 0.8em;" align = "right">
1587
    </td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3;  padding:2px; font-size: 0.8em;" align = "right">
0.301
    </td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3;  padding:2px; font-size: 0.8em;" align = "right">
1.71
    </td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3;  padding:2px; font-size: 0.8em;" align = "right">
0.43
    </td>
</tr>
<tr>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3;  padding:2px; font-size: 0.8em;">
70-80
    </td>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3;  padding:2px; font-size: 0.8em;" align = "right">
1583
    </td>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3;  padding:2px; font-size: 0.8em;" align = "right">
0.312
    </td>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3;  padding:2px; font-size: 0.8em;" align = "right">
1.47
    </td>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3;  padding:2px; font-size: 0.8em;" align = "right">
0.3
    </td>
</tr>
<tr>
<td style="background-color:#ffffff; border:1px solid #c3c3c3;  padding:2px; font-size: 0.8em;">
80-90
    </td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3;  padding:2px; font-size: 0.8em;" align = "right">
1452
    </td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3;  padding:2px; font-size: 0.8em;" align = "right">
0.293
    </td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3;  padding:2px; font-size: 0.8em;" align = "right">
1.36
    </td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3;  padding:2px; font-size: 0.8em;" align = "right">
0.23
    </td>
</tr>
<tr>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3;  padding:2px; font-size: 0.8em;">
90-100
    </td>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3;  padding:2px; font-size: 0.8em;" align = "right">
1295
    </td>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3;  padding:2px; font-size: 0.8em;" align = "right">
0.275
    </td>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3;  padding:2px; font-size: 0.8em;" align = "right">
1.18
    </td>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3;  padding:2px; font-size: 0.8em;" align = "right">
0.12
    </td>
</tr>
</table>
<p>&nbsp;<br />
There does seem to be a negative trend between trade average R-multiple and relative volatility value:</p>
<p><img src="http://www.automated-trading-system.com/wp-content/uploads/2010/09/Trade-Stats1.png" alt="Trade-Stats" title="Trade-Stats" width="371" height="251" class="aligncenter size-full wp-image-2976" /></p>
<p>What is quite striking is that the Win % does not change much across all deciles (and if anything goes slightly up), unlike the average R-multiple. This seems to indicate that the winning trades simply fail to hit these high R-values when volatility is high at time of entry.</p>
<p>Below are the results when zooming in on the top decile:</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.8em;">
      ATR Rank
    </th>
<th style="background-color:#e5eecc; border:1px solid #c3c3c3;  padding:2px; font-size: 0.8em;">
      # Trades
    </th>
<th style="background-color:#e5eecc; border:1px solid #c3c3c3;  padding:2px; font-size: 0.8em;">
      Win %
    </th>
</th>
<th style="background-color:#e5eecc; border:1px solid #c3c3c3;  padding:2px; font-size: 0.8em;">
      Pct Profit factor
    </th>
</th>
<th style="background-color:#e5eecc; border:1px solid #c3c3c3;  padding:2px; font-size: 0.8em;">
      R-multiple
    </th>
</tr>
<tr>
<td style="background-color:#ffffff; border:1px solid #c3c3c3;  padding:2px; font-size: 0.8em;">
91-100
    </td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3;  padding:2px; font-size: 0.8em;" align = "right">
1254
    </td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3;  padding:2px; font-size: 0.8em;" align = "right">
0.257
    </td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3;  padding:2px; font-size: 0.8em;" align = "right">
1.11
    </td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3;  padding:2px; font-size: 0.8em;" align = "right">
0.07
    </td>
</tr>
<tr>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3;  padding:2px; font-size: 0.8em;">
92-100
    </td>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3;  padding:2px; font-size: 0.8em;" align = "right">
1215
    </td>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3;  padding:2px; font-size: 0.8em;" align = "right">
0.255
    </td>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3;  padding:2px; font-size: 0.8em;" align = "right">
1.11
    </td>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3;  padding:2px; font-size: 0.8em;" align = "right">
0.07
    </td>
</tr>
<tr>
<td style="background-color:#ffffff; border:1px solid #c3c3c3;  padding:2px; font-size: 0.8em;">
93-100
    </td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3;  padding:2px; font-size: 0.8em;" align = "right">
1169
    </td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3;  padding:2px; font-size: 0.8em;" align = "right">
0.243
    </td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3;  padding:2px; font-size: 0.8em;" align = "right">
1.02
    </td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3;  padding:2px; font-size: 0.8em;" align = "right">
0.01
    </td>
</tr>
<tr>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3;  padding:2px; font-size: 0.8em;">
94-100
    </td>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3;  padding:2px; font-size: 0.8em;" align = "right">
1135
    </td>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3;  padding:2px; font-size: 0.8em;" align = "right">
0.234
    </td>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3;  padding:2px; font-size: 0.8em;" align = "right">
1.02
    </td>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3;  padding:2px; font-size: 0.8em;" align = "right">
0.01
    </td>
</tr>
<tr>
<td style="background-color:#ffffff; border:1px solid #c3c3c3;  padding:2px; font-size: 0.8em;">
95-100
    </td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3;  padding:2px; font-size: 0.8em;" align = "right">
1068
    </td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3;  padding:2px; font-size: 0.8em;" align = "right">
0.23
    </td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3;  padding:2px; font-size: 0.8em;" align = "right">
0.98
    </td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3;  padding:2px; font-size: 0.8em;" align = "right">
-0.01
    </td>
</tr>
<tr>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3;  padding:2px; font-size: 0.8em;">
96-100
    </td>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3;  padding:2px; font-size: 0.8em;" align = "right">
1021
    </td>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3;  padding:2px; font-size: 0.8em;" align = "right">
0.231
    </td>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3;  padding:2px; font-size: 0.8em;" align = "right">
0.98
    </td>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3;  padding:2px; font-size: 0.8em;" align = "right">
-0.02
    </td>
</tr>
<tr>
<td style="background-color:#ffffff; border:1px solid #c3c3c3;  padding:2px; font-size: 0.8em;">
97-100
    </td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3;  padding:2px; font-size: 0.8em;" align = "right">
914
    </td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3;  padding:2px; font-size: 0.8em;" align = "right">
0.228
    </td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3;  padding:2px; font-size: 0.8em;" align = "right">
1
    </td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3;  padding:2px; font-size: 0.8em;" align = "right">
0
    </td>
</tr>
<tr>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3;  padding:2px; font-size: 0.8em;">
98-100
    </td>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3;  padding:2px; font-size: 0.8em;" align = "right">
882
    </td>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3;  padding:2px; font-size: 0.8em;" align = "right">
0.221
    </td>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3;  padding:2px; font-size: 0.8em;" align = "right">
0.98
    </td>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3;  padding:2px; font-size: 0.8em;" align = "right">
-0.01
    </td>
</tr>
<tr>
<td style="background-color:#ffffff; border:1px solid #c3c3c3;  padding:2px; font-size: 0.8em;">
99-100
    </td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3;  padding:2px; font-size: 0.8em;" align = "right">
814
    </td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3;  padding:2px; font-size: 0.8em;" align = "right">
0.211
    </td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3;  padding:2px; font-size: 0.8em;" align = "right">
1.06
    </td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3;  padding:2px; font-size: 0.8em;" align = "right">
0.05
    </td>
</tr>
</table>
<p>&nbsp;<br />
Adding these high volatility trades might result in extra diversification (if one is to adopt the logic of &#8220;<em>the more the merrier</em>&#8220;) but they definitely do not seem to be the best use of your (probably precious) margin. If your available margin allows you to trade 50 instruments with no volatility filter, you might be able to trade 55 instruments at 90% max volatility instead, and get a better trade profitability.</p>
<p>In any case I ran a quick test by filtering the high volatility trades at 90%, 95% and 100% (no filtering) and the results show an improvement when filtering:</p>
<ul>
<li>90%: CAGR = 53.65%, MAR = 0.73</li>
<li>95%: CAGR = 52.90%, MAR = 0.68</li>
<li>100%: CAGR = 46.08%, MAR = 0.5</li>
</ul>
<h3>Code Download</h3>
<p>The Trading Blox code is composed of 2 blox:
<ul>
<ul>
<li>Auxiliary Blox, which calculates the percent rank for the ATR</li>
<li>Portfolio Filter Blox, which stops trades from being entered if they breach the acceptable percent rank range.</li>
</ul>
<p>These could be added to any standard system without modifications.</p>
<p><a href='http://www.automated-trading-system.com/wp-content/uploads/2010/09/Aux_ATRPctRank1.tbx'>Aux_ATRPctRank</a><br />
<a href='http://www.automated-trading-system.com/wp-content/uploads/2010/09/Port_ATRRankFilter.tbx'>Port_ATRRankFilter</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.automated-trading-system.com/volatility-filters/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Walk-Forward in Trading Blox: Back-Testing Adaptive Trading</title>
		<link>http://www.automated-trading-system.com/walk-forward-trading-blox/</link>
		<comments>http://www.automated-trading-system.com/walk-forward-trading-blox/#comments</comments>
		<pubDate>Wed, 08 Sep 2010 13:58:11 +0000</pubDate>
		<dc:creator>Jez Liberty</dc:creator>
				<category><![CDATA[Backtest]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Trading Blox]]></category>
		<category><![CDATA[walk-forward]]></category>

		<guid isPermaLink="false">http://www.automated-trading-system.com/?p=2866</guid>
		<description><![CDATA[A few months ago, I got quite interested when Trading Blox announced that they introduced a new walk-forward functionality in their latest version. I just got round to upgrading, and giving that walk-forward testing a go. Amongst other things, some of the chart features have been improved &#8211; as can be seen in the eye [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.automated-trading-system.com/wp-content/uploads/2010/09/surface-chart.png" alt="surface-chart" title="surface-chart" width="480" height="394" class="aligncenter size-full wp-image-2867" /></p>
<p>A few months ago, I got quite interested when Trading Blox announced that they introduced a <strong>new walk-forward functionality</strong> in their latest version. I just got round to upgrading, and giving that walk-forward testing a go. Amongst other things, some of the chart features have been improved &#8211; as can be seen in the <em>eye candy</em> above.</p>
<h3>How it works</h3>
<p>You can check this previous <a href="http://www.automated-trading-system.com/walk-forward-testing/">post for an explanation of how walk-forward works</a>, from a general point of view. Robert Pardo (usually credited with the invention of walk-forward) has also written <a href="http://www.amazon.com/exec/obidos/ASIN/0470128011/autotradblog-20" target="_blank" rel="nofollow">his book</a>few books</a> on the subject.</p>
<p>This new feature is a combination of small enhancements to the core application (ie. silent tests, dynamic date and starting equity settings, etc.) and a semi-custom script implementing the walk-forward testing procedure. It feels more like a (good) hack leveraging the core stepping functionality, rather than a functionality built from the ground up, but it does the job rather well (I looked at the underlying code and its ingenuity is actually pretty cool).<span id="more-2866"></span></p>
<p>A minor issue is that you have to work out the number of optimization/out-of-sample cycles. If you get that wrong, the test will not cover the desired time interval and it makes the process less automated. Apart from that, the settings are pretty straight-forward, you can choose lengths of optimization and out-of-sample phases as well as other options:</p>
<div id="attachment_2871" class="wp-caption aligncenter" style="width: 418px"><img src="http://www.automated-trading-system.com/wp-content/uploads/2010/09/walk-forward-options.png" alt="In the setting above, there are 8 cycles, each having a 5-year optimization phase and 1-year out-of-sample phase" title="walk-forward-options" width="408" height="246" class="size-full wp-image-2871" /><p class="wp-caption-text">In the settings above, there are 8 cycles, each having a 5-year optimization phase and 1-year out-of-sample phase</p></div>
<h3>Objective Function</h3>
<p>At the end of the <strong>optimization phase</strong> of each cycle, the system picks the best set of parameters to be used in the <strong>out-of-sample phase</strong>. However there are many ways to determine the <strong><em>best</em> system</strong>. Do you use raw CAGR, MAR, Sharpe ratio, etc.?</p>
<p>There is a need to define the <strong>objective function</strong> (also called <a href="http://www.automated-trading-system.com/bliss-function-quantify-trading-system-objective/">bliss function, as explained here</a>, which will be used to determine the best system performance.</p>
<p>Trading Blox calculates standard statistics (MAR, CAGR, Drawdown, etc.) which can all be used as the objective function, but also allows the implementation of custom statistics calculations. These <strong>custom statistics</strong> can then be used as the objective function.</p>
<h3>Output</h3>
<p>This is where you realise the functionality is not fully integrated into the app. The system shows the individual results of each out-of-sample runs:</p>
<p><img src="http://www.automated-trading-system.com/wp-content/uploads/2010/09/wf-results1.png" alt="wf-results" title="wf-results" width="480" height="112" class="aligncenter size-full wp-image-2874" /></p>
<p>The stats calculated relate to each out-of-sample run (1 year in my example), whereas ideally these should all be spliced together, to form <strong>one system</strong> with its own stats. Same applies to equity curves, which are charted year by year (as individual charts). It is still possible to access the Daily Equity log file to do this yourself but it would be nice to have it better automated. The fact that it is a script and not compiled core code might make it possible to customize it to implement this automation.</p>
<p>Another log file also allows you to investigate the results of each optimization run and check their performance:</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:monospace;">Starting optimization run ,225,2005-01-03, <span style="color: #8D38C9; font-weight: bold;">to</span> ,2010-01-01, <span style="color: #8D38C9; font-weight: bold;">with</span> starting equity ,166470686.069881530,
&nbsp;
Run ,225, of ,256, Stepped Parameters: ,
Name,<span style="color: #8D38C9; font-weight: bold;">Step</span> Value,Goodness Measure of ,64.497285767,
Run ( Index ),8.000000000,
Optimization Run,1.000000000,
Entry Breakout (days),20.000000000,
<span style="color: #E56717; font-weight: bold;">Exit</span> Breakout (days),10.000000000,
Starting optimization run ,226,2005-01-03, <span style="color: #8D38C9; font-weight: bold;">to</span> ,2010-01-01, <span style="color: #8D38C9; font-weight: bold;">with</span> starting equity ,166470686.069881530,
&nbsp;
&nbsp;
----------------------------------------,
Best goodness of ,64.497285767, was <span style="color: #151B8D; font-weight: bold;">on</span> run ,1.000000000,
----------------------------------------,
&nbsp;
Starting out of sample test ,241,2010-01-01, <span style="color: #8D38C9; font-weight: bold;">to</span> ,2010-09-07, <span style="color: #8D38C9; font-weight: bold;">with</span> starting equity ,166470686.069881530,</pre></div></div>

<h3>Test Results</h3>
<p>For my first &#8220;test ride&#8221; of the walk-forward functionality, I used the <em>good ol&#8217;</em> <strong>Donchian system</strong>.</p>
<p>The system parameters being tested are the Entry and Exit breakout lengths ranging from 20 to 50 days for the entry and 10 to 25 days for the exit.</p>
<p>The parameters for the walk-forward procedure are a <strong>5-year optimization phase and 1-year out-of-sample phase</strong> with the plain CAGR stat being used as the objective/bliss/goodness function. The dates of the test go from 1998 to 2010 (but bear in mind that the first out-of-sample result is from 2003, ie. 1998 to 2002 are used as first optimization period).</p>
<p>The results (year by year) are the ones shown in the section above.</p>
<p>For an interesting comparison, I ran a standard stepped test using the same Donchian system and parameter values. Check below how the walk-forward system performance stacks up against the range of outputs from the stepped test:</p>
<div id="attachment_2878" class="wp-caption aligncenter" style="width: 462px"><img src="http://www.automated-trading-system.com/wp-content/uploads/2010/09/perf-results.png" alt="walk-forward in yellow" title="perf-results" width="452" height="325" class="size-full wp-image-2878" /><p class="wp-caption-text">All test results with the walk-forward result in yellow</p></div>
<p>In hindsight, it would have been better to pick other systems that performed better, but the advantage of the walk-forward process is that it adapts itself to pick a system.</p>
<h3>In Closing</h3>
<p>The walk-forward functionality is definitely not a fully-fledged feature of Trading Blox (yet?) &#8211; however it does allow for some automation of the process. The fact that it is &#8220;open&#8221; is probably a good thing as it can be tinkered with and improved easily. A nice addition to the product&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.automated-trading-system.com/walk-forward-trading-blox/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Slippage: Are your back-testing results realistic?</title>
		<link>http://www.automated-trading-system.com/slippage-backtesting-realistic/</link>
		<comments>http://www.automated-trading-system.com/slippage-backtesting-realistic/#comments</comments>
		<pubDate>Mon, 10 May 2010 12:25:49 +0000</pubDate>
		<dc:creator>Jez Liberty</dc:creator>
				<category><![CDATA[Backtest]]></category>
		<category><![CDATA[slippage]]></category>
		<category><![CDATA[Trading Blox]]></category>

		<guid isPermaLink="false">http://www.automated-trading-system.com/?p=2259</guid>
		<description><![CDATA[Slippage can make or break your trading system. Hard to believe? Read on and check the tests and charts further below&#8230; We recently talked about some data pitfalls that can affect your trading and testing of mechanical systems. Slippage was not mentioned. However, this is a critical piece of data to integrate in your back-testing [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.automated-trading-system.com/wp-content/uploads/2010/05/slippage_eek-the-cat2.jpg"><img src="http://www.automated-trading-system.com/wp-content/uploads/2010/05/slippage_eek-the-cat2.jpg" alt="slippage_eek the cat2" title="slippage_eek the cat2" width="280" height="370" class="aligncenter size-full wp-image-2260" /></a></p>
<p>Slippage can <strong>make or break</strong> your trading system.<br />
Hard to believe? Read on and check the tests and charts further below&#8230;</p>
<p>We recently talked about some <a href="http://www.automated-trading-system.com/data-pitfalls/">data pitfalls</a> that can affect your trading and testing of mechanical systems. <strong>Slippage </strong>was not mentioned. However, this is a <em>critical</em> piece of data to integrate in your back-testing parameters (and to get right if you want to get accurate backtest results).</p>
<p>I decided to study the impact of slippage on one of the trading systems from the suite used for the <a href="http://www.automated-trading-system.com/state-of-trend-following-draft-20100/">State of Trend Following report</a>.</p>
<h3>Impact of Slippage on Donchian System</h3>
<p>The system under study is the simple Donchian Channel with the following parameters:</p>
<ul>
<li>Entry breakout: 20 days</li>
<li>Exit breakout: 10 days</li>
<li>Entry Stop: 2 x 39-day exponential ATR, risking 1% of Total Equity</li>
</ul>
<p>One of the good things about Trading Blox is the wide range of parameters you can test in your simulation. There are over 30 simulation parameters such as interest, rollover, commissions, handling of lock-days, which can be tested to check their impact on the system performance.</p>
<p>So, I quickly fired up Trading Blox, and ran a stepped simulation with <strong>slippage varying from 0% to 35%</strong>.<span id="more-2259"></span></p>
<h3>Slippage in Trading Blox</h3>
<p>The slippage percentage is not an amount directly added/substracted to the entry/exit price. Instead it takes into account the range of the day of the order. From Trading Blox documentation:</p>
<blockquote><p>
For a long entry, the slippage factor is calculated by measuring the range from the theoretical entry price to the day&#8217;s highest price, and multiplying that amount by the Slippage Percent. (For short entries, the slippage factor is calculated by measuring the range from the theoretical entry price to the low). The slippage factor is then added to, or subtracted from the theoretical entry price, to obtain the simulated fill price.</p>
<p>Here&#8217;s how it works for a buy trade:</p>
<p><a href="http://www.automated-trading-system.com/wp-content/uploads/2010/05/TB-slippage.png"><img src="http://www.automated-trading-system.com/wp-content/uploads/2010/05/TB-slippage.png" alt="TB-slippage" title="TB-slippage" width="420" height="150" class="alignnone size-full wp-image-2261" /></a></p>
<p>Slippage percent: 25%<br />
Theoretical buy order price: 100<br />
High Price (for the day): 120<br />
Slippage Factor: (120 &#8211; 100) x 0.25 = (20 x 0.25) = 5<br />
Simulated fill price:  Order Price + Slippage Factor = (100 + 5) = 105</p>
<p>The distance between the high price and the order price is multiplied by the slippage factor. In this example, the difference between the high price and the order price is 20 points. The 20 points are multiplied by the 25% slippage to get an estimated slippage of 5 points. The fill price for the order will be 5 points worse than the stop order price of 100 simulating a fill at 105.</p></blockquote>
<h3>Slippage test results</h3>
<p>Here are the results of the stepped simulation and a chart of the resulting equity curves for each stepped test:</p>
<table border=1 frame=above rules=rows bordercolor=black cellpadding=2 cellspacing=0 style="font-size: 0.8em;">
<caption><strong>Stepped Parameter Summary Performance</strong></caption>
<tr>
<td bgcolor="#CCFFCC">&nbsp;&nbsp;Slippage (%)</td>
<td width=120 bgcolor="#CCFFCC">Ending Balance</td>
<td width=55 bgcolor="#CCFFCC">CAGR%</td>
<td width=40 bgcolor="#CCFFCC">MAR</td>
<td width=60 bgcolor="#CCFFCC">Modified Sharpe</td>
<td width=50 bgcolor="#CCFFCC">Annual Sharpe</td>
<td width=80 bgcolor="#CCFFCC">Max Total Equity DD</td>
<td width=80 bgcolor="#CCFFCC">Longest Drawdown</td>
<td width=60 bgcolor="#CCFFCC"># Trades</td>
</tr>
<tr>
<td style="font-size:1pt" colspan=14 height = 1><img src="spacer.gif" width=1 height=1></td>
</tr>
<tr>
<td>0%</td>
<td>6,002,394,255.23</td>
<td>56.26%</td>
<td>1.08</td>
<td>1.02</td>
<td>0.49</td>
<td>52.1%</td>
<td>27.4</td>
<td>6,483</td>
</tr>
<tr>
<td>5%</td>
<td>555,900,504.33</td>
<td>32.36%</td>
<td>0.51</td>
<td>0.73</td>
<td>0.31</td>
<td>63.6%</td>
<td>50.6</td>
<td>6,482</td>
</tr>
<tr>
<td>10%</td>
<td>166,197,092.85</td>
<td>21.66%</td>
<td>0.29</td>
<td>0.59</td>
<td>0.21</td>
<td>74.5%</td>
<td>58.5</td>
<td>6,473</td>
</tr>
<tr>
<td>15%</td>
<td>33,017,684.15</td>
<td>8.69%</td>
<td>0.11</td>
<td>0.40</td>
<td>0.07</td>
<td>82.1%</td>
<td>59.8</td>
<td>6,392</td>
</tr>
<tr>
<td>20%</td>
<td>8,004,611.35</td>
<td>-1.54%</td>
<td>-0.02</td>
<td>0.24</td>
<td>-0.06</td>
<td>91.5%</td>
<td>128.9</td>
<td>6,371</td>
</tr>
<tr>
<td>25%</td>
<td>1,914,036.01</td>
<td>-10.89%</td>
<td>-0.11</td>
<td>0.07</td>
<td>-0.22</td>
<td>96.1%</td>
<td>128.9</td>
<td>6,371</td>
</tr>
<tr>
<td>30%</td>
<td>455,560.44</td>
<td>-19.39%</td>
<td>-0.20</td>
<td>-0.13</td>
<td>-0.43</td>
<td>98.4%</td>
<td>128.9</td>
<td>6,349</td>
</tr>
<tr>
<td>35%</td>
<td>142,291.14</td>
<td>-25.67%</td>
<td>-0.26</td>
<td>-0.37</td>
<td>-0.86</td>
<td>99.3%</td>
<td>128.9</td>
<td>5,573</td>
</tr>
</table>
<p><a href="http://www.automated-trading-system.com/wp-content/uploads/2010/05/slippage.png"><img src="http://www.automated-trading-system.com/wp-content/uploads/2010/05/slippage.png" alt="slippage" title="slippage" width="492" height="353" class="aligncenter size-full wp-image-2272" /></a></p>
<p>The impact of slippage is rather dramatic. Even ignoring the extreme cases, consider the difference between a back-test with no slippage and the next one up, with a small 5% number: the performance is cut drastically to a point where the MAR ratio of the system is more than halved (1.08 v 0.51) as both CAGR and Drawdowns deteriorate sharply.</p>
<p>Imagine setting up a buy order for 100 tomorrow. If the price trades between 99 and 102, your order should be filled. However, with 5% slippage, the fill price would be 100.1 instead of the order price of 100. This is the difference between a good system and a not-so-good one&#8230;</p>
<h3>Slippage: fact of life for Trend Followers</h3>
<p>Most Trend Following systems get in and out in the same direction as the current price momentum. Therefore, this keeps them more exposed to slippage than a mean-reversion system, for example.</p>
<p>Unfortunately, this is not something that can be tested, apart from running tests in real markets (or having some more complete and granular data, such as tick data, complemented with some book depth information).</p>
<p>An idea to investigate would be to <strong>avoid the obvious price levels</strong> that every trader and their dog are watching (ie breakout of 20-day range, 50-day moving average, etc.). Alternative but close parameter values (19 or 21-day breakouts, 50-day MA + 1%, etc.) could possibly give similar results (they should if the system is robust) but trade at levels less watched and possibly expose the system to less slippage.</p>
<h3>Slippage at the &#8220;Pros&#8221;</h3>
<p>I was recently talking to an emergent Trend Following hedge fund in London. They mentioned their team of two traders to enter and manage positions. You could think that the need for two traders in a Long Term Trend Following fund managing under $20M is possibly superflous. However the result they were getting is <strong>negative slippage</strong>, which, as the backtest results show, can mean much more than just a nice little extra boost to the overall performance.</p>
<p>Aspect Capital, one of the <a href="http://www.automated-trading-system.com/resources/trend-following-wizards-fund-performance/">Trend Following Wizards</a>, is an example of a large fund having developed a research team and infrastructure to enhance their trade executions, with the use of algorithmic trading (execution) in combination with their trading desk. This is used in addition to their main alpha-generating automated trading signals. Their approach is discussed in an <a href="http://www.automatedtrader.net/articles/my-machine/614/empirical-execution-aspect-capital" target="_blank" rel="nofollow">interview with Automated Trader magazine</a>:</p>
<blockquote><p>
&#8220;At the moment about 90% of our electronic trading is managed by our algorithmic execution model&#8221;</p>
<p>&#8220;we see automation as being of value in [...] removing our footprint in the market by keeping our order flow under the radar&#8221;</p>
<p>&#8220;We have a team of three people mostly focused on the execution algorithms&#8221;
</p></blockquote>
<h3>Slippage: an essential part of a System</h3>
<p>Slippage might be considered as an after-thought in developing an automated trading system, However, the results of our tests point to slippage being a core contributor to the overall system performance. This is further highlighted by the effort professional fund managers put in to improve their executions.</p>
<p>The question is: how can you reduce slippage as a small trader? Sure, your footprint is much smaller than the big funds, but if you employ a Trend Following system you&#8217;re likely to occur slippage. Probably a case where it does not pay to be a <a href="http://www.automated-trading-system.com/small-fish-big-trading-pond/">small fish in a big pond</a> (with bigger fish having better market access).<br />
&nbsp;<br />
&nbsp;<br />
&nbsp;<br />
<sup>Picture credits: eek-the-cat@flickr</sup></p>
]]></content:encoded>
			<wfw:commentRss>http://www.automated-trading-system.com/slippage-backtesting-realistic/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Data Pitfalls: a true Minefield?</title>
		<link>http://www.automated-trading-system.com/data-pitfalls/</link>
		<comments>http://www.automated-trading-system.com/data-pitfalls/#comments</comments>
		<pubDate>Tue, 04 May 2010 09:55:36 +0000</pubDate>
		<dc:creator>Jez Liberty</dc:creator>
				<category><![CDATA[Data]]></category>
		<category><![CDATA[Back-Adjusted]]></category>
		<category><![CDATA[CSI]]></category>
		<category><![CDATA[rollover]]></category>
		<category><![CDATA[Trading Blox]]></category>

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

		<guid isPermaLink="false">http://www.automated-trading-system.com/?p=1841</guid>
		<description><![CDATA[I just have to get something out on this 1st beginning of March. I could keep polishing this report until Christmas&#8230; But instead here is a first draft. The State of Trend Following report will be published at the beginning of each month (expect it to be evolving for the first few months). The Concept [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.automated-trading-system.com/wp-content/uploads/2010/03/State-of-TF.png" alt="State of TF" title="State of TF" width="450" height="113" class="aligncenter size-full wp-image-1842" /></p>
<p>I just have to get something out on this <del>1st</del> beginning of March. I could keep polishing this report until Christmas&#8230; But instead here is a first draft. The <strong>State of Trend Following</strong> report will be published at the beginning of each month (expect it to be evolving for the first few months).</p>
<h3>The Concept</h3>
<p>The principle was inspired to me by Michael Stokes from <a href="http://marketsci.wordpress.com/" target="_blank">MarketSci</a> with his very smart <a href="http://marketsci.wordpress.com/state-of-the-market/" target="_blank">State of the Market report</a> describing how the markets are behaving.</p>
<p>The idea is to track several <em>classic</em> <strong>Trend Following</strong> systems over a wide range of instruments and <strong>different timeframes</strong>. This should, in theory be a good complement to tracking the <a href="http://www.automated-trading-system.com/trend-following-wizards/">Trend Following Wizards</a> to get an idea of how well Trend Following is doing as a strategy.</p>
<p>For this first report, I picked (arbitrarily) 3 standard Trend Following systems that ship with Trading Blox:</p>
<ul>
<li>Moving Average Crossover system with ATR-based stops</li>
<li>Bollinger Band Breakout</li>
<li>Triple Exponential Moving Average</li>
</ul>
<p>Each system is tested over<span id="more-1841"></span> a short, medium and longer timeframe. Details of the system rules,  parameters used and instruments traded can be found at the end of the post.</p>
<h3>The Background Picture</h3>
<p>As an initial run &#8211; to give a long-term idea of how each of the 9 systems performed (3 systems x 3 timeframes) &#8211; the whole futures data available in Trading Blox (provided free by CSI) was used for the backtest simulation.</p>
<p>One of the main interest of the study is how trends evolve over time and different systems. Therefore, the simulation parameters include no trade friction (ie no commissions and slippage at all). The equity curves below are therefore over-optimistic but they should really be used for <em>relative</em> comparisons.</p>
<div id="attachment_1847" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.automated-trading-system.com/wp-content/uploads/2010/03/State-TF-1996-2010.png" target="_blank"><img src="http://www.automated-trading-system.com/wp-content/uploads/2010/03/State-TF-1996-2010-300x204.png" alt="Systems Equity curves and Drawdowns. Each column represents a system (MA=MA Crossover; TMA=Triple Moving Average; BBBO=Bollinger Band Breakout) , with each row representing a timeframe (short, medium, long from top to bottom)" title="State-TF-1996-2010" width="300" height="204" class="size-medium wp-image-1847" /></a><p class="wp-caption-text">Chart showing Systems Equity curves and Drawdowns. Each column represents a system (MA=MA Crossover; TMA=Triple Moving Average; BBBO=Bollinger Band Breakout) , with each row representing a timeframe (short, medium, long from top to bottom) - Click to zoom in</p></div>
<p>If there is one trend that seems to be shared across all 9 systems, it is the increased volatility &#8211; expressed by the larger drawdowns having appeared in the last 4-5 years in all systems.</p>
<p>Imagine starting trading the Golden Crossover system (50-200 MA Crossover) on January 1st 2003 &#8211; after good backtesting results (CAGR>20% and worst drawdown around 10% &#8211; a MAR of 2), only to see drawdown figures quadruple in the next 5 years!</p>
<p>This could be down to the fact that most instruments have become more correlated in the last few years, in effect negating some benefits provided by diversification.</p>
<h3>Zoom in to 2009 and 2010</h3>
<p>We are also interested in the most recent picture. Below are 2 charts comparing our 9 systems on the 2009-2010 and 2010-only time horizons (each system adjusted back to 100 at the start of the period). Each type of system is represented in one colour and each timeframe in one line style:</p>
<p><img src="http://www.automated-trading-system.com/wp-content/uploads/2010/03/State-TF-2009-2010.png" alt="State-TF-2009-2010" title="State-TF-2009-2010" width="498" height="382" class="alignnone size-full wp-image-1852" /></p>
<p>Nothing very exciting in 2009, and with addition of trade friction, it seems to correlate with the (negative) results witnessed on the Trend Following Wizards. Also note that most systems follow the same path (apart from the short-term Bollinger system, all over the place with extreme volatility &#8211; the chart does not show it, but it closed February 2010 at around 60).</p>
<p><img src="http://www.automated-trading-system.com/wp-content/uploads/2010/03/State-TF-2010.png" alt="State-TF-2010" title="State-TF-2010" width="499" height="353" class="alignnone size-full wp-image-1853" /></p>
<p>2010 seems to be a continuation of 2009 so far: with a slight downward trend emerging across all systems.</p>
<h3>Improvements to the report</h3>
<p>There are quite a few things that could be added to this report, starting with integrating more systems and parameters (probably aggregated as an average per timeframe to avoid the <em>data deluge syndrome</em>). It might also be interesting to be able to break down the performance by type of markets/sectors.</p>
<p>But I am also open to your suggestions and requests. So <strong>please let me know</strong> in the comments below and I will integrate the best ideas.</p>
<p>Until next month&#8230;</p>
<h3>Appendix: System Details</h3>
<h4>System Rules and Parameters</h4>
<p>All the systems were tested with the same simplistic position sizing rules of 1% per new trade. No other Money/Risk Management rules were used.</p>
<p>The system rules are detailed on the Trading Blox online documentation.<br />
The <a href="http://www.tradingblox.com/Manuals/UsersGuideHTML/index.html?macd.htm" target="_blank" rel="nofollow">MA Crossover system</a> was used with moving average pairs of 10-20, 20-50 and 50-200 days. The stops are set at 5 x ATR(39).<br />
The <a href="http://www.tradingblox.com/Manuals/UsersGuideHTML/index.html?bollingerbreakout.htm" target="_blank" rel="nofollow">Bollinger Band system</a> is the classic use of the Bollinger Bands with entries taking place at Breakouts. The parameters used were 20, 50 and 200 days with 2 standard deviations.<br />
The <a href="http://www.tradingblox.com/Manuals/UsersGuideHTML/index.html?triplemovingaverage.htm" target="_blank" rel="nofollow">Triple moving Average system</a> was used with moving average triplets of 10-20-50, 20-50-200 and 50-200-800 days. The stops are set at 5 x ATR(39).</p>
<h4>Portfolio Instruments</h4>
<p>The instruments included in the simulation are a semi-diversified list of futures, contained in the <em>All Futures</em> Trading Blox set:</p>
<table style="border:1px solid #c3c3c3; border-collapse:collapse;">
<tr>
<th style="background-color:#e5eecc; border:1px solid #c3c3c3; padding-left:2px; font-size: 0.7em;" >
      CSI Num.
    </th>
<th style="background-color:#e5eecc; border:1px solid #c3c3c3; padding-left:2px; font-size: 0.7em;" >
      Futures Contract
    </th>
</tr>
<tr>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding-left:2px; font-size: 0.7em;" >
AD
    </td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding-left:2px; font-size: 0.7em;" >
Australian Dollar-CME(Floor+Electronic Combined)
    </td>
</tr>
<tr>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3; padding-left:2px; font-size: 0.7em;" >
BP
    </td>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3; padding-left:2px; font-size: 0.7em;" >
British Pound-CME(Floor+Electronic Combined)
    </td>
</tr>
<tr>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding-left:2px; font-size: 0.7em;" >
C
    </td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding-left:2px; font-size: 0.7em;" >
Corn-CBT (Floor+Electronic Combined)
    </td>
</tr>
<tr>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3; padding-left:2px; font-size: 0.7em;" >
CC
    </td>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3; padding-left:2px; font-size: 0.7em;" >
Cocoa-CSCE
    </td>
</tr>
<tr>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding-left:2px; font-size: 0.7em;" >
CD
    </td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding-left:2px; font-size: 0.7em;" >
Canadian Dollar-CME(Floor+Electronic Combined)
    </td>
</tr>
<tr>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3; padding-left:2px; font-size: 0.7em;" >
CL
    </td>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3; padding-left:2px; font-size: 0.7em;" >
Crude Oil-Light-NYMEX(Floor+Electronic Combined)
    </td>
</tr>
<tr>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding-left:2px; font-size: 0.7em;" >
CT
    </td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding-left:2px; font-size: 0.7em;" >
Cotton #2-NYCE
    </td>
</tr>
<tr>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3; padding-left:2px; font-size: 0.7em;" >
EC
    </td>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3; padding-left:2px; font-size: 0.7em;" >
Euro(Floor+Electronic Combined)-CME
    </td>
</tr>
<tr>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding-left:2px; font-size: 0.7em;" >
ED
    </td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding-left:2px; font-size: 0.7em;" >
Eurodollar-3 Mth-CME-Globex(Floor+Electronic Combined)
    </td>
</tr>
<tr>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3; padding-left:2px; font-size: 0.7em;" >
EM
    </td>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3; padding-left:2px; font-size: 0.7em;" >
LIBOR(1Mth)-CME(Floor+Electronic Combined)
    </td>
</tr>
<tr>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding-left:2px; font-size: 0.7em;" >
FC
    </td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding-left:2px; font-size: 0.7em;" >
Cattle-Feeder-CME(Floor+Electronic Combined)
    </td>
</tr>
<tr>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3; padding-left:2px; font-size: 0.7em;" >
GC
    </td>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3; padding-left:2px; font-size: 0.7em;" >
Gold-COMEX(Floor+Electronic Combined)
    </td>
</tr>
<tr>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding-left:2px; font-size: 0.7em;" >
HG
    </td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding-left:2px; font-size: 0.7em;" >
CopperHG-COMEX(Floor+Electronic Combined)
    </td>
</tr>
<tr>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3; padding-left:2px; font-size: 0.7em;" >
HO
    </td>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3; padding-left:2px; font-size: 0.7em;" >
Heating Oil #2-NYMEX(Floor+Electronic Combined)
    </td>
</tr>
<tr>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding-left:2px; font-size: 0.7em;" >
HU
    </td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding-left:2px; font-size: 0.7em;" >
Gasoline-Reformulated Blendstock(Combined)-NYMEX
    </td>
</tr>
<tr>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3; padding-left:2px; font-size: 0.7em;" >
JY
    </td>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3; padding-left:2px; font-size: 0.7em;" >
Japanese Yen-CME(Floor+Electronic Combined)
    </td>
</tr>
<tr>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding-left:2px; font-size: 0.7em;" >
KC
    </td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding-left:2px; font-size: 0.7em;" >
Coffee-CSCE
    </td>
</tr>
<tr>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3; padding-left:2px; font-size: 0.7em;" >
LC
    </td>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3; padding-left:2px; font-size: 0.7em;" >
Cattle-Live(Floor+Electronic Combined)-CME
    </td>
</tr>
<tr>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding-left:2px; font-size: 0.7em;" >
LH
    </td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding-left:2px; font-size: 0.7em;" >
Hogs-Lean(Floor+Electronic Combined)-CME
    </td>
</tr>
<tr>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3; padding-left:2px; font-size: 0.7em;" >
MP
    </td>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3; padding-left:2px; font-size: 0.7em;" >
Mexican Peso(Floor+Electronic Combined)-CME
    </td>
</tr>
<tr>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding-left:2px; font-size: 0.7em;" >
NG
    </td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding-left:2px; font-size: 0.7em;" >
Natural Gas-Henry Hub-NYMEX(Floor+Electronic Combined)
    </td>
</tr>
<tr>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3; padding-left:2px; font-size: 0.7em;" >
S
    </td>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3; padding-left:2px; font-size: 0.7em;" >
Soybeans (Floor+Electronic Combined)-CBT
    </td>
</tr>
<tr>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding-left:2px; font-size: 0.7em;" >
SB
    </td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding-left:2px; font-size: 0.7em;" >
Sugar #11-NYCE(Floor+Electronic Combined)
    </td>
</tr>
<tr>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3; padding-left:2px; font-size: 0.7em;" >
SF
    </td>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3; padding-left:2px; font-size: 0.7em;" >
Swiss Franc-CME-(Floor+Electronic Combined)
    </td>
</tr>
<tr>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding-left:2px; font-size: 0.7em;" >
SI
    </td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding-left:2px; font-size: 0.7em;" >
Silver-COMEX(Floor+Electronic Combined)
    </td>
</tr>
<tr>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3; padding-left:2px; font-size: 0.7em;" >
TY
    </td>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3; padding-left:2px; font-size: 0.7em;" >
T-Note-U.S. 10 Yr w/Prj A-CBT(Floor+Electronic Combined)X
    </td>
</tr>
<tr>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding-left:2px; font-size: 0.7em;" >
US
    </td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding-left:2px; font-size: 0.7em;" >
T-Bond-U.S.-CBT (Floor+Electronic Combined)
    </td>
</tr>
<tr>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3; padding-left:2px; font-size: 0.7em;" >
W
    </td>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3; padding-left:2px; font-size: 0.7em;" >
Wheat-CBT (Floor+Electronic Combined)
    </td>
</tr>
</table>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.automated-trading-system.com/state-of-trend-following-draft-201003/feed/</wfw:commentRss>
		<slash:comments>13</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>MMDI Portfolio Filter in Trading Blox</title>
		<link>http://www.automated-trading-system.com/mmdi-portfolio-filter-trading-blox/</link>
		<comments>http://www.automated-trading-system.com/mmdi-portfolio-filter-trading-blox/#comments</comments>
		<pubDate>Tue, 02 Feb 2010 12:21:08 +0000</pubDate>
		<dc:creator>Jez Liberty</dc:creator>
				<category><![CDATA[Backtest]]></category>
		<category><![CDATA[Futures]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Strategies]]></category>
		<category><![CDATA[robust]]></category>
		<category><![CDATA[screenshots]]></category>
		<category><![CDATA[Trading Blox]]></category>
		<category><![CDATA[Trend Following]]></category>

		<guid isPermaLink="false">http://www.automated-trading-system.com/?p=1447</guid>
		<description><![CDATA[David Varadi, from the very good CSS Analytics blog, pointed me to his interesting findings on a Mean Median Divergence Indicator (MMDI) he devised as a replacement to the standard MACD. I wanted to test the MMDI as a follow-up to Moving Median: a better indicator than Moving Average?. This also provided a good opportunity [...]]]></description>
			<content:encoded><![CDATA[<p>David Varadi, from the <a href="http://cssanalytics.wordpress.com/" target="_blank">very good CSS Analytics blog</a>, pointed me to his <a href="http://cssanalytics.wordpress.com/2009/08/06/meanmedian-divergence-a-great-trend-indicator-part-1/" target="_blank">interesting findings on a Mean Median Divergence Indicator</a> (MMDI) he devised as a replacement to the standard MACD.</p>
<p>I wanted to test the MMDI as a follow-up to <a href="http://www.automated-trading-system.com/moving-median-better-indicator-than-moving-average/">Moving Median: a better indicator than Moving Average?</a>. This also provided a good opportunity to test Trading Blox (which <a href="">I am thinking of buying</a>).</p>
<h3>MMDI: What is it?</h3>
<p>In short, this is an indicator very similar to the MACD, except that the short moving average of the MACD is replaced by a moving median.</p>
<h3>Portfolio Filter: Trade with the trend</h3>
<p>One concept often used to improve the edge of a trading system is to look at 2 or more timeframes. The main  timeframe (shorter one) is used for triggering trading signals (eg Donchian Channel breakouts), and the longer timeframe is used to determine the direction of the main trend. The filter rules prevent any trade signal to be taken if it goes against the main trend.</p>
<h3>Trading Blox: a componentized testing framework</h3>
<p>A great feature of Trading Blox is that it provides you with a <em>skeleton workflow</em> that forms the framework for the backtesting process. What this means is that Trading Blox implements and runs its logical workflow in the <em>simulation loop</em> (ie read data, update indicators, check entry signals, check exit signals, post-simulation scripts, etc.) but provides you with hooks at every step (about 35 hooks per simulation loop) where you can write your own code for customisation (with access to Trading Blox internal objects).<span id="more-1447"></span></p>
<p>Next is the concept of <em>blocks</em>, which represent the different components of a trading systems (Entry signals, Money Management, Risk Management, Portfolio Filter, etc.). These blocks are easily reusable in any system and implement the functionality required via the code contained in their scripts.</p>
<p>One such block we are interested in for today is the MACD Portfolio Filter:</p>
<div id="attachment_1458" class="wp-caption aligncenter" style="width: 460px"><img src="http://www.automated-trading-system.com/wp-content/uploads/2010/02/MACDPortfolioFilter.png" alt="MACD Portfolio Filter Blox" title="MACDPortfolioFilter" width="450" height="291" class="size-full wp-image-1458" /><p class="wp-caption-text">MACD Portfolio Filter Blox</p></div>
<p>This block stops the system from opening new trades in the opposite direction to the trend (the direction of the trend is derived from the MACD value).</p>
<h3>MMDI Portfolio Filter</h3>
<p>It was easy to use the standard Donchian channel system that ships with Trading Blox and replace its MACD Portfolio filter block by an implementation of the MMDI Portfolio filter. All it took was a copy of that block and an update of some of the scripts to implement the MMDI indicator and the filtering based on its value.</p>
<p>Indicator calculation:</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:monospace;">mmdiIndicator=Median(ohlcDiv4,mmdiShort)-emaIndicator</pre></div></div>

<p>Filtering code (long side):</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:monospace;">[...]
<span style="color: #008000;">' If positive, then allow long trades
</span><span style="color: #8D38C9; font-weight: bold;">IF</span> ( mmdiIndicator &gt; 0 ) <span style="color: #8D38C9; font-weight: bold;">THEN</span>
	instrument.AllowLongTrades
ENDIF
[...]</pre></div></div>

<p>And applying the new block (MMDI Portfolio Filter) to the system in the system editor screen:<br />
<div id="attachment_1458" class="wp-caption alignleft" style="width: 490px"><img src="http://www.automated-trading-system.com/wp-content/uploads/2010/02/SystemEditorMMDI.png" alt="SystemEditorMMDI" title="SystemEditorMMDI" width="480" height="343" class="alignleft size-full wp-image-1464" /><p class="wp-caption-text">System Editor</p></div><br />
&nbsp;<br />
&nbsp;</p>
<h3>Test Scenario</h3>
<p>The test is a comparison of the standard Donchian Channel breakout Tend Following system with MACD Portfolio Filter against its variation using the MMDI Portfolio Filter.</p>
<p>In order to get more data points (and to test Trading Blox parameter stepping), the comparison was run over a combination of system parameters:<br />
- Long MMDI Moving Average: 200, 250 and 300<br />
- Short MMDI Moving Median: 50, 62 and 74<br />
- Donchian Channel Length (Entry): 20, 30 and 40<br />
- Donchian Channel Length (Exit): 15<br />
- Stop level: 2 x ATR(40)<br />
- Slippage: 15% of ATR (+3% at rollover)<br />
- Commissions: $12.50 per contract<br />
- Dates: 01/01/2001 to 09/30/2010<br />
- Instruments: 28 liquid futures (currencies, commodities, financials)</p>
<h3>Test Results</h3>
<p>Here are the two results tables produced by Trading Blox, showing a few stats for each system tested:</p>
<div id="attachment_1450" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.automated-trading-system.com/wp-content/uploads/2010/02/MACD_Results.png" target="_blank"><img src="http://www.automated-trading-system.com/wp-content/uploads/2010/02/MACD_Results-300x182.png" alt="MACD Portfolio Filter Results" title="MACD_Results" width="300" height="182" class="size-medium wp-image-1450" /></a><p class="wp-caption-text">MACD Portfolio Filter Results - click to expand</p></div>
<div id="attachment_1451" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.automated-trading-system.com/wp-content/uploads/2010/02/MMDI_Results.png" target="_blank"><img src="http://www.automated-trading-system.com/wp-content/uploads/2010/02/MMDI_Results-300x180.png" alt="MMDI Portfolio Filter results" title="MMDI_Results" width="300" height="180" class="size-medium wp-image-1451" /></a><p class="wp-caption-text">MMDI Portfolio Filter results - click to expand</p></div>
<p>Looking at the CAGR and Sharpe ratio on aggregate, here is the how the systems compare:</p>
<table style="border:1px solid #c3c3c3; border-collapse:collapse;">
<tr>
<th style="background-color:#e5eecc; border:1px solid #c3c3c3; padding:5px;">
      Stats
    </th>
<th style="background-color:#e5eecc; border:1px solid #c3c3c3; padding:5px;">
      MACD Sys.
    </th>
<th style="background-color:#e5eecc; border:1px solid #c3c3c3; padding:5px;">
      MMDI Sys.
    </th>
</tr>
<tr>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding:2px;">
Median CAGR
    </td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding:2px;" align = "right">
<div style="color:black">13.94%</div>
</td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding:2px;" align = "right">
<div style="color:black">15.58%</div>
</td>
</tr>
<tr>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3; padding:2px;">
CAGR Median Absolute Deviation
    </td>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3; padding:2px;" align = "right">
<div style="color:black">1.68%</div>
</td>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3; padding:2px;" align = "right">
<div style="color:black">1.83%</div>
</td>
</tr>
<tr>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding:2px;">
CAGR Coefficient of Variation
    </td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding:2px;" align = "right">
0.1205
    </td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding:2px;" align = "right">
0.1175
    </td>
</tr>
<tr>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3; padding:2px;">
</td>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3; padding:2px;" align = "right">
    </td>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3; padding:2px;" align = "right">
    </td>
</tr>
<tr>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding:2px;">
Median Sharpe ratio
    </td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding:2px;" align = "right">
<div style="color:black">0.42</div>
</td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding:2px;" align = "right">
<div style="color:black">0.45</div>
</td>
</tr>
<tr>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3; padding:2px;">
Sharpe ratio Median Absolute Deviation
    </td>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3; padding:2px;" align = "right">
<div style="color:black">0.06</div>
</td>
<td style="background-color:#f3f3f3; border:1px solid #c3c3c3; padding:2px;" align = "right">
<div style="color:black">0.07</div>
</td>
</tr>
<tr>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding:2px;">
Sharpe ratio Coefficient of Variation
    </td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding:2px;" align = "right">
0.1429
    </td>
<td style="background-color:#ffffff; border:1px solid #c3c3c3; padding:2px;" align = "right">
0.1556
    </td>
</tr>
</table>
<h3>Conclusions</h3>
<p>First on Trading Blox: it was fairly straight-forward to code up this new indicator and system. The stepped parameter tests were also really quick to run (<1 min). Still pretty pleased and feeling at ease with it.</p>
<p>The test results show a small improvement in the MMDI favour. A possible explanation might be that the more volatile nature of the moving median (as illustrated in the <a href="http://www.automated-trading-system.com/moving-median-better-indicator-than-moving-average/">moving median indicator post</a>) allows it to pick up changes in trend faster (and get in them at an earlier, better price).</p>
<p>The whipsawing produced in the Moving Median crossover run would normally take place during range-bound markets, where few Donchain breakouts would happen, therefore cancelling the extra noise and losses associated with them.</p>
<p>Might be worth investigating further&#8230;<br />
&nbsp;<br />
&nbsp;<br />
PS: David&#8217;s code for MMDI on TradeStation is available for free on his <a href="http://www.dvindicators.com/indicator/mmdi/" target="_blank">dvindicators.com website</a></p>
<p>PS2: As a comparison, and to illustrate the impact of a portfolio filter, here are the results for the same system without any Portfolio Filter:</p>
<div id="attachment_1469" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.automated-trading-system.com/wp-content/uploads/2010/02/NoFilterResults.png" target="_blank"><img src="http://www.automated-trading-system.com/wp-content/uploads/2010/02/NoFilterResults-300x56.png" alt="Only 3 sets of results as the MACD/MMDI stepped parameters have been removed" title="NoFilterResults" width="300" height="56" class="size-medium wp-image-1469" /></a><p class="wp-caption-text">Only 3 sets of results as the MACD/MMDI stepped parameters have been removed  - click to expand</p></div>
<p>Without the trend filter applied to the portfolio, the Donchian channel breakout system now exhibits a negative performance (-2.68% on average across the 3 backtests). The trend is definitely your friend!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.automated-trading-system.com/mmdi-portfolio-filter-trading-blox/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Thinking of buying Trading Blox?</title>
		<link>http://www.automated-trading-system.com/trading-blox-teaser-review/</link>
		<comments>http://www.automated-trading-system.com/trading-blox-teaser-review/#comments</comments>
		<pubDate>Mon, 01 Feb 2010 11:59:29 +0000</pubDate>
		<dc:creator>Jez Liberty</dc:creator>
				<category><![CDATA[Backtest]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[amibroker]]></category>
		<category><![CDATA[comparison]]></category>
		<category><![CDATA[rollover]]></category>
		<category><![CDATA[screenshots]]></category>
		<category><![CDATA[tradersstudio]]></category>
		<category><![CDATA[Trading Blox]]></category>

		<guid isPermaLink="false">http://www.automated-trading-system.com/?p=1422</guid>
		<description><![CDATA[Well, I am&#8230; Regular readers might think that I suffer from backtesting-software-indecision-itis. Having first settled for TradersStudio, I then evaluated (and purchased) AmiBroker and found that it was 25 times faster than TradersStudio (at least for the calculation of the e-ratio). However, AmiBroker is not really geared towards true portfolio allocation testing with Futures and [...]]]></description>
			<content:encoded><![CDATA[<p>Well, I am&#8230;<br />
<a href="http://www.tradingblox.com/" target="_blank" rel="nofollow"><img src="http://www.automated-trading-system.com/wp-content/uploads/2010/01/TradingBloxLogo.jpg" alt="TradingBloxLogo" title="TradingBloxLogo" width="235" height="90" class="aligncenter size-full wp-image-1424" /></a></p>
<p>Regular readers might think that I suffer from <em>backtesting-software-indecision-itis</em>. Having <a href="http://www.automated-trading-system.com/tradersstudio-systems-testing-software/">first settled for TradersStudio</a>, I then evaluated (and purchased) AmiBroker and found that it was <a href="http://www.automated-trading-system.com/amibroker-tradersstudio-speed-comparison/">25 times faster than TradersStudio</a> (at least for the <a href="http://www.automated-trading-system.com/tag/e-ratio/">calculation of the e-ratio</a>). However, AmiBroker is not really geared towards true portfolio allocation testing with Futures and could not just <em>replace</em> TradersStudio &#8211; so I purchased it as a (cheap: $199) complement to it.</p>
<h3>Why TradersStudio in the first place?</h3>
<p>During my first round of evaluation, I did hesitate between TradersStudio and <a href="http://www.tradingblox.com/" target="_blank" rel="nofollow">Trading Blox</a>. At the time, it appeared that there was not a huge difference in functionality but a substantial price difference ($499 for TradersStudio, $3,000 for the full version of Trading Blox Builder). And this is how the choice was made.</p>
<p>However, I never really got past my TraderStudio&#8217;s first (not so good) impressions. Ultimately, I find the platform awkward to work with, documentation rather poor and the user community is very small.</p>
<p>So I decided to give Trading Blox another go and test their latest trial version (v3.3), and give you a <em>teaser</em> review of it.</p>
<h3>Trading Blox: friendly, efficient, fast, professional</h3>
<p>Trading Blox is vastly superior in terms of <span id="more-1422"></span>user interface &#8220;friendliness&#8221; and efficiency (love that script management/edit screen!). This makes the documentation lookup less necessary (and in any case, it is rather better).</p>
<p>The simulation runs are also very fast (300 stepped parameter tests under 7 minutes) and the software comes pre-packed with about a dozen ready-coded systems including the famous Turtle Trading system.</p>
<p>Finally, the numerous backtest options (slippage, commission, rollover slippage, volume, interest, etc.) should simulate trading reality much more closely.</p>
<p>Overall, it feels that the difference between Trading Blox and TradersStudio can be summed up by <em>Pro vs. Amateur</em>: both good at what they do, but playing in different leagues.</p>
<h3>User community</h3>
<p><a href="http://www.tradingblox.com/forum/" target="_blank" rel="nofollow">Trading Blox forum</a> is very good, with top-notch contributors. I joined it a few months ago and the discussion there is top-level, be it on all aspects of trading in general, backtesting, Data problems, Trading Blox questions, etc. It also has a <em>marketplace</em> where users can exchange code/systems, etc. This forum played a big part in my decision to re-consider Trading Blox (TradersStudio&#8217;s own forum and yahoo user group are barely ticking&#8230;).</p>
<h3>In closing: screenshots</h3>
<p>I feel I am about to give in and &#8220;cut my losses short&#8221; with TradersStudio and redeploy my resources towards Trading Blox. In the end, it is a &#8220;time vs dollar trade&#8221; and I feel that the initial outlay will give a great payback (in time savings and progress made). After all, automated trading is a business and one should not shy away from the essential investments.</p>
<p>Tomorrow, I should post a detailed system test using Trading Blox; but for now please find below some screenshots of the software (click to zoom in):<br />
<div id="attachment_1434" class="wp-caption aligncenter" style="width: 160px"><a href="http://www.automated-trading-system.com/wp-content/uploads/2010/01/TradingBloxSampleResults.htm" target="_blank"><img src="http://www.automated-trading-system.com/wp-content/uploads/2010/01/ResultReports-150x150.png" alt="Result Reports" title="ResultReports" width="150" height="150" class="size-thumbnail wp-image-1434" /></a><p class="wp-caption-text">Result Reports</p></div><br />
<div id="attachment_1431" class="wp-caption aligncenter" style="width: 160px"><a href="http://www.automated-trading-system.com/wp-content/uploads/2010/01/GeneralOptions.png" target="_blank"><img src="http://www.automated-trading-system.com/wp-content/uploads/2010/01/GeneralOptions-150x150.png" alt="rich choice in general options" title="GeneralOptions" width="150" height="150" class="size-thumbnail wp-image-1431" /></a><p class="wp-caption-text">rich choice in general options</p></div><br />
<div id="attachment_1432" class="wp-caption aligncenter" style="width: 160px"><a href="http://www.automated-trading-system.com/wp-content/uploads/2010/01/SystemEditor.png" target="_blank"><img src="http://www.automated-trading-system.com/wp-content/uploads/2010/01/SystemEditor-150x150.png" alt="System Editor" title="SystemEditor" width="150" height="150" class="size-thumbnail wp-image-1432" /></a><p class="wp-caption-text">System Editor</p></div><br />
<div id="attachment_1433" class="wp-caption aligncenter" style="width: 160px"><a href="http://www.automated-trading-system.com/wp-content/uploads/2010/01/BloxEditor.png" target="_blank"><img src="http://www.automated-trading-system.com/wp-content/uploads/2010/01/BloxEditor-150x150.png" alt="Blox Editor" title="BloxEditor" width="150" height="150" class="size-thumbnail wp-image-1433" /></a><p class="wp-caption-text">Blox Editor</p></div><br />
<div id="attachment_1435" class="wp-caption aligncenter" style="width: 160px"><a href="http://www.automated-trading-system.com/wp-content/uploads/2010/01/ResultsScatterPlot_P0.png" target="_blank"><img src="http://www.automated-trading-system.com/wp-content/uploads/2010/01/ResultsScatterPlot_P0-150x150.png" alt="Heat map for stepped parameter" title="ResultsScatterPlot_P0" width="150" height="150" class="size-thumbnail wp-image-1435" /></a><p class="wp-caption-text">Heat map for stepped parameter</p></div></p>
]]></content:encoded>
			<wfw:commentRss>http://www.automated-trading-system.com/trading-blox-teaser-review/feed/</wfw:commentRss>
		<slash:comments>49</slash:comments>
		</item>
	</channel>
</rss>

