<?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; walk-forward</title>
	<atom:link href="http://www.automated-trading-system.com/tag/walk-forward/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>R Code for Walk-Forward LSPM</title>
		<link>http://www.automated-trading-system.com/r-code-walk-forward-lspm/</link>
		<comments>http://www.automated-trading-system.com/r-code-walk-forward-lspm/#comments</comments>
		<pubDate>Thu, 23 Dec 2010 09:35:50 +0000</pubDate>
		<dc:creator>Jez Liberty</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[lspm]]></category>
		<category><![CDATA[R]]></category>
		<category><![CDATA[walk-forward]]></category>

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

<h3>In Closing</h3>
<p>Despite my very limited experience, I can really see some of the potential in using R for any sort of data manipulation.</p>
<p>If you want to get started in R and test this code, the following links will be useful:</p>
<p><a href="http://www.r-project.org/" target="_blank" rel="nofollow">R homepage</a>, which contains link to a download page. The installation is very simple and quick. Make sure you also check the docs as they are good.</p>
<p>The <a href="http://r-forge.r-project.org/projects/lspm/" target="_blank" rel="nofollow">R LSPM package</a> maintained by Josh Ulrich, the real meat of the code above &#8211; credits to him for making this!</p>
<p>The <a href="http://www.automated-trading-system.com/wp-content/uploads/2010/12/test2.r" target="_blank" rel="nofollow">R code</a> included in the post above</p>
<p>And a <a href="http://www.automated-trading-system.com/wp-content/uploads/2010/12/R.bat" target="_blank" rel="nofollow">batch file</a> to run the above code from a command prompt.</p>
<p>Finally, if you want to re-run the same test, here are the return files that were used in the code above:<br />
<a href='http://www.automated-trading-system.com/wp-content/uploads/2010/12/ReturnDataFiles.zip'>Return Data Files (zipped)</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.automated-trading-system.com/r-code-walk-forward-lspm/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>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>Intricacies of Market and Trend Following Changes</title>
		<link>http://www.automated-trading-system.com/intricacies-of-market-and-trend-following-changes/</link>
		<comments>http://www.automated-trading-system.com/intricacies-of-market-and-trend-following-changes/#comments</comments>
		<pubDate>Wed, 10 Mar 2010 11:10:49 +0000</pubDate>
		<dc:creator>Jez Liberty</dc:creator>
				<category><![CDATA[Strategies]]></category>
		<category><![CDATA[autocorrelation]]></category>
		<category><![CDATA[distribution]]></category>
		<category><![CDATA[kurtosis]]></category>
		<category><![CDATA[michael covel]]></category>
		<category><![CDATA[niederhoffer]]></category>
		<category><![CDATA[Turtle]]></category>
		<category><![CDATA[walk-forward]]></category>

		<guid isPermaLink="false">http://www.automated-trading-system.com/?p=1880</guid>
		<description><![CDATA[In the last post we looked at the Turtle Trading system and saw that its performance went from outstanding for a long period of time to flat for 20 years. This opens a can of worms: Does Trend Following work, is it dead, do markets change, does trend following rules need to adapt to these [...]]]></description>
			<content:encoded><![CDATA[<div id="attachment_1887" class="wp-caption aligncenter" style="width: 310px"><img src="http://www.automated-trading-system.com/wp-content/uploads/2010/03/nebulous-look1.jpg" alt="nebulous intricacies" title="nebulous look" width="300" height="215" class="size-full wp-image-1887" /><p class="wp-caption-text">nebulous intricacies</p></div>
<p>In the last post we looked at the <a href="http://www.automated-trading-system.com/turtles-just-lucky/">Turtle Trading system</a> and saw that its performance went from outstanding for a long period of time to flat for 20 years. This opens a can of worms:</p>
<p><em>Does Trend Following work, is it dead, do markets change, does trend following rules need to adapt to these changes?</em></p>
<p>Let&#8217;s look at the different points of view.<span id="more-1880"></span></p>
<h3>The EMH Crowd</h3>
<p>The EMH crowd does not believe in anything else than the <em>Random Walk</em> and by definition discards any profit-generating mechanical strategy.</p>
<p>As much as the <strong>Efficient Market Hypothesis</strong> (EMH) is a cornerstone of most modern financial theory, it has proven to be wrong partly because of some of its assumptions (not all actors in the market are rational, market prices are not fully random and normally distributed, etc.).</p>
<p>One great book that discredits the EMH approach and their <em>descendant</em> theories (CAPM, etc.) is by <strong>Mandelbrot</strong>: <a href="http://www.amazon.com/exec/obidos/ASIN/0465043577/autotradblog-20" target="_blank" rel="nofollow">The (mis)behavior of the markets</a>. It lays the arguments against the EMH in an approachable (ie not too much maths) way.</p>
<h3>Trend Following is dead/does not work</h3>
<p>Curtis Faith declared that &#8220;every few years trend following traders experience a period of losses and inevitably some expert will announce the end of trend following.&#8221;</p>
<p>Mike Covel also has a similar quote in his <a href="http://www.amazon.com/exec/obidos/ASIN/013702018X/autotradblog-20" target="_blank" rel="nofollow">Trend Following</a> book: &#8220;every 5 years some famous trader blows up and everyone declares <strong>trend following to be dead</strong>. Then 5 years later some famous trader blows up and everyone declares trend following to be dead, etc. &#8221;</p>
<p>One of the main proponents of the argument against Trend Following is infamous trader <strong>Vic Niederhoffer</strong> (who &#8220;blew up&#8221; twice). He has been highly vocal about it, declaring Trend Following as one of the <a href="http://www.dailyspeculations.com/vic/goodboy_interview.html" target="_blank" rel="nofollow">top Stock Market con</a>.<br />
Here is <a href="http://www.dailyspeculations.com/wordpress/?p=830" target="_blank" rel="nofollow">another link</a> from his website to read more about it.</p>
<p>Arguments like this, despite the empirical evidence against it &#8211; in the form of Trend Following Wizards success, can be taken as a motivation for healthy skepticism and push you to strengthen your statistical research.</p>
<h3>Are markets changing? (and must Trend Following change too?)</h3>
<p>The self-professed &#8220;Trend Following poster boy&#8221; (a.k.a. Michael Covel) authoratively declares that this is a <a href="http://www.michaelcovel.com/2009/10/13/the-ever-changing-markets-argument/" target="_blank" rel="nofollow">specious argument</a>.</p>
<blockquote><p>Occasionally, someone trying to promote something or start a debate will argue that trend following rules must always change due to changing market conditions. This is nonsense. It is a specious argument.</p></blockquote>
<p>This is at best ambiguous. Covel likes to cite Bill Dunn who:</p>
<blockquote><p>proffered that his basic system rules have not changed since 1974</p></blockquote>
<p>Now, that is seducing: it seems to sell you the idea that you can develop a system, implement it and trade it for life. However this is not strictly true. As mentioned in <a href="http://www.streetstories.com/dunn_art_futures.html" target="_blank" rel="nofollow">this interview</a>:</p>
<blockquote><p>Dunn annually adjusts the parameters of trading signals and each markets weighting. In February &#8211; just as the grains were about to take off &#8211; he dumped the entire grain sector. But Dunn has no regrets.</p></blockquote>
<p>Dunn is also known to have collaborated with Robert Pardo, a strong proponent of Walk-Forward testing (see below: a constant system adjustment).</p>
<p>To clarify: although Trend Following principles will never change, the rules/parameters of a Trend Following system might need to be adjusted to changing market conditions.</p>
<h3>How can a Trend Following strategy adapt to the ever-changing markets?</h3>
<p>In an <a href="http://www.activetradermag.com/index.php/c/Trading_Strategies/d/Tuning_up_the_turtle" target="_blank" rel="nofollow">Active Trader article</a>, Anthony Garner attempts to discuss:</p>
<blockquote><p>Do markets change? Is it necessary to undertake continued research and development and adapt a trend-following system to maintain its profitability over the years?</p></blockquote>
<p>The article is only available for the magazine subscribers, but the result of the equity curve can be found on the <a href="http://www.tradingblox.com/forum/viewtopic.php?t=7301" target="_blank" rel="nofollow">Trading Blox forum</a>. By &#8220;tuning up&#8221; the Turtle system, Garner manages to obtain interesting stats (MAR=2.26, CAGR=35.28%). The main change to the system is the use of a longer-term timeframe.</p>
<p><a href="http://www.tradingblox.com/forum/viewtopic.php?t=7301" target="_blank" rel="nofollow"><img src="http://www.automated-trading-system.com/wp-content/uploads/2010/03/tunedturtle_139.png" alt="tunedturtle_139" title="tunedturtle_139" width="166" height="125" class="alignnone size-full wp-image-1884" /></a></p>
<h3>Practically</h3>
<p>I know I would not be happy trading the original Turtle System in the last 20 years and get a 0% return. If you started trading this system &#8220;back then&#8221;, when and how would you think it is time to switch to a revised system?</p>
<p>Let&#8217;s look at options:</p>
<h4>1. Walk-Forward</h4>
<p><a href="http://www.automated-trading-system.com/walk-forward-testing/">Walk-Forward testing</a>&#8216;s principle is to keep running (in simulation) a &#8220;pool&#8221; of systems using different rules/parameters. At regular interval, you evaluate what systems are best (performance, robustness, etc.) and trade those until the next re-evaluation. The potential risk with this approach is that you might end up like a dog <em>chasing your tail</em>.</p>
<p>However, this approach would have you switched from the original Turtle system to the new one a while ago.</p>
<h4>2. Alternative Walk-Forward</h4>
<p>Markets exhibit some degree of inefficiency &#8211; and Trend Following is a strategy designed to profit from these inefficiencies. I am still refining my theoritical understanding and explanation of it, but I believe Trend Following&#8217;s performance is mostly the result of <a href="http://www.automated-trading-system.com/why-trend-following-works-look-at-the-distribution/">fat-tailed distributions</a> (distribution kurtosis) and possibly <a href="http://www.automated-trading-system.com/why-trend-following-works-autocorrelation/">autocorrelation</a>.</p>
<p>If one can associate the evolution of these characteristics to the performance of Trend Following systems it might be possible to adapt the system rules/parameters to the values and evolution of the price distribution characteristics. This is a topic I&#8217;d like to investigate further.</p>
<h4>3. Mixing Systems</h4>
<p>Finally, and this seems to be a strategy adopted by many professionals: mix different systems and different timeframes. Here the rationale is that we cannot predict what systems are going to under/over perform and mixing several ones together will smooth out the equity curve.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.automated-trading-system.com/intricacies-of-market-and-trend-following-changes/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>How can Walk-Forward testing keep your system a step ahead?</title>
		<link>http://www.automated-trading-system.com/walk-forward-testing/</link>
		<comments>http://www.automated-trading-system.com/walk-forward-testing/#comments</comments>
		<pubDate>Thu, 05 Nov 2009 13:08:41 +0000</pubDate>
		<dc:creator>Jez Liberty</dc:creator>
				<category><![CDATA[Backtest]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[optimisation]]></category>
		<category><![CDATA[tradersstudio]]></category>
		<category><![CDATA[walk-forward]]></category>

		<guid isPermaLink="false">http://www.automated-trading-system.com/?p=671</guid>
		<description><![CDATA[Out-of-Sample testing is a necessary practice to avoid curve-fitting during the optimisation of a trading system. Walk-Forward testing improves on the idea of out-of-sample data testing and is designed as an on-going, adaptive approach. Its invention is mostly credited to Robert Pardo (read more about it in his book) The way it works is fairly [...]]]></description>
			<content:encoded><![CDATA[<p>Out-of-Sample testing is a necessary practice to avoid curve-fitting during the optimisation of a trading system. Walk-Forward testing improves on the idea of out-of-sample data testing and is designed as an on-going, adaptive approach. Its invention is mostly credited to Robert Pardo (read more about it in <a href="http://www.amazon.com/exec/obidos/ASIN/0470128011/autotradblog-20" target="_blank" rel="nofollow">his book</a>)</p>
<p>The way it works is fairly simple. It is a combination of multiple cycles of &#8220;in-sample optimisation&#8221; with &#8220;out-of-sample verification&#8221;.</p>
<h3>Background on optimisation and out-of-sample testing</h3>
<p>The reason for performing out-of sample verification tests is to <span id="more-671"></span>check whether the in-sample data optimisation resulted in curve-fitting (over-optimisation) or in a robust system parameters selection.</p>
<p>If the parameters derived from optimisation perform much worse in the out-of-sample verification test, it most likely means that the parameter values were (over-) optimised for the specific in-sample dataset (curve-fitted). If the system performs similarly, it should mean that the system parameters are robust and validate the approach taken for optimisation.</p>
<h3>Walk-Forward Process: how it works</h3>
<p>Walk-Forward testing is an <em>on-going and dynamic process</em> to determine whether parameters optimisation just curve fits the price and noise or produces statistically valid out-of-sample results. Here is how it works:</p>
<p>Let&#8217;s say we have 10 years of data from 1999 to 2009. Optimisation period is three years (in-sample data) and Verification period is one year (out-of-sample data). To begin, you start by optimising your system using only the first three years of data &#8211; in this example, 1999-2001. When the system is optimised, record the optimal parameter values and use them in the test with new data (out-of-sample) starting with 2002.</p>
<div id="attachment_672" class="wp-caption aligncenter" style="width: 471px"><img src="http://www.automated-trading-system.com/wp-content/uploads/2009/10/Walk-Forward.gif" alt="Walk Forward from 1999 to 2009" title="Walk Forward" width="461" height="360" class="size-full wp-image-672" /><p class="wp-caption-text">Walk Forward from 1999 to 2009</p></div>
<p>Slide the three-year window of data forward (2000-2002) and perform the same process. Once you have processed all the data available, you can collate the performance of all out-of-sample tests and compare those to in-sample optimisation runs. If the comparison shows that the system is sufficiently robust to be traded live, you simply continue the walk-forward process in real time by re-optimising every year.</p>
<h3>In Closing</h3>
<p>Walk-Forward is an adaptive process which re-optimises the system on a continuous basis to adapt its parameters to the most recent market conditions.</p>
<p>The premise of performing several optimisation/verification steps over time is that the recent past is a better environment for selecting system parameters than the distant past. This is an assumption you need to consider when choosing whether to use Walk-Forward testing or not but this is a useful tool in your Systems development arsenal.</p>
<p>As discussed <a href="http://www.automated-trading-system.com/trading-chameleon/">earlier</a> changing system parameters based on recent market conditions could result in a system chasing its tail. The next post on this topic will be an actual comparison of a basic system’s performance when optimised in a &#8220;standard way&#8221; and when optimised using &#8220;Walk-Forward&#8221;.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.automated-trading-system.com/walk-forward-testing/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
		<item>
		<title>Should you be trading a chameleon?</title>
		<link>http://www.automated-trading-system.com/trading-chameleon/</link>
		<comments>http://www.automated-trading-system.com/trading-chameleon/#comments</comments>
		<pubDate>Tue, 03 Nov 2009 11:10:49 +0000</pubDate>
		<dc:creator>Jez Liberty</dc:creator>
				<category><![CDATA[Backtest]]></category>
		<category><![CDATA[Strategies]]></category>
		<category><![CDATA[Bill Dunn]]></category>
		<category><![CDATA[chameleon]]></category>
		<category><![CDATA[walk-forward]]></category>

		<guid isPermaLink="false">http://www.automated-trading-system.com/?p=646</guid>
		<description><![CDATA[Thanks to marfis75 for Mr. DJ Chameleon There are 2 approaches to systems parameters: Decide on a set of parameters for the strategy and stick to it Keep changing the system parameters based on the latest market conditions (chameleon approach) The chameleon method will inherently be lagging and, as a result, might not give you [...]]]></description>
			<content:encoded><![CDATA[<div id="attachment_658" class="wp-caption aligncenter" style="width: 460px"><img src="http://www.automated-trading-system.com/wp-content/uploads/2009/10/chameleon3.jpg" alt="DJ chameleon" title="DJ chameleon" width="450" height="272" class="size-full wp-image-658" />
<p class="wp-caption-text">Thanks to <a href="http://www.flickr.com/photos/marfis75/" target="_blank" rel="nofollow">marfis75</a> for Mr. DJ Chameleon</p>
</div>
<p>There are 2 approaches to systems parameters:</p>
<ul>
<li>Decide on a set of parameters for the strategy and stick to it</li>
<li>Keep changing the system parameters based on the latest market conditions (chameleon approach)</li>
</ul>
<p>The chameleon method will inherently be lagging and, as a result, might not give you very good results. Think about being stuck in a traffic jam on the highway: you always think the queue next to you is faster &#8211; but it seems that every time you change lanes, the one you just left picks up speed… and you end up being stuck even longer!</p>
<p>In terms of automated trading, you might end up with <span id="more-646"></span>a system that chases its tail (instead of <a href="http://www.automated-trading-system.com/why-trend-following-works-look-at-the-distribution/">chasing the <em>fat-tail</em></a>). Of course there are &#8220;different shades of grey&#8221; and some parts of the system can be self-adapting (volatility-adjusted indicators for example) and allow for a middle ground approach. Consider the Turtle Rules as an example: they used to have static parameters (i.e. 20 and 55 days breakouts) but used ATR as a central part of their strategy to adapt to different volatility levels.</p>
<p>The concept of chasing its tail can also be illustrated by <a href="http://www.streetstories.com/dunn_art_futures.html" target="_blank" rel="nofollow">this story</a> about Bill Dunn:</p>
<blockquote><p>The World Monetary program currently trades 13 markets. Back testing 10 to 12 years (each year has equal weighting), Dunn annually adjusts the parameters of trading signals and each market’s weighting. In February &#8211; just as the grains were about to take off &#8211; he dumped the entire grain sector.</p></blockquote>
<p>Performance will depend on how fast the chameleon can adapt and be responsive while keeping a robust approach. We will try to find out&#8230;<br />
In a next post, we will cover Walk-Forward testing (which uses a sliding look-back period for back-test and applies the optimal parameters to the latest trading period). It can be associated with a chameleon approach. We will also run a comparison test between the 2 approaches and see how the chameleon performs!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.automated-trading-system.com/trading-chameleon/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

