<?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; optimisation</title>
	<atom:link href="http://www.automated-trading-system.com/tag/optimisation/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>Vince&#8217;s Leverage Space Model: better than MPT?</title>
		<link>http://www.automated-trading-system.com/vince-leverage-space-model/</link>
		<comments>http://www.automated-trading-system.com/vince-leverage-space-model/#comments</comments>
		<pubDate>Mon, 22 Mar 2010 12:11:23 +0000</pubDate>
		<dc:creator>Jez Liberty</dc:creator>
				<category><![CDATA[Backtest]]></category>
		<category><![CDATA[Money Management]]></category>
		<category><![CDATA[distribution]]></category>
		<category><![CDATA[leverage space model]]></category>
		<category><![CDATA[optimal f]]></category>
		<category><![CDATA[optimisation]]></category>
		<category><![CDATA[ralph vince]]></category>
		<category><![CDATA[research paper]]></category>

		<guid isPermaLink="false">http://www.automated-trading-system.com/?p=1946</guid>
		<description><![CDATA[Ralph Vince&#8216;s book Handbook of Portfolio Mathematics has been shamefully lying untouched on my desk for a few months&#8230; I started reading it but never finished it. I recently found a 30-page paper introducing the ideas and principles of his Leverage Space Model. I thought reading it might be a good way to get back [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Ralph Vince</strong>&#8216;s book <a href="http://www.automated-trading-system.com/Handbook-Portfolio-Mathematics-Vince" target="_blank" rel="nofollow">Handbook of Portfolio Mathematics</a> has been shamefully lying untouched on my desk for a few months&#8230; I started reading it but never finished it.</p>
<p>I recently found a 30-page paper introducing the ideas and principles of his <strong>Leverage Space Model</strong>. I thought reading it might be a good way to get back into Vince&#8217;s material.</p>
<p>Follows a summary of the paper (<a href='http://www.automated-trading-system.com/wp-content/uploads/2010/03/Vince-LeverageSpaceModel.pdf'>PDF download link</a>), which is maths-less (only concepts and principles are discussed). It is a good introduction to Ralph Vince theories.<span id="more-1946"></span></p>
<h3>Vince&#8217;s Optimal f</h3>
<p>This is what Vince is famous for. It is basically a way to determine trading quantity (aka leverage) using the probability distributions of the trade outcomes.</p>
<p>If <em>f</em> represents the fraction of capital to wager (risk) on each bet (trade), the optimal value is the one which optimises the geometric growth of the bankroll (account balance).</p>
<p>In his previous books, Vince has defined the formula to determine the optimal f. The first part of the paper discusses the <strong>optimal f</strong> concept and is a good introduction for the non-initiated (showing how over-betting on a game with positive expectancy can and will result in a loss).</p>
<h3>Leverage Space Model promises</h3>
<p>The optimal f section discusses a single-component approach whereas the Leverage Space Model deals with <strong>multiple components portfolio</strong>.</p>
<p>It is presented as an improvement on the <em>Modern Portfolio Theory</em>, briefly discussed. This is based on the following advantages:</p>
<blockquote><ol>
<li>Risk is defined as drawdown (instead of variance in the MPT)</li>
<li>The fallacy and danger of correlation is eliminated</li>
<li>Valid for any distributional form &#8211; Fat-tails are addressed</li>
<li>The model is all about Leverage, which is not addressed in the MPT model.</li>
</ol>
</blockquote>
<h3>Return aspect</h3>
<p>The model starts by building a <strong>multi-dimensional terrain</strong>, drawing the overall expected return, based on multiple combinations of components in the portfolio and their respective <em>f</em>-values.</p>
<div id="attachment_1951" class="wp-caption alignnone" style="width: 260px"><img src="http://www.automated-trading-system.com/wp-content/uploads/2010/03/Full-Return-LSM.png" alt="In this example the model builds the terrain for 2 simultaneous coin-toss with a payoff of 2:1" title="Full-Return-LSM" width="250" height="198" class="size-full wp-image-1951" /><p class="wp-caption-text">In this example the model builds the terrain for 2 simultaneous coin-toss with a payoff of 2:1. The x and y axis represent the respective f-values (leverage) for each of the bets/trades - while the z-axis (vertical) represents the expected return</p></div>
<p>The maximum portfolio growth is located at the peak of the terrain, resulting from the specific corresponding <em>f</em>-values combination. The terrain construction <strong>does not take into account correlation</strong> between the instruments &#8211; instead, the model uses the joint probability of two scenarios occurring simultaneously, dictated by the price data history.</p>
<h3>The Risk Aspect</h3>
<p>So far, the model has only looked at returns. To introduce the risk component, you must determine your <strong>maximum allowed drawdown</strong>. This is a hard and fast rule: no combination should breach that limit.</p>
<p>Using a derivation of the <em>risk of ruin</em>, the model computes the risk of maximum drawdown for each set of <em>f</em>-values (for a specific timeline &#8211; as, in the long run, the risk of drawdown tends to 100%). If the <em>risk of drawdown</em> is too high, the specific <em>f</em>-values combination is ignored.</p>
<p>In practice, <strong>the initial terrain is truncated</strong>: by removing all points breaching the maximum drawdown threshold.</p>
<div id="attachment_1952" class="wp-caption alignnone" style="width: 261px"><img src="http://www.automated-trading-system.com/wp-content/uploads/2010/03/Truncated-Return-LSM.png" alt="The terrain has been truncated: all areas deemed too risky, from a drawdown perspective, have been removed." title="Truncated-Return-LSM" width="251" height="197" class="size-full wp-image-1952" /><p class="wp-caption-text">The terrain has been truncated: all areas deemed too risky, from a drawdown perspective, have been removed.</p></div>
<h3>The Algorithm</h3>
<p>Vince implements a <em>genetic algorithm</em> to calculate the terrain, by initially calculating the <em>expected return</em> for each set of <em>f</em>-values, and secondly by running the maximum drawdown test on this same set. Once the whole set combination has been run through, the terrain is built (including truncations). The the aim is then to find the optimal set (highest return with lowest <em>f</em>-values).</p>
<h3>Comments and Extra Info</h3>
<p>The paper is rather short and does not deal with any of the maths behind the models. For this you&#8217;d have to get yourself a copy of <a href="http://www.automated-trading-system.com/Handbook-Portfolio-Mathematics-Vince" target="_blank" rel="nofollow">the Handbook of Portfolio Mathematics</a> which introduces the model in more detail or Vince&#8217;s <a href="http://www.amazon.com/exec/obidos/ASIN/0470455950/autotradblog-20" target="_blank" rel="nofollow">latest book</a>, dedicated to the Leverage Space Model, which has had a not-so-positive <a href="http://www.maxdama.com/?p=156" target="_blank">review by Max Dama</a>.</p>
<p>The ideas in the paper are an interesting take on position sizing. Vince uses a simple objective/bliss function (CAGR with a binary risk/drawdown filter) to evaluate all possible scenarios of portfolio allocation/leverage. It might be interesting to use the concepts of the model with your own <a href="http://www.automated-trading-system.com/bliss-recipe-robustness-spice/">bliss function recipe</a>.</p>
<p>One of Vince&#8217;s claim that the MPT does not address leverage sounds a bit simplistic &#8211; surely the percentage of Cash as an asset in the portfolio is an implicit measure of leverage. On the other hand, the approach on correlation/joint probability of scenarios sounds interesting and seems to go in the right direction. As Vince says:</p>
<blockquote><p>Counting on correlation fails you when you need it the most.</p></blockquote>
<p>Another point that seems missed out is how the model handles non-stationarity of the market. Vince mentions the <em>chronomorphism</em> of market prices distributions (i.e. they change with time) and even draws a betting comparison with blackjack &#8211; in which the optimal f curve changes for each card dealt. However there is no mention of how the model takes an adaptive approach to these <em>chronomorphic</em> distributions.</p>
<p><a href="http://parametricplanet.com/rvince/" target="_blank">Vince&#8217;s homepage</a> contains a link to the java software that implements his model  (needs to register/leave email to download) and another one with a spreadsheet example. I have not had time to take a serious look at all those. Please let me know your feedback if you do.</p>
<p>Joshua Ulrich &#8211; blogger and reader of this blog (hello there: finally got round to adding you to the blogroll!) &#8211; is collaborating with Ralph Vince to port the Leverage Space Model to the R platform. His <a href="http://blog.fosstrading.com/search/label/LSPM" target="_blank">FOSS Trading</a> blog is definitely worth a read too.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.automated-trading-system.com/vince-leverage-space-model/feed/</wfw:commentRss>
		<slash:comments>29</slash:comments>
		</item>
		<item>
		<title>Were the Turtles just lucky?&#8230;</title>
		<link>http://www.automated-trading-system.com/turtles-just-lucky/</link>
		<comments>http://www.automated-trading-system.com/turtles-just-lucky/#comments</comments>
		<pubDate>Mon, 08 Mar 2010 10:35:08 +0000</pubDate>
		<dc:creator>Jez Liberty</dc:creator>
				<category><![CDATA[Strategies]]></category>
		<category><![CDATA[Trend Following]]></category>
		<category><![CDATA[eckhardt]]></category>
		<category><![CDATA[optimisation]]></category>
		<category><![CDATA[Richard Dennis]]></category>
		<category><![CDATA[Turtle]]></category>

		<guid isPermaLink="false">http://www.automated-trading-system.com/?p=1798</guid>
		<description><![CDATA[&#160; Most people will have heard of the mythical Turle Traders, a group of novice traders set up and mentored by legendary &#8220;Prince of the Pit&#8221; Richard Dennis. Dennis did so to set up an old argument with fellow trader Bill Eckhardt on whether trading could be taught or not (not unlike the story in [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.automated-trading-system.com/wp-content/uploads/2010/02/turtle-trader-dennis-eckhardt-pandiyan.png" alt="turtle-trader-dennis-eckhardt-pandiyan" title="turtle-trader-dennis-eckhardt-pandiyan" width="400" height="295" class="alignnone size-full wp-image-1800" /><br />
&nbsp;<br />
Most people will have heard of the mythical <strong>Turle Traders</strong>, a group of novice traders set up and mentored by legendary &#8220;Prince of the Pit&#8221; <a href="http://en.wikipedia.org/wiki/Richard_Dennis" target="_blank" rel="nofollow">Richard Dennis</a>.</p>
<p>Dennis did so to set up an old argument with fellow trader <a href="http://en.wikipedia.org/wiki/William_Eckhardt_(trader)" target="_blank" rel="nofollow">Bill Eckhardt</a> on whether <strong>trading could be taught or not</strong> (not unlike the story in classic movie <a href="http://www.imdb.com/title/tt0086465/" target="_blank" rel="nofollow">Trading Places</a>).</p>
<p>The experience was succesful in proving Dennis right (trading <em>could</em> be taught), with his turtle traders making him $100 million.</p>
<h3>Why turtles?</h3>
<p>The Turtles were nicknamed as such because<span id="more-1798"></span> of an analogy with how Richard Dennis expected to &#8220;grow&#8221; traders in the same way <strong>Singapore farms grow turtles</strong>. Dennis taught his students a mechanical Trend Following system and let them trade with his own capital. After being kept secret for more than a decade, the rules were revealed and floated on the internet for a while. Two enjoyable books have now been published on the topic (<a href="http://www.automated-trading-system.com/turtle-trader-covel" target="_blank" rel="nofollow">Complete Turtle Trader</a> &#8211; featuring the actual turtle rules and <a href="http://www.automated-trading-system.com/way-turtle-faith" target="_blank" rel="nofollow">The Way of the Turtle</a> written by Curtis Faith, a former Turtle) if you are interested in learning more about it.</p>
<h3>The turtle system</h3>
<p>The Turtle system did not contain &#8220;magical&#8221; components. It was basically a combination of 2 different breakout systems with specific rules for money management, including position sizing, pyramiding, correlation limits and cutting down position size during drawdowns (a quick &#8220;Turtle trading rules&#8221; google search should yield some results for the exact rules).</p>
<h3>System kaput?</h3>
<p>Now that the rules have been made public, it is possible to backtest them and see how they would have performed on the recent markets. Such test result can be found on the <a href="http://www.tradingblox.com/forum/viewtopic.php?p=35018#35018" target="_blank" rel="nofollow">Trading Blox forum</a>.</p>
<div id="attachment_1875" class="wp-caption alignnone" style="width: 176px"><a href="http://www.tradingblox.com/forum/viewtopic.php?p=35018#35018" target="_blank" rel="nofollow"><img src="http://www.automated-trading-system.com/wp-content/uploads/2010/03/since_1970_350.png" alt="click to zoom in" title="turtles_since_1970_350" width="166" height="100" class="size-full wp-image-1875" /></a><p class="wp-caption-text">click to zoom in</p></div>
<p>It basically shows that the CAGR drops from 216% (!!) from 1970 to 1986 (when Dennis and Eckhardt were developing the system, and also when the students traded the system with real money) to barely double digits (10.5%) in the last 23 years (1986 to 2009), with a completely <strong>flat period from 1996 to 2009</strong>.</p>
<p>As a side note check the crazy amount that compounding generates at that rate of 216%!</p>
<p>One could argue that Dennis &#038; co were just lucky to trade the system during what appears to be its golden period.</p>
<h3>System overheating warning</h3>
<p>During the Turtle experiment, Dennis came to the realisation that their position sizing rules were such that:</p>
<blockquote><p>you have been trading as much as twice as big as we thought</p></blockquote>
<p>Here is a snapshot of the <a href="http://www.trendfollowing.com/whitepaper/memo.pdf" target="_blank" rel="nofollow">memo</a> that Dennis sent to all traders asking them to cut their position size in half.<br />
<img src="http://www.automated-trading-system.com/wp-content/uploads/2010/02/Dennis-Memo.jpg" alt="Dennis-Memo" title="Dennis-Memo" width="484" height="477" class="alignnone size-full wp-image-1799" /><br />
As Dennis said:</p>
<blockquote><p>We must be living right</p></blockquote>
<p>Another way of saying &#8220;We have been very lucky&#8221;?&#8230;</p>
<h3>What does this mean?</h3>
<p>Well, some say that the Turtle performance was a fluke &#8211; that the Turtles were actually the proverbial monkeys writing Hamlet (see the <a href="http://en.wikipedia.org/wiki/Infinite_monkey_theorem" target="_blank" rel="nofollow">Infinite Monkey Theorem</a>). I guess these people would be in the EMH camp (Efficient Market Hypothesis).</p>
<p>Some say that Trend Following is dying/dead and the Turtle system under-performance is an illustration of that. Problem is: these people seem to celebrate the demise of &#8220;simpleton&#8221; Trend Following strategy every so often (during major drawdown peiods), only for Trend Following to come back roaring again (think 2008).</p>
<p>Some might also say that market conditions are changing, and systems need to adapt to these changing conditions.</p>
<p>Although, some also say that this argument is specious, citing Bill Dunn as an example of a CTA claiming to use the same rules as when he started in the 70&#8242;s.</p>
<h3>Reconciling it all</h3>
<p>Instead of concluding this post quickly here &#8211; on what it does or does not means &#8211; I thought it might be more interesting to expand and spend more time on the possible interpretations above in a post of its own. Part 2 will take this discussion further.</p>
<p>Stay tuned,  I will try to touch on whether or not Trend Following should, and can, adapt to changing market conditions &#8211; update: <a href="http://www.automated-trading-system.com/intricacies-of-market-and-trend-following-changes/">post here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.automated-trading-system.com/turtles-just-lucky/feed/</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
		<item>
		<title>Bliss recipe with a robustness spice</title>
		<link>http://www.automated-trading-system.com/bliss-recipe-robustness-spice/</link>
		<comments>http://www.automated-trading-system.com/bliss-recipe-robustness-spice/#comments</comments>
		<pubDate>Thu, 04 Feb 2010 10:58:29 +0000</pubDate>
		<dc:creator>Jez Liberty</dc:creator>
				<category><![CDATA[Backtest]]></category>
		<category><![CDATA[bliss function]]></category>
		<category><![CDATA[optimisation]]></category>
		<category><![CDATA[robust]]></category>

		<guid isPermaLink="false">http://www.automated-trading-system.com/?p=1489</guid>
		<description><![CDATA[This post is trying to present a process to determine your bliss function, as a follow-up to the previous post introducing the bliss function concept. We&#8217;ve seen that the bliss function is not a universal function but needs to encapsulate your own criteria for evaluating a trading system. Similarly to popular dishes, everybody has got [...]]]></description>
			<content:encoded><![CDATA[<p>This post is trying to present a process to determine your bliss function, as a follow-up to the <a href="http://www.automated-trading-system.com/bliss-function-quantify-trading-system-objective/">previous post introducing the bliss function concept</a>.<br />
<div id="attachment_1495" class="wp-caption alignleft" style="width: 260px"><img src="http://www.automated-trading-system.com/wp-content/uploads/2010/02/MasterChef.png" alt="Master Chef Paul Fraser - photo: Peter-Duke@flickr" title="MasterChef" width="250" height="310" class="size-full wp-image-1495" /><p class="wp-caption-text">Master Chef Paul Fraser - photo: Peter-Duke@flickr</p></div>We&#8217;ve seen that the bliss function is not a universal function but needs to encapsulate <em>your own</em> criteria for evaluating a trading system. Similarly to popular dishes, everybody has got their own recipe based on their personal preferences.<br />
&nbsp;</p>
<p>Well, &#8220;building&#8221; your bliss function is a bit like making up your own recipe: you first have to choose the main ingredients (return, variance, risk, etc.) and mix them in a way that makes sense and in the right proportions. Most great chefs perfect their recipes through <em>trial and error</em>. The process can equally be applied to the bliss function.<br />
&nbsp;<br />
Please note that my bliss function recipe is not finished. I am merely floating the idea of how I am planning to establish my <em> bliss equation</em>. Please feel free to comment if you have any comments on super ingredients you know about: at the Au.Tra.Sy restaurant, everybody can help in the cuisine!</p>
<h3>Main ingredients and proportions</h3>
<p>First, you have to decide what will be in your recipe. The base ingredients will probably be return, variance and risk. These can be declined in several flavours which you must choose. In the <a href="http://www.automated-trading-system.com/bliss-function-quantify-trading-system-objective/">previous bliss function post</a>, we looked at the following comparison of 2 different systems:<span id="more-1489"></span></p>
<div id="attachment_1307" class="wp-caption alignnone" style="width: 356px"><img src="http://www.automated-trading-system.com/wp-content/uploads/2010/01/SyssX-SysY.png" alt="test caption" title="SyssX-SysY" width="346" height="209" class="size-full wp-image-1307" /><p class="wp-caption-text">MAR = CAGR / MaxDD (MaxDD = worst drawdown)</p></div>
<p>This led us to conclude that neither CAGR nor MAR were a good performance and variance measure on their own. From that observation came the idea of using:</p>
<p><code>ln(CAGR + 1) x MAR</code></p>
<p>We then added some more ingredients to complete the recipe such as:</p>
<p><code>Bliss = ln(CAGR + 1) x MAR - 0.5 x ME - 0.1 x TimeInMkt%</code></p>
<p>This would be our base recipe. The process here is just to use common sense (based on your preferences) to build a tentative bliss function equation</p>
<h3>tinkering with ingredients and proportions</h3>
<p>This is the stage where great recipes are made!</p>
<p>If you set out to invent a dish, you&#8217;ll pick up the ingredients that you want to use and mix them with common sense (as we have done above). However, your first attempt will surely need some adjustments (that chocolate cake never turns perfect the first time!)</p>
<p>Test your equation on any system equity curve and stats that you can put your hands on. Use your back-testing software output, real-life fund performance reports, or just make them up: you just want some data to run your equation on.</p>
<p>You should have some ideas of which systems you prefer naturally. Your mission is simply to run the equation on all these systems and make sure that the bliss function ranks them as per your natural preferences. If it does not, you need to tinker with the recipe/equation.</p>
<p>What caused the divergence between the function output and your natural choice? How can you adjust the formula to rectify this? You&#8217;ll probably have to change some coefficients, add some smoothing functions, add a minor ingredient, add some extra logic, etc.</p>
<p>The downside: it is a long, on-going process, maybe a process that does not appear very scientific: but we are not trying to find a universal truth here &#8211; rather your own truth. And unless you can formulate it right off the bat, you have no alternative but <em>trial and error</em></p>
<h3>An extra ingredient: robustness</h3>
<p>That could be chef Jez Liberty&#8217;s signature ingredient &#8211; that makes people love or hate that recipe&#8230;</p>
<p>What we want to measure here is how the system is robust. We&#8217;ve seen that <a href="http://www.automated-trading-system.com/robustness-definitions/">there are multiple ways to define and measure robustness</a>. For this, let&#8217;s concentrate on robustness to slight parameter variation. The process would be three-fold (assuming you are already happy with one robustness-less bliss function equation):</p>
<ul>
<li>Run a backtest of your system with different parameter values</li>
<li>Calculate the bliss value for each of the sub-system/parameter value generated in your backtest</li>
<li>Establish a <em>robustness score</em> for each sub-system/parameter value based on the variance of its own bliss value compared to the bliss values of its neigbouring parameter values</li>
</ul>
<p>A picture will illustrate this more clearly. Imagine that the following is a chart of our bliss values (for each parameter value tested):<br />
<img src="http://www.automated-trading-system.com/wp-content/uploads/2010/02/robustness-parameters.png" alt="robustness-parameters" title="robustness-parameters" width="400" height="265" class="alignnone size-full wp-image-1491" /></p>
<p>The 16th parameter value produces the best bliss value, but its neighbouring values are pretty low: its robustness score would penalise it. On the other hand, parameter #11 seems fairly close to its four closest neighbours and it should get a positive score.</p>
<p>One robustness coefficient (Rob), calculated for each parameter value, could be:<br />
<code>Rob = sd(all) / sd(param,n_neigh)</code><br />
where:<br />
sd(param,neigh) would be the standard deviation of the bliss values across the parameter observed and its <em>n</em> neighbours (e.g. n=4 would consider a group of 5 bliss values)<br />
sd(all) would be the standard deviation across all parameters</p>
<p>The new <em>robust</em> bliss value would be adjusted by Rob such as:<br />
<code>Bliss<sub>new</sub> = Bliss<sub>old</sub> x Rob</code></p>
<p>Of course you would have to tinker with this Rob formula, possibly change the formula a fair bit. But this gives you a base to start working with and test against sample backtest results.</p>
<h3>one main problem</h3>
<p>That robustness measure is only good <em>intra-system</em>, for taking into account which parameter sets are more robust.</p>
<p>This does not allow to compare multiple systems from a robustness point of view. But for this, you just have to start the same <em>thought process</em> again: how do you want to measure robustness for a given system and compare it against another one?</p>
<p>A starting point might be to apply some variations to the trading systems, maybe a 10% variation on the parameter values, a bit of light price &#8220;scrambling&#8221; (i.e. update your price series by adding 0.1% to the close), etc. Measure the variance of the bliss values across these variations for different systems and update the bliss value by this <em>variance score</em>.</p>
<h3>the proof in the pudding?</h3>
<p>At the end of the day, the bliss function is trying to aggregate many aspects of a trading system (performance, variance, risk, robustness, etc.) into one single value. The concept is attractive but the recipe might fail to capture all the subtleties of the ingredients.</p>
<p>Imagine mixing together a <a href="http://www.mydish.co.uk/recipe/2225/Banana%20Banoffee%20Pie" target="_blank" rel="nofollow">banoffee pie</a> with <a href="http://users.skynet.be/RICHIUSO.SOSPEL/HTML/RICHIUSO301.htm#ratatouille" target="_blank" rel="nofollow">ratatouille nicoise</a>, an entrecote, some <a href="http://en.wikipedia.org/wiki/Maroilles_(cheese)" target="_blank" rel="nofollow">Maroilles cheese</a> and a Corn and Clam Chowder all rinsed down with some <a href="http://en.wikipedia.org/wiki/Kaoliang">Kaoliang</a>&#8230; An extreme comparison, you may say but you get the idea (ps: try some of these dishes &#8211; individually &#8211; they are very nice!)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.automated-trading-system.com/bliss-recipe-robustness-spice/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Bliss Function: Quantify your Trading System Objective</title>
		<link>http://www.automated-trading-system.com/bliss-function-quantify-trading-system-objective/</link>
		<comments>http://www.automated-trading-system.com/bliss-function-quantify-trading-system-objective/#comments</comments>
		<pubDate>Thu, 21 Jan 2010 12:20:30 +0000</pubDate>
		<dc:creator>Jez Liberty</dc:creator>
				<category><![CDATA[Backtest]]></category>
		<category><![CDATA[bliss function]]></category>
		<category><![CDATA[Ed Seykota]]></category>
		<category><![CDATA[optimisation]]></category>

		<guid isPermaLink="false">http://www.automated-trading-system.com/?p=1304</guid>
		<description><![CDATA[Backtesting mechanical trading systems involves a great deal of optimization: testing and running a system across a myriad of parameters to choose the one(s) that produce the best results. But what is &#8220;best&#8221;? How do you measure best results, though? Compound Annual Growth Rate (CAGR) is one of the first metric that comes to mind [...]]]></description>
			<content:encoded><![CDATA[<p>Backtesting mechanical trading systems involves a great deal of optimization: testing and running a system across a myriad of parameters to choose the one(s) that produce the <em>best results</em>.</p>
<h3>But what is &#8220;best&#8221;?</h3>
<p>How do you measure best results, though? Compound Annual Growth Rate (CAGR) is one of the first metric that comes to mind (it is the simplest and most direct one). However consider this:</p>
<p><img src="http://www.automated-trading-system.com/wp-content/uploads/2010/01/SysA-SysB.png" alt="SysA-SysB" title="SysA-SysB" width="344" height="270" class="aligncenter size-full wp-image-1306" /></p>
<p>System A produces a greater CAGR &#8211; at the cost of much larger variability in the results. I don&#8217;t know about you, but &#8220;to a point&#8221;, I would rather obtain a smoother equity curve and slightly worse CAGR (i.e. choosing System B).</p>
<p>This reasoning leads to <span id="more-1304"></span>a bunch of other metrics and ratio dealing another measure: the variance of the return (<a href="http://en.wikipedia.org/wiki/Sharpe_ratio" target="_blank" rel="nofollow">Sharpe ratio</a>, <a href="http://en.wikipedia.org/wiki/Sterling_ratio" target="_blank" rel="nofollow">Sterling ratio</a>, <a href="http://en.wikipedia.org/wiki/Sortino_ratio" target="_blank" rel="nofollow">Sortino ratio</a>, <a href="http://en.wikipedia.org/wiki/Treynor_ratio" target="_blank" rel="nofollow">Treynor ratio</a>, <a href="http://www.seykota.com/tribe/risk/index.htm" target="_blank" rel="nofollow">Lake ratio</a>, <a href="http://en.wikipedia.org/wiki/Calmar_ratio" target="_blank" rel="nofollow">Calmar and MAR ratios</a>, etc.).</p>
<h3>Introducing YOUR Bliss function</h3>
<p>In short, there are many ways to quantify how good a system is. One of the first step in the optimization process is to decide on the <strong>objective function</strong> &#8211; which will be used to measure and compare the performance of each system tested in the optimization run (the <em>Sharpe ratio</em> is one such objective function, widely used to compare fund managers).</p>
<p>Ed Seykota coined the term <strong>Bliss Function</strong>, which suits very aptly: the system that performs best on <em>your</em> set of criteria will give you the most blissful results (wealth increase, peace of mind).</p>
<p>Now consider this:</p>
<div id="attachment_1307" class="wp-caption aligncenter" style="width: 356px"><img src="http://www.automated-trading-system.com/wp-content/uploads/2010/01/SyssX-SysY.png" alt="test caption" title="SyssX-SysY" width="346" height="209" class="size-full wp-image-1307" /><p class="wp-caption-text">MAR = CAGR / MaxDD (MaxDD = worst drawdown)</p></div>
<p>System A is very consistent but its return is very unexciting. There might be a threshold where you are willing to accept more <del datetime="2010-01-21T11:59:07+00:00">risk </del>variance for more reward (i.e. choose to trade system B despite its lower return-to-variability ratio value, like the MAR chosen here). And this is the main point of building an  objective/bliss function:</p>
<p><strong>The bliss function should be <u>your own</u> &#8220;goodness measure&#8221; of a trading system, using your own formula and criteria.</strong> Choose a formula that will produce the best results/pick the best systems <strong>for you</strong>. And you get to be as original as you want!</p>
<p>For the case above, you might decide to complicate the formula of the <em>Bliss function</em> by adding an arbitrary <em>adjustment multiplying </em> function AM to penalise low-returns systems such as:</p>
<p><code>Bliss = AM(CAGR) x MAR</code></p>
<p>with:<br />
<code>AM(x<10%) = 0</code> (ignore any systems producing less than 10%)<br />
<code>AM(10%<=x<20%) = 0.5</code> (penalising low-returns systems)<br />
<code>AM(20%<=x<60%) = 1</code> (standard value)<br />
<code>AM(x>=60%) = 1.5</code> (rewarding high-returns systems)</p>
<p>A continuous function with the same impact would be the logarithmic function.</p>
<h3>Variance != Risk</h3>
<p>The shortcut taken by many is to equate <em>return variance</em> with <em>risk</em>. If that is the case, any of your preferred ratio above would be an elegant way to measure risk-adjusted returns.</p>
<p>However, risk and variance are two complete different animals (LTCM had an outstanding Sharpe ratio... until they <em>blew up</em>!)</p>
<p>So, how can you quantify <em>hidden risk</em>? Raw performance return does not allow you to identify it. It really depends on what <strong>you</strong> consider as <em>Risk</em>.</p>
<p>Hidden risk can be contained in all of these aspects of a strategy that expose you to "risk situations" (think <em>Black Swans</em>) even if they do not materialise.</p>
<p>Time in the Market might be relevant here: all things being equal, you might prefer a strategy in the market 30% of the time rather than 75% - less chance to be hit by this 6-sigma event).</p>
<p>Leverage has a direct influence on the quantitative impact of such event. You might want to introduce measures such as average margin-equity ratio (ME) into your Bliss formula.</p>
<p>Adding the 2 components with arbitrary coefficients the formula would become:</p>
<p><code>Bliss = ln(CAGR + 1) x MAR - 0.5 x ME - 0.1 x TimeInMkt%</code></p>
<h3>additional parameters</h3>
<p>So far, we have covered fairly standard metrics for trading systems. But you might want to add your own specific criteria.</p>
<p>One such criteria, which could be interesting to add, is some form of "robustness measure". This will be the subject of a follow-up post.</p>
<h3>In Closing</h3>
<p>Coming up with your own bliss function is basically mixing up the various metrics of your trading system (absolute performance, variance, risk and possibly other factors such as robustness) that matter to you. This post tries to highlight the concept and <em>thought process</em> rather than a complete or exact Bliss function.</p>
<p>To expand on the concept of the bliss function, concepts such as <a href="http://www.automated-trading-system.com/walk-forward-testing/">walk-forward testing</a> can leverage the bliss function and use it as the objective/selective function.</p>
<p>One can argue that there are as many bliss functions as there are traders. The difficulty lies in finding and formulating its formula...</p>
]]></content:encoded>
			<wfw:commentRss>http://www.automated-trading-system.com/bliss-function-quantify-trading-system-objective/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Robustness? What robustness?</title>
		<link>http://www.automated-trading-system.com/robustness-definitions/</link>
		<comments>http://www.automated-trading-system.com/robustness-definitions/#comments</comments>
		<pubDate>Thu, 17 Dec 2009 12:53:06 +0000</pubDate>
		<dc:creator>Jez Liberty</dc:creator>
				<category><![CDATA[Backtest]]></category>
		<category><![CDATA[eckhardt]]></category>
		<category><![CDATA[optimisation]]></category>
		<category><![CDATA[robust]]></category>

		<guid isPermaLink="false">http://www.automated-trading-system.com/?p=1175</guid>
		<description><![CDATA[Stepping back from the story of the cockroach and the cheetah, it seems that robustness is all about survival. For an automated trading system, this means the system &#8220;survives and thrives&#8221; after you decide to put it &#8220;live&#8221;. However there are different ways to look at robustness in a mechanical trading system. Different definitions for [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.automated-trading-system.com/wp-content/uploads/2009/12/3976143160_c81a7d53e3.jpg" alt="Orchid: a robust flower - photo by purplemattfish@flickr" title="Orchid: a robust flower - photo by purplemattfish@flickr" width="300" height="300" style="float:left; margin-right:16px; margin-top:4px;"/>Stepping back from the <a href="http://www.automated-trading-system.com/cheetah-cockroach-robust/">story of the cockroach and the cheetah</a>, it seems that robustness is all about <em>survival</em>. For an automated trading system, this means the system &#8220;survives and thrives&#8221; after you decide to put it &#8220;live&#8221;.</p>
<p>However there are different ways to look at <em>robustness</em> in a mechanical trading system.</p>
<h3>Different definitions for robustness</h3>
<p>Trading system robustness usually implies that the system exhibits similar performance when subject to slight variations. However thinking about it, you realise that this can mean several things:<span id="more-1175"></span></p>
<ul>
<li>Robustness to future prices (the survival aspect)</li>
<li>Robustness to internal changes (i.e. variation in system parameters)</li>
<li>Robustness to external changes (i.e. variation in price data)</li>
<li>Robustness in system design</li>
<li>Robustness in system testing</li>
</ul>
<p>Also check that <a href="http://www.tradingblox.com/forum/viewtopic.php?t=7120 ">Trading Blox forum post</a> for more discussion on robustness (some of which directly inspired ideas in this post).</p>
<p>There are 2 assumptions that can be made:</p>
<p>The first: a system robust to changes (internal and external) will likely be robust to future prices: this is because markets always evolve and changes &#8211; and your system should be able to cope with these changes.</p>
<p>The second one is that creating a system using robust concepts and procedures, both in design and testing, should ensure that the system will show robustness.</p>
<h3>Robust system design</h3>
<p>This generally starts with a trading strategy that makes sense, with few parameters, not many bells and whistles (we do not want the Ferrari that looks good and go fast round the track but which can not go over speed bumps or underground car parks&#8230; Well, I do really&#8230;but you get the point! ;-)</p>
<p>Another aspect to consider when aiming to build a robust trading system is illustrated by this quote from Bill Eckhardt who aims to use robust tools and components in his systems:</p>
<blockquote><p>We developed all our systems exclusively in-house so there aren’t any sort of publicly recognizable indicators I could mention. We definitely use non-linear systems and non-linear indicators. Linear indicators, such as filters with moving averages, have been mined dry. </p></blockquote>
<p>In statistics, the median is a more robust tool than the mean/average (it is les subject to underlying data changes such as outliers). Possibly, using median instead of average in a trading strategy is more robust. A moving &#8220;median&#8221; crossover system would show more robustness than using a classic moving average crossover system &#8211; this is something I am planning to test out.</p>
<h3>Robust system testing</h3>
<p>The main aspect of robust system testing is to ensure that the back-test is realistic and that no over-fitting takes place. We will not go too much in detail as these have been well documented (I recommend <a href="http://www.amazon.com/exec/obidos/ASIN/047126847X/autotradblog-20" target="_blank" rel="nofollow">Perry Kaufman&#8217;s book</a> which has a whole chapter on System Testing and robustness).</p>
<p>Important points are good quality data, in-sample vs. out-of-sample data, realistic assumptions (costs, slippage, etc.), logic in the strategy.</p>
<h3>Robustness to internal changes</h3>
<p>This is when you change the parameters of the trading system. It is probably fairly easy to test and measure. Assume you have a Donchian Channel Breakout system with Channel length at 20 days and ATR-based stop at 30 days with a multiplier of 2.</p>
<p>A robust system would exhibit very similar performance with slightly different parameters: the robustness could be quantified by measuring the overall difference/standard deviation in system&#8217;s performance when varying parameters (for example in a range of +/- 10%), e.g. Donchian Channel Breakout system with Channel length at 22 days and ATR-based stop at 33 days with a multiplier of 1.8, etc.</p>
<h3>Robustness to external changes</h3>
<p>Here, this is mainly the &#8220;parameters&#8221; of the price data that can be amended to test for robustness. There are quite a few things that can be changed such as the set of instruments traded (small permutations should not affect performance drastically), testing period (system performs similarly over all time periods), or even random slight amendments in actual prices.</p>
<h3>Robustness to future prices</h3>
<p>Unfortunately future price data is pretty hard to come by (CSI are pretty good but they <em>only</em> provide historical data! Feel free to email me if you have found a good provider ;-), so you obviously cannot test your system for future price robustness before putting it live.</p>
<p>Arguably, the aim of focusing on robustness with the four previous points is to ensure that the system performs equally well on future prices. However these four robustness aspects in a trading system can only act as a <em>proxy</em> for future prices robustness.</p>
<p>Although we, as trading system developers, like to gain some sort of &#8220;comforting&#8221; certainty, we have to keep in mind that the future will be unpredictable, markets will change, and therefore designing a system to trade future prices will always contain some degree of uncertainty. It is up to us to decide (and predict) what parameters and proxies are important to ensure robustness in the future.</p>
<p>This might sound like a paradox, but designing an automated trading system involves more <em>discretion and prediction</em> than one would think.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.automated-trading-system.com/robustness-definitions/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Amibroker V. TradersStudio: Speed comparison Fight</title>
		<link>http://www.automated-trading-system.com/amibroker-tradersstudio-speed-comparison/</link>
		<comments>http://www.automated-trading-system.com/amibroker-tradersstudio-speed-comparison/#comments</comments>
		<pubDate>Tue, 10 Nov 2009 14:41:15 +0000</pubDate>
		<dc:creator>Jez Liberty</dc:creator>
				<category><![CDATA[Backtest]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[afl]]></category>
		<category><![CDATA[amibroker]]></category>
		<category><![CDATA[CSI]]></category>
		<category><![CDATA[e-ratio]]></category>
		<category><![CDATA[optimisation]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[screenshots]]></category>
		<category><![CDATA[tradersstudio]]></category>

		<guid isPermaLink="false">http://www.automated-trading-system.com/?p=930</guid>
		<description><![CDATA[It might not capture the imagination as much as the recent Haye v. Valuev WBA World Heavyweight Championship fight (it probably might for some of you&#8230; ;-) but I decided to organise my own &#8220;fight&#8221;: AmiBroker V. TradersStudio! And similarly to the boxing, speed was of the essence &#8211; with one platform completely out-performing the [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.automated-trading-system.com/wp-content/uploads/2009/11/valuevhayeposter.jpg" alt="valuevhayeposter" title="valuevhayeposter" width="235" height="287" class="alignleft size-full wp-image-932" style="margin-right:12px; margin-bottom:26px;"/><br />
It might not capture the imagination as much as the recent Haye v. Valuev WBA World Heavyweight Championship fight (it probably might for some of you&#8230; ;-) but I decided to organise my own &#8220;fight&#8221;: AmiBroker V. TradersStudio!<br />
And similarly to the boxing, speed was of the essence &#8211; with one platform completely out-performing the other one. Let&#8217;s find out which one&#8230;<span id="more-930"></span></p>
<p>In the last few posts I have been exploring the <a href="http://www.automated-trading-system.com/e-ratio-trading-edge/">e-ratio</a> and wrote the <a href="http://www.automated-trading-system.com/e-ratio-tradersstudio-excel/">code in TradersStudio</a>. I also tried to implement it in <a href="http://www.automated-trading-system.com/e-ratio-amibroker-code/">AmiBroker AFL language</a> mostly to check how it performed speed-wise &#8211; as I found TradersStudio quite slow.</p>
<p>While testing AmiBorker, it actually felt so fast that I decided to perform a more formal speed comparison test.</p>
<h3>Conditions of the test</h3>
<p>I exported the <a href="http://www.automated-trading-system.com/unfair-advantage-api-code-c-extract-futures-continuous-data/">CSI data via the API</a> for a proportionally back-adjusted Corn contract going back to 1949. The data was imported in both AmiBroker and TradersStudio via their ASCII Import.</p>
<p>The system tested is a simple 20-day Donchian Channel Breakout (Buy-only) and the ATR used to normalise the MAE/MFE is 20-day also.<br />
The optimiser in both systems were used to generate the e-ratio for <del datetime="2009-11-10T14:34:18+00:00">50 </del>51 different trade durations (from 10 to 50 days).</p>
<p>One of the condition to validate the results of the test was that the trades generated by both systems are similar (to double-check I did not make a coding mistake resulting in simpler/faster process for one of the platforms).</p>
<p>The computer I was running the test on is a quad-core CPU (2.4 GHz) with 3.25 GB of addressable RAM. Only one platform was running at the time it was tested.</p>
<h3>Results are in!</h3>
<p>And they look astoninglishly good for AmiBroker:</p>
<ul>
<li>The <strong>TradersStudio</strong> test was run first and took <strong>4 mins 15 sec</strong> to complete and produce the custom report (which needs to be manipulated in Excel to calculate the e-ratio). Furthermore, it appeared that every incremental run in the optimisation process took slightly longer than the previous one.</li>
<li>The <strong>AmiBroker</strong> test ran in (&#8230;drumrolls&#8230;) <strong>10 sec!</strong> And the e-ratio was readily available from the results grid:<br />
<div id="attachment_956" class="wp-caption alignnone" style="width: 310px"><a href="http://www.automated-trading-system.com/wp-content/uploads/2009/11/amibroker-optimisation-results.jpg" target="_blank"><img src="http://www.automated-trading-system.com/wp-content/uploads/2009/11/amibroker-optimisation-results-300x191.jpg" alt="AmiBroker optimisation results showing the e-ratio. Click to expand" title="amibroker-optimisation-results" width="300" height="191" class="size-medium wp-image-956" /></a><p class="wp-caption-text">AmiBroker optimisation results showing the e-ratio. Click to expand</p></div></li>
</ul>
<p>Both apps maxed out their allocated CPU (i.e. overall CPU usage of 25% = a quarter of the quad-core CPU available).</p>
<p>I then decided to run the AmiBroker code over <strong>5 markets</strong> to get a feel of how long it would take. I added Crude Oil (going back to 1985), Cotton (1968), Gold (1975) and Yen (1972).<br />
AmiBroker ran the same code + optimisation in <strong>2 mins 20 sec</strong>, twice as fast as one market in TradersStudio!</p>
<p>Applying a simple proportional calculation to derive the time it would take in TradersStudio for the same dataset would give us a completion time of 1 hour (59 min 30 sec exactly&#8230;). Since the performance seems to degrade over the course of the optimisation in TradersStudio (i.e. the first back-test is quicker than the last one of the optimisation run) we could assume that it would actually take longer, which is what I experienced when I was testing on similar data in the last few weeks.</p>
<p>So here you have it: <strong>AmiBroker is 25 times faster than TradersStudio</strong> and it gives you the results in a much more friendly format.</p>
<h3>Trade Reconciliation</h3>
<p>As mentioned earlier, to ensure that the test was valid, the set of trades generated by both systems should be compared. I ran one back-test of the system over the Corn data for a single optimisation step (e-ratio for 20 days duration) in both systems.</p>
<p>I could find that 296 trades out of 340 presented a very good match (some matches had one day difference on the Entry date and rounding differences on the prices). But overall the trade comparison was good enough to give assurance that the same systems and results were being tested.</p>
<p>I&#8217;ll keep investigating for myself where these errors are coming from (and post a  further code update if warranted) but we can assume that the differences are trivial with regards to performance comparison.</p>
<p>Did I mention that AmiBroker is 3 times as cheap with a much wider following (many more code samples, better docs, more forums, etc.)?&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.automated-trading-system.com/amibroker-tradersstudio-speed-comparison/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Amibroker e-ratio code</title>
		<link>http://www.automated-trading-system.com/e-ratio-amibroker-code/</link>
		<comments>http://www.automated-trading-system.com/e-ratio-amibroker-code/#comments</comments>
		<pubDate>Mon, 09 Nov 2009 12:30:53 +0000</pubDate>
		<dc:creator>Jez Liberty</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[afl]]></category>
		<category><![CDATA[amibroker]]></category>
		<category><![CDATA[e-ratio]]></category>
		<category><![CDATA[edge]]></category>
		<category><![CDATA[optimisation]]></category>
		<category><![CDATA[tradersstudio]]></category>

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

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

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

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

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

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

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

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

<p>If you want to run this code, you can download the <a href="http://www.automated-trading-system.com/wp-content/uploads/2009/11/e-ratio-gorilla.afl" target="_blank">e-ratio &#8220;gorilla&#8221; afl file</a> and simply update the BUY signals to whatever you fancy testing.</p>
<p>The next post will be a direct speed comparison between TradersStudio and Amibroker for computing the e-ratio on the same underlying data and with the same signal. I expect Amibroker to <em>win the fight</em> hands-down as it appeared &#8220;way&#8221; faster!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.automated-trading-system.com/e-ratio-amibroker-code/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
		<item>
		<title>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>
	</channel>
</rss>

