<?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>Hack the market &#187; regime-switching</title>
	<atom:link href="http://www.puppetmastertrading.com/blog/index.php/category/regime-switching/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.puppetmastertrading.com/blog</link>
	<description>Algorithmic trading experiences</description>
	<lastBuildDate>Wed, 21 Apr 2010 23:11:41 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>transitions</title>
		<link>http://www.puppetmastertrading.com/blog/2010/02/08/transitions/</link>
		<comments>http://www.puppetmastertrading.com/blog/2010/02/08/transitions/#comments</comments>
		<pubDate>Mon, 08 Feb 2010 21:21:12 +0000</pubDate>
		<dc:creator>tito</dc:creator>
				<category><![CDATA[EMS Internals]]></category>
		<category><![CDATA[portfolio management]]></category>
		<category><![CDATA[regime-switching]]></category>
		<category><![CDATA[strategy development]]></category>

		<guid isPermaLink="false">http://www.puppetmastertrading.com/blog/?p=1004</guid>
		<description><![CDATA[Today we return to our series on regime switching and the topic of managing portfolios of strategies.  In particular, we build on the examples illustrated in sensitivity testing and steppin&#8217; out, in which we showed historical and then real-time &#8216;forward-walking&#8217; of strategies.  The next step we&#8217;d described was to evolve the techniques illustrated to support [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignright" style="margin-left: 5px; margin-right: 5px;" src="/images/genetic.png" alt="" width="353" height="285" />Today we return to our series on regime switching and the topic of managing portfolios of strategies.  In particular, we build on the examples illustrated in <a title="sensitivity testing: historical forward walk" href="http://www.puppetmastertrading.com/blog/2009/11/14/sensitivity-testing/" target="_blank">sensitivity testing</a> and <a title="steppin' out" href="http://www.puppetmastertrading.com/blog/2009/11/25/steppin-out/" target="_blank">steppin&#8217; out</a>, in which we showed historical and then real-time &#8216;forward-walking&#8217; of strategies.  The next step we&#8217;d described was to evolve the techniques illustrated to support the real-time management of a portfolio of strategies.</p>
<p>In the example below, we look at another &#8216;meta&#8217; strategy named <em>StrategyPortfolio</em> which maintains a dynamic portfolio &#8211; P &#8211; of strategies which it will select from a set of strategies &#8211; S &#8211; running concurrently in simulation.  The constituents of P as well as their cash allocations and parameterizations will be rebalanced/adjusted regularly after an initial &#8216;out-of-sample&#8217; period during which only the S strategies are run.</p>
<p>Apart education, the intention of this strategy, as I&#8217;d originally suggested <a title="multi-strategy trading with regimes" href="http://www.puppetmastertrading.com/blog/2009/09/13/multi-strategy-trading-with-regimes/" target="_blank">here</a>, is to &#8216;back-into&#8217; a regime-switching strategy without attempting to directly quantify the regimes explicitly.</p>
<p>This has proved to be even more interesting than I&#8217;d expected, not so much because it performs particularly well (though it&#8217;s promising), but because of all of the things it has taught us.  In particular, the transitions are a killer and there are properties of strategies which (dis-)qualify them from being effective in such a scheme&#8230;</p>
<p><span id="more-1004"></span></p>
<p><strong><em>bad news </em><em>good news </em></strong><img class="alignleft" style="margin-left: 5px; margin-right: 5px;" src="/images/goodbad.jpg" alt="" width="270" height="212" /></p>
<p>As before, I&#8217;m not going to take the time to write-up my results in any formal manner but will again rely upon a quick screencast of the software running.  The good news is that I&#8217;m figuring out how to edit these things, so it&#8217;s mercifully shorter than earlier screencasts&#8230;</p>
<p><a title="Screencast: StrategyPortfolio in Stratbox" href="/images/flash/StrategyPortfolio/StrategyPortfolio.html" target="_blank">Please click here to see the screencast.</a></p>
<p>I hope you find it interesting and will look forward to any comments or suggestions you might make.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.puppetmastertrading.com/blog/2010/02/08/transitions/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>steppin&#8217; out</title>
		<link>http://www.puppetmastertrading.com/blog/2009/11/25/steppin-out/</link>
		<comments>http://www.puppetmastertrading.com/blog/2009/11/25/steppin-out/#comments</comments>
		<pubDate>Wed, 25 Nov 2009 19:01:40 +0000</pubDate>
		<dc:creator>tito</dc:creator>
				<category><![CDATA[EMS Internals]]></category>
		<category><![CDATA[regime-switching]]></category>
		<category><![CDATA[strategy development]]></category>

		<guid isPermaLink="false">http://www.puppetmastertrading.com/blog/?p=822</guid>
		<description><![CDATA[We&#8217;ve been looking at what we&#8217;ve been calling &#8220;meta-strategies&#8221; &#8211; strategies that act upon other strategies &#8211; with the goal of implementing something like we&#8217;d described in the recent regime-switching post.  (Please note that since then I&#8217;ve added a category to capture this thread.)
Last time we saw an example of historical forward-walking of a portfolio-oriented [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignleft" style="margin: 2px 5px;" src="/images/steppin-out.jpg" alt="" width="240" height="240" />We&#8217;ve been looking at what we&#8217;ve been calling &#8220;meta-strategies&#8221; &#8211; strategies that act upon other strategies &#8211; with the goal of implementing something like we&#8217;d described in the recent <a title="multi-strategy trading with regimes" href="http://www.puppetmastertrading.com/blog/2009/09/13/multi-strategy-trading-with-regimes/" target="_blank">regime-switching post</a>.  (Please note that since then I&#8217;ve added a category to capture this thread.)</p>
<p>Last time we saw an example of historical forward-walking of a portfolio-oriented day-trading strategy which utilized daily data.  This time we do something a bit more interesting and correspondingly complex.  Today we&#8217;ll look at a real-time forward-walk of a moderate-frequency strategy (trades perhaps a few hundred times in  a day) which looks at the top-of-the-book but doesn&#8217;t use market-depth.  The strategy is a simple mean-reverter that we&#8217;ve described before though we&#8217;ve had to make some small changes to get it to behave in the context we&#8217;re looking at now&#8230;</p>
<p><span id="more-822"></span></p>
<h3>meta-strategy protocol</h3>
<div class="wp-caption alignright" style="width: 179px"><img class=" " style="margin: 2px 3px;" src="/images/gigo.jpg" alt="" width="169" height="201" /><p class="wp-caption-text">careful ...</p></div>
<p>In particular, we need something of a protocol for sending <em>commands </em>from the meta-strategy to the &#8216;target&#8217; strategy.  Stratparts generally have a simple mechanism for this as they are notified of any changes to their descriptors.  What they do upon such notifications is their own business.  In order to achieve our goals, we might need to firm this up a bit, but it turns out this quickly becomes tricky terrain.</p>
<p>Consider a single contract strategy, say, a simple mean-reverter like one we&#8217;ve seen before (and which I&#8217;ll illustrate in the screencast below).  If we want to treat it as an element within a portfolio of strategies, then we need to be able to modify its allocation.  But changing the allocation to a dynamic strategy is very different from changing the allocation to a single name within a portfolio as the allocation effectively becomes a maximum and the strategy may spend the great majority of its time under-allocated.  But this is manageable if we don&#8217;t mind being under-allocated at times.</p>
<p>A harder case is if someone comes along and says, &#8220;stop trading gold&#8221;, and &#8220;start trading silver&#8221;.  What about my open positions &amp; orders?  If the answer is to go flat, then the <em>character </em>(of the returns) of the strategy is itself going to be effected by the fact that they are being mutated by a meta-strategy; if the answer isn&#8217;t to go flat then you&#8217;re really talking about a whole different, multi-contract strategy.  So you have to be careful to ensure that the kinds of mutations you are relying upon aren&#8217;t excessively disruptive to the strategy or you&#8217;re likely to see performance wildly different from normal for the strategy.  As always, if you put garbage in, you shouldn&#8217;t expect cotton candy to come out&#8230;</p>
<p>For this example, we can control allocation and two simple numeric params governing the strategy.  I&#8217;m just going to avoid the please-trade-a-different-contract-case and aim to address that issue by ultimately placing these strategies into a portfolio (some later day).  For now, we avoid the hard cases but I think the results remain interesting all the same&#8230;</p>
<p>In particular, just as we&#8217;d seen last time (on a totally different time-frame and with a totally different strategy), the forward-walked strategy appears to perform well relative to its peers&#8230;</p>
<p style="text-align: center;">If interested, <a title="Realtime Forward-walk example in stratbox" href="/images/flash/realtimeFwdWalk-Stratbox/realtimeFwdWalk-Stratbox.html" target="_blank">please click here</a> to see the screencast/example.</p>
<p style="text-align: left;">-</p>
<p style="text-align: left;">Happy Thanksgiving!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.puppetmastertrading.com/blog/2009/11/25/steppin-out/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>sensitivity testing</title>
		<link>http://www.puppetmastertrading.com/blog/2009/11/14/sensitivity-testing/</link>
		<comments>http://www.puppetmastertrading.com/blog/2009/11/14/sensitivity-testing/#comments</comments>
		<pubDate>Sat, 14 Nov 2009 16:44:34 +0000</pubDate>
		<dc:creator>tito</dc:creator>
				<category><![CDATA[EMS Internals]]></category>
		<category><![CDATA[back-testing]]></category>
		<category><![CDATA[performance analysis]]></category>
		<category><![CDATA[portfolio management]]></category>
		<category><![CDATA[regime-switching]]></category>
		<category><![CDATA[strategy development]]></category>

		<guid isPermaLink="false">http://www.puppetmastertrading.com/blog/?p=850</guid>
		<description><![CDATA[We&#8217;ve been looking at how a strategy container might view and implement a variety of modes for strategies it will launch and contain.  Last time I documented a uniform initialization process for many of them, including a posited walk-forward parameter optimization mode.  I&#8217;ve implemented an initial version of this that I&#8217;ll illustrate through a screencast [...]]]></description>
			<content:encoded><![CDATA[<div class="wp-caption alignright" style="width: 260px"><img src="/images/smarmySpock.gif" alt="" width="250" height="188" /><p class="wp-caption-text">&#39;optimization&#39; or &#39;search&#39;?</p></div>
<p>We&#8217;ve been looking at how a strategy container might view and implement a variety of modes for strategies it will launch and contain.  <a title="ready to launch" href="http://www.puppetmastertrading.com/blog/2009/11/08/ready-to-launch/" target="_blank">Last time</a> I documented a uniform initialization process for many of them, including a posited walk-forward parameter optimization mode.  I&#8217;ve implemented an initial version of this that I&#8217;ll illustrate through a screencast (first ever &#8211; be gentle) below, but before continuing want to raise a couple of cautionary notes about the slope we&#8217;re traversing here.</p>
<p>From the <a title="fools gold" href="http://puppetmastertrading.com/blog/2007/09/26/fools-gold/" target="_blank">very first post</a> on this blog I&#8217;ve tried to underline the danger that over &#8216;optimization&#8217; poses in view of the simple unalterable fact that if you look at enough random junk, you are bound to see things that look impossibly good.  Doesn&#8217;t mean they&#8217;re actually good.  In the context of trading strategy development, this is a particular danger as strategy parameter optimizers are easy to come by and can be very misleading if employed naively.  I think this is in part due to the term &#8216;optimization&#8217; which is really a stretch for what these tools do.  They&#8217;re better described as search tools as they are really searching through a tuple-space of possible parameter combinations that you&#8217;ve specified, and then ranking them by some criteria you specify.</p>
<p>They&#8217;re still useful, but less as &#8216;optimizers&#8217; and more as tools for judging the <em>sensitivity </em>of the strategy to different parameterizations.  If the strategy demonstrates good performance and stability over a variety of market conditions and parameterizations, you may just have found yourself a <a title="character of a winner" href="http://www.puppetmastertrading.com/blog/2008/04/04/the-character-of-a-winner/" target="_blank">winner</a>&#8230;</p>
<p>Anyway, I felt that had to be said&#8230;</p>
<p><span id="more-850"></span></p>
<p>Now, I&#8217;ll open the floor to a quick illustration of the initialization process described previously and an example of historical forward-walking.</p>
<p>At this point, I&#8217;m vested in the inquiry we&#8217;d started with the <a title="regime-switching" href="http://www.puppetmastertrading.com/blog/2009/09/13/multi-strategy-trading-with-regimes/" target="_blank">regime-switching post</a> and will apportion time each week towards implementing something like what we&#8217;d described there.  I expect the steps to be something like:</p>
<ol>
<li>historical fwd-walking which I&#8217;ll illustrate today</li>
<li>real-time fwd-walking, that is, dynamically adjusting a live strategy&#8217;s parameters based on a continuously repeated ranking of a concurrent &#8216;live optimization&#8217; of the same strategy</li>
<li>real-time allocation to a portfolio of strategies based on regime-switching where regimes are defined by the performance of a heterogeneous set of strategies we run concurrently (again &#8216;live optimization&#8217;)</li>
<li>peace on earth</li>
</ol>
<p>I may have some of the steps wrong, but am hopeful.  We&#8217;ll adjust as needed.</p>
<p>If interested, please click on the below image/link which will hopefully take you to a screencast.  This is my first-ever attempt to put a screencast in the blog, so please let me know if you have technical difficulties or suggestions on how to improve the experience.  Or if it&#8217;s just a big waste of time!</p>
<p>In the screencast I give a quick illustration of a simple backtest, a simple parameter optimization and finally a fwd-walk.  I&#8217;ll appreciate your feedback.</p>
<div class="wp-caption aligncenter" style="width: 410px"><a href="http://www.puppetmastertrading.com/images/flash/fwdWalk-Stratbox/fwdWalk-Stratbox.html"><img class=" " src="/images/forwardWalkScreencast.jpg" alt="click" width="400" height="311" /></a><p class="wp-caption-text">&gt;click&lt;</p></div>
]]></content:encoded>
			<wfw:commentRss>http://www.puppetmastertrading.com/blog/2009/11/14/sensitivity-testing/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>ready to launch</title>
		<link>http://www.puppetmastertrading.com/blog/2009/11/08/ready-to-launch/</link>
		<comments>http://www.puppetmastertrading.com/blog/2009/11/08/ready-to-launch/#comments</comments>
		<pubDate>Sun, 08 Nov 2009 13:08:50 +0000</pubDate>
		<dc:creator>tito</dc:creator>
				<category><![CDATA[EMS Internals]]></category>
		<category><![CDATA[back-testing]]></category>
		<category><![CDATA[regime-switching]]></category>
		<category><![CDATA[technology]]></category>

		<guid isPermaLink="false">http://www.puppetmastertrading.com/blog/?p=784</guid>
		<description><![CDATA[In this post I&#8217;m going to revisit some of the topics discussed in the recent &#8216;containing a strategy&#8216; and &#8216;multi-strategy trading with regimes&#8216; posts, focusing on the process of assembling a strategy and its context in preparation for its launch into any of a variety of modes.
I recently realized that &#8211; from the perspective of [...]]]></description>
			<content:encoded><![CDATA[<div class="wp-caption alignleft" style="width: 208px"><img src="/images/slightMiscalc.jpg" alt="he wasnt ready..." width="198" height="148" /><p class="wp-caption-text">poor Jorge wasn&#39;t ready...</p></div>
<p>In this post I&#8217;m going to revisit some of the topics discussed in the recent &#8216;<a title="containing a strategy" href="http://www.puppetmastertrading.com/blog/2009/08/19/containing-a-strategy/" target="_blank">containing a strategy</a>&#8216; and &#8216;<a title="multi strategy trading with regimes" href="http://www.puppetmastertrading.com/blog/2009/09/13/multi-strategy-trading-with-regimes/" target="_blank">multi-strategy trading with regimes</a>&#8216; posts, focusing on the process of assembling a strategy and its context in preparation for its launch into any of a variety of modes.</p>
<p>I recently realized that &#8211; from the perspective of a strategy container &#8211; the process of walk-forward testing is remarkably similar to the regime-switching model we&#8217;d discussed previously.  Up until now, I&#8217;ve employed walk-forward testing in an ad-hoc manner by taking an existing strategy and then writing a little driver very much like a unit-test scaffolding which would walk the strategy forward, permuting parameters based on previous performance.  Not a general solution, but straight-forward as I employ the strategy parameter optimizer from stratbox in this kind of a <em>toolkit</em> use-case.</p>
<p>I sat down to write one of these walk-forward scaffolds yesterday and started to think about how I could generalize the solution and roll it into stratbox&#8217;s GUI and it occurred to me that I could likely kill two birds with one stone&#8230;</p>
<h4><span id="more-784"></span><span style="color: #000000;">walk-forward testing</span></h4>
<p>&#8211;</p>
<p>I imagine there are different ideas/implementations of it, but for me walk-forward testing is the case where you are using repeated historical parameter &#8216;optimizations&#8217; to dynamically modify the parameters on a back-tested strategy.  For example, say we have strategy X with parameters p1 and p2.  Let&#8217;s say we want to walk-forward test it from the beginning of the year until now.  We&#8217;ll need a look-back period for optimizations &#8211; say 20 trading days &#8211; and a frequency with which to apply the results of our optimizations &#8211; say every 5 trading days.  So, on a weekly basis we&#8217;re going to look back at the prior (rolling) month performance and adjust our parameters to match the <em><strong>best</strong></em> performer.  How you define &#8216;best&#8217; is your business but I&#8217;ll use something simple like sharpe here.</p>
<p>Continuing with our example, we&#8217;ll say that p1 will be permuted 3 ways with values from { 1, 2, 3 } and p2 will be permuted across 4 values { &#8220;a&#8221;, &#8220;b&#8221;, &#8220;c&#8221;, &#8220;abcd&#8221; }.  So we have a basis of 12 strategies for optimization and we&#8217;ll call these O1&#8230;O12.</p>
<p>To perform a walk-forward test on X from 2009/01/01-now, we will begin a parallel back-test on O1..O12 starting 20 trading days <strong><em>before</em></strong> Jan1.  On Jan2 we will look at the prior ~month&#8217;s results and pick the strategy who had the highest sharpe ratio and clone him and start testing him &#8220;walking forward.&#8221;  Each week, we&#8217;ll repeat the process except that instead of cloning the winner as we did the first time, we&#8217;ll just make sure his params are the same as the new winner&#8217;s params.</p>
<p>Repeat this process until &#8216;now&#8217; and you&#8217;re done &#8211; you&#8217;ve performed walk-forward testing on X.</p>
<p>&#8211;</p>
<p>Let&#8217;s think about what&#8217;s happening here.  There are 12 strategies running from ~2008/12/1 and another strategy running from 2009/1/2; all strategies run until now.  There&#8217;s also the activity that &#8220;we&#8221; have done during this process.  What we are doing is the role of a meta-strategy just as we&#8217;d seen in the regime-switching case.  The walk-forward meta-strategy needs to watch a set of &#8216;optimization&#8217; strategies and permute another target (&#8220;X marks the spot&#8221;) strategy on a regular basis to match parameters with the prior period&#8217;s winner.</p>
<h4><span style="color: #000000;"><strong>differences vs. allocating to strategies with regimes</strong></span></h4>
<p>Let&#8217;s imagine that we&#8217;re going to take the 13 lovingly-named strategies O1&#8230;O12 and X, along with the newly revealed meta-strategy we&#8217;ll dub &#8220;M&#8221;, and put them onto a live environment instead of a historical back-test.  Suddenly we&#8217;re pretty close to what we&#8217;d described previously.  The biggest difference is just the <em>temporality</em> of the strategy context: historical or real-time.  Another difference is that O1&#8230;O<em><strong>n</strong></em> (let&#8217;s generalize just a bit) are no longer necessarily all the same strategy &#8211; they may be completely different. X is also no longer a strategy, but a portfolio of strategies:  a replicated subset of O1&#8230;On we&#8217;ll call X1..Xm.  &#8220;Best&#8221; is no longer a unary choice but must be rich enough to allow M to support some kind of an allocation algorithm across the X family.</p>
<p>OK, so there are some significant differences.  But from the perspective of the object model on which all of this can be implemented, the differences may be limited enough to warrant tackling together.</p>
<h4><span style="color: #000000;"><strong>ready to launch</strong></span></h4>
<p>Before looking at the workflow of a strategy launch, let&#8217;s consider all of the various modes we support with our design:</p>
<ul>
<li>Historical: back-test single strategy</li>
<li>Historical: parameter-based optimization of strategy (decomposes to many back-tests)</li>
<li>Historical: walk-forward testing of strategy</li>
<li>Real-time: SIM &#8211; run single strategy with real-time market data and an exchange simulator</li>
<li>Real-time: LIVE &#8211; run single strategy with real-time market data and a live connection to OMS/broker/exchange</li>
<li>Real-time: LIVE+SIM &#8211; run two cloned instances using the same market data, but with one routing orders to live venue(s) and the other to a simulator.  This is mostly useful for the development of a simulator or to evaluate the quality of simulation for a given strategy.</li>
<li>Real-time: optimization &#8211; run many strategies, permuted differently across live data but routing to a simulator.  I don&#8217;t know what this is useful for, but I find it entertaining&#8230; The screenshots from the <em>regimes</em> post were illustrating this mode.</li>
<li>Real-time: meta-strategy &#8211; our mythic regime-switching allocator will be a nice example of this mode.</li>
</ul>
<p>-</p>
<p>Consider the following sorta-flowchart illustrating the preparation for launch of a strategy.</p>
<div class="wp-caption aligncenter" style="width: 606px"><a href="/images/strategyLaunchFlow.jpg"><img src="/images/strategyLaunchFlow.jpg" alt="" width="596" height="466" /></a><p class="wp-caption-text">click for larger version...</p></div>
<p>The process has 4 or 5 stages depending on whether we&#8217;re being &#8220;meta&#8221; or not &#8211; that is, if we&#8217;re using optimization of any sort.  The highlighted parallelograms are the concrete end-result(s) for each of their respective steps.</p>
<ul>
<li><strong>Assemble Strategy Context</strong> &#8211; The basic channels of I/O for a trading strategy are its sources for market data and the exchanges where trades can be executed.  The MktDataSrc and ExecutionPlatform abstractions need to be specified.</li>
<li><strong>Assemble Strategy</strong> &#8211; Whatever mode we&#8217;re looking to employ will require a strategy either to itself go and trade for us or else to serve as the seed or prototype for our activities.  In this step we define that strategy.  For me, this can be a composite process as a strategy is made up of an arbitrary number of stratparts.  The assembly of a strategy can be done manually with a gui or by loading a strategy from a file or other store.  Once the parts are identified, they can be bound together to form a strategy instance.</li>
<li><strong>Configure Strategy</strong> &#8211; Once assembled, the strategy needs to be configured.  This may just mean we need to parameterize it appropriately for our use.  If we&#8217;re being meta and require optimization then we&#8217;ll also need to describe the parameters to modify and the ranges for each.  This gets boiled-down into an OptimizationDescriptor which is composed of a prototype strategy and the parameter/range data required to perform the requisite back-tests.</li>
<li><strong>Configure Optimization or Meta-strategy</strong> &#8211; If we&#8217;re not running an optimization or utilizing a meta-strategy, this step is skipped.  Otherwise, this is where the optimization and/or meta-strategy should be built and configured.</li>
<li><strong>Review &amp; Launch</strong> &#8211; Anytime you might loose a piece of software on an account with real money in it, it behooves you to pause and reflect for a moment.  Now is that moment.  If, after that moment of reflection, both you and whatever risk measures you employ agree that it&#8217;s OK, then it&#8217;s time to launch.  Happily, this is easy because we now have everything we need.  Again, the meta cases are a bit more involved as the strategies to be optimized or managed must be first generated based on the optimization descriptor we&#8217;ve inherited from earlier steps.  Then it&#8217;s a matter of assembling the pieces previously selected and configured and away we go.</li>
</ul>
<p>-</p>
<blockquote><p>Anytime you might loose a piece of software on an account with real money in it, it behooves you to pause and reflect for a moment.  Now is that moment.</p></blockquote>
<p>I was taught that writing software is easy <em>if</em> you can express the problem you&#8217;re looking to solve <em>and its solution</em> in clear and precise English.  I&#8217;m not sure about this being grammatical, clear or precise, but hopefully it&#8217;s enough to illustrate a means of uniformly modeling and implementing these beasties across a variety of use-cases.</p>
<p>For me, at least, writing this description is helpful as it forces me to walk through the various twists and turns in some detail before digging into the code.  When I get the integrated walk-forward testing working I&#8217;ll try to provide some illustration of its use and will look-ahead to developing a regime-switching example using the models/mechanisms we&#8217;ve been discussing.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.puppetmastertrading.com/blog/2009/11/08/ready-to-launch/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>multi-strategy trading with regimes</title>
		<link>http://www.puppetmastertrading.com/blog/2009/09/13/multi-strategy-trading-with-regimes/</link>
		<comments>http://www.puppetmastertrading.com/blog/2009/09/13/multi-strategy-trading-with-regimes/#comments</comments>
		<pubDate>Sun, 13 Sep 2009 19:02:12 +0000</pubDate>
		<dc:creator>tito</dc:creator>
				<category><![CDATA[EMS Internals]]></category>
		<category><![CDATA[dereferenced]]></category>
		<category><![CDATA[portfolio management]]></category>
		<category><![CDATA[regime-switching]]></category>
		<category><![CDATA[strategy development]]></category>

		<guid isPermaLink="false">http://www.puppetmastertrading.com/blog/?p=594</guid>
		<description><![CDATA[One of the challenges of algorithmic trading is that although there&#8217;s plenty of interest in the space, practitioners aren&#8217;t generally forthcoming about their observations.  Academics, instead, focus on things that are frequently not very immediately practicable, or when they might be, always seem to set-up a little hedge-fund on the side while publishing colorful chum [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignright" style="margin: 2px;" src="/images/rswitch.jpg" alt="" width="225" height="300" />One of the challenges of algorithmic trading is that although there&#8217;s plenty of interest in the space, practitioners aren&#8217;t generally forthcoming about their observations.  Academics, instead, focus on things that are frequently not very immediately practicable, or when they might be, always seem to set-up a little hedge-fund on the side while publishing colorful chum about how markets are &#8216;behavioural&#8217; or somesuch.</p>
<p>Even if it&#8217;s hard to find good stuff, one must still look as there&#8217;s always more information that can help you than you can effectively process or retain.  A few weeks ago I was trying to formalize the expected profit function of an algorithm I&#8217;m developing and wanted to see what people had written about the topic.  I entered &#8216;define profit function for trading algo&#8217; into google and was pleasantly surprised to see a paper entitled <a title="Multi-strategy trading utilizing market regimes" href="/images/mstratRegimes.pdf" target="_blank">&#8216;Multi-strategy trading utilizing market regimes&#8217;</a> by Mlnarik, Ramamoorthy and Savani.  It doesn&#8217;t directly cover the topic I was looking for, but instead addresses a number of related topics I&#8217;ve been interested in for some time:</p>
<ul>
<li>the treatment of a strategy as an instrument in its own right</li>
<li>composing portfolios comprised of strategies</li>
<li>using regime switching techniques to manage portfolios of strategies</li>
</ul>
<p>In this post, I&#8217;ll briefly review their paper, illustrate how one can easily model strategies in relevant ways using the strategy &#8216;object model&#8217; I&#8217;ve described <a title="containing a strategy" href="http://www.puppetmastertrading.com/blog/2009/08/19/containing-a-strategy/" target="_blank">previously</a> through an example, and conclude with some thoughts on how these kinds of strategies might be implemented and further explored.</p>
<p><span id="more-594"></span></p>
<p><strong><a title="Multi-strategy trading utilizing market regimes" href="/images/mstratRegimes.pdf" target="_blank">&#8216;Multi-strategy trading utilizing market regimes&#8217;</a> by Mlnarik, Ramamoorthy and Savani</strong></p>
<p>Their paper begins:</p>
<blockquote><p>This paper considers the problem of dynamically allocating capital to a portfolio of trading strategies. The allocation should be robust, and the capital allocated to a trading strategy should reflect the confidence in the expected profit that the strategy will make in current market conditions.</p>
<p>Good trading strategies exploit recurring market dynamics that can be more prevalent in some time periods than in others. Indeed, the concept of regimes is fundamental to financial markets, and much research has focused on the detection of regime shifts. In this paper, we consider a regime as defined by a set of trading strategies that exhibit similar performance in a given time period.</p>
<p>We consider different parameterizations of the same strategy as distinct in our ground set of strategies. The trading problem is to pick a distribution over the ground set that will achieve good performance in the current time period.</p></blockquote>
<p>They start with some interesting definitions.  A trading strategy is defined as a function which takes a given market <em>State </em>and generates a convenient<strong> </strong><em>Answer </em>&#8220;denoting all possible trading decisions&#8221;.  <em>Strategy functions</em> can also be parameterized and different parameterizations of the same function/strategy are viewed as distinct <em>qualitative strategies</em>.  They assume the existence of  the set of all strategies.  A <strong>regime</strong> is defined as a set of trading strategies who behave similarly over a given period of time where <em>similarly</em> is measured by the variance of a fitness function.</p>
<p>So they start with a set of strategies, a fitness function and some historical market data or state, and their first task is to identify the regimes.  They do this by running the strategies against randomly selected partitions of historical data, quantifying their respective performances with the fitness function and identifying the clusters deemed statistically significant.  Those sufficiently significant and similar sets of strategies are themselves the <em>reasonable regimes</em> while the set of strategies within all the reasonable regimes are themselves dubbed the <em>reasonable strategies</em> &#8211; the candidates for execution.  This might sound strange, but as I&#8217;ll illustrate with a concrete example below, this is actually a pretty effective and even intuitive way of defining regimes.</p>
<p>They define function <em><strong>stFuncDist </strong></em>as, for any regime, generating a distribution or weighting of the strategies within the regime.<em><strong> </strong></em>While <em><strong>classifyMarket</strong></em> is a function that generates a distribution across all regimes for any given market state. Both models can be &#8220;trained&#8221; and they do so by again iterating randomly across chunks of historical data adjusting the weighting constants of these two functions.</p>
<p>Finally, it&#8217;s time to trade and they can effectively use <strong>classifyMarket </strong>to determine a predominant regime and allocate capital as indicated by <strong>stFuncDist</strong> to the appropriate set of &#8220;reasonable strategies.&#8221;</p>
<p>They claim to have utilized this technique to generate the results charted in Figure 1, but they give little detail on the initial universe of strategies.  I believe they had one strategy which was parameterized into a set of <em>qualitative strategies</em> and run across one market, the CME&#8217;s Nasdaq emini.  I have no reason to doubt that they had exactly this result, but without more details on what they actually did, it&#8217;s hard to view it as very meaningful, though it certainly is suggestive.  An interesting thing about how they present their result, which I&#8217;ve seen in other academic papers, is that because they&#8217;ve precisely defined the set of possible strategies they look at, they can also calculate max and min possible returns over the relevant period.</p>
<p><strong> </strong></p>
<div class="wp-caption aligncenter" style="width: 283px"><strong><strong><img src="/images/mstumr-returns.jpg" alt="Figure 1: Out-of-sample profit (middle line) versus possible min (bottom line) and max profit (top line) over all strategies for the period 2006-11-01 to 2008-08-28." width="273" height="142" /></strong></strong><p class="wp-caption-text">Figure 1: Out-of-sample profit (middle line) versus possible min (bottom line) and max profit (top line) over all strategies for the period 2006-11-01 to 2008-08-28.</p></div>
<p><strong> </strong></p>
<p>The paper continues with another section, but I&#8217;m going to stop my overview here as the last part is less interesting to me and the interested reader should of course read it themselves.</p>
<p><strong>complex strategies or simple strategies combined</strong></p>
<p>One of the broadest design questions I see for the development of effective trading algorithms is whether one should employ complex, customized algorithms or instead utilize simple algos which can be simply combined to produce <em>emergent</em> complexity.  Although the authors of this paper allude to &#8220;Good trading strategies&#8221;, I wonder if one can even forget the &#8220;good&#8221; part and instead worry about applying &#8211; even <em>bad</em>! &#8211; strategies at the right times.</p>
<p>There are a lot of things I like about this paper, but probably most of all it&#8217;s their definition and use of a regime.  One of my first <a title="redistribution" href="http://www.puppetmastertrading.com/blog/2007/10/07/redistribution/" target="_blank">posts</a> describes a pair of strategies &#8211; a simple mean reverter and a simple trend follower.  These two strategies are about as dumb as you please.  And yet, their behavior is pretty interesting apart the observations I&#8217;d published at the time regarding the distribution of their returns.  During the trading day, I&#8217;ve taken to running those two, old, dumb strategies across a variety of markets in simulation mode.  Why?  Because it&#8217;s easy, costs me nothing and actually is pretty interesting in that the strategies really do cluster in the way Mlnarik et al describe, effectively partitioning the market into visible regimes.</p>
<p><strong>a simple example: identifying regimes with strategies<br />
</strong></p>
<p>In order to illustrate this, I created a desktop within stratbox onto which I ran these two <em>qualitative strategies</em> parameterized differently and across six different markets.  In total, I have 48 strategies running with 24 of the mean reverting (MR) variety and 24 of the trend following (TF).  In figure 2 and figure 3, they are sorted by qualitative strategy – all of the MR strategies followed by all of the TF strats.   In figure 4, they’re instead sorted by instrument at the end of the day after all of the strats had been rendered quiescent for the night by their schedulers.  You can click to see a bigger version of these screenshots.  On each, the left side of the screen shows simple charts of the relevant markets while the right contains a table in which each line item is a running strategy.  The first is at the beginning of the day. the second is shortly before going silent at 4pm and the third is shortly after 4pm.</p>
<p style="text-align: center;">
<div class="wp-caption aligncenter" style="width: 510px"><a href="/images/regimes1.jpg" target="_blank"><img class="   " src="/images/regimes1.jpg" alt="variously parameterized mean-reverting &amp; trend-following strats run in sim " width="500" height="312" /></a><p class="wp-caption-text">Figure 2: variously parameterized MR &amp; TF strats run in realtime+simulation mode.  Sorted with the MR strats first. (click)</p></div>
<p style="text-align: center;">
<div class="wp-caption aligncenter" style="width: 510px"><a href="/images/regimes2.jpg" target="_blank"><img class=" " src="/images/regimes2.jpg" alt="later the same day" width="500" height="312" /></a><p class="wp-caption-text">Figure 3: later the same day</p></div>
<p style="text-align: center;"><strong> </strong></p>
<div class="wp-caption aligncenter" style="width: 510px"><strong><strong><a href="/images/regimes3.jpg" target="_blank"><img class=" " src="/images/regimes3.jpg" alt="at EOD, now sorted by instrument" width="500" height="312" /></a></strong></strong><p class="wp-caption-text">Figure 4: at EOD, now sorted by instrument</p></div>
<p>You’ll note that at all times throughout the day, the MR and TF strategies effectively mirrored each other regardless of market.  Although I’m not going to illustrate it, I’m going to just go right ahead and assert that this is almost always true  based on what I’ve seen.  And this is at the heart of the paper’s authors&#8217; insight regarding regimes – they can be effectively identified by examining the performance of even simple but well-defined strategies.</p>
<p>This suggests a simple means of implementing a similar design to that they described right on top of this example I’ve put together.</p>
<p><strong>modeling meta-strategies</strong></p>
<p>We need one more element to manage all of this – a meta-strategy – that is, a strategy for managing other strategies.  We support this idea in stratbox with what we call a controller strat.  The cannonical example of a controller strat is our implementation of the (Don’t) Panic button (the bright red button with an ! in the upper right hand corner) which will get all strategies out of the market with varying degrees of urgency and finality.  This is implemented as a controller strat which injects a stratpart into all running strategies.  The injected stratpart first deactivates its peers and then cancels outstanding orders and then gets out of the market with whatever urgency the user has required.</p>
<p><strong>allocating to portfolios of strategies</strong></p>
<p>In my example above, I have 48 strategies running in simulation across 6 futures markets.  Let’s imagine that at any moment in time, I will always have at least one strategy of each type (MR and TF) running for each market.<strong> </strong>Thus, I’ll always have 12 live strategies running against real money accounts and 36 candidates running against a simulator.  Effectively, we’ve just described a portfolio of 12 elements where each element is itself a strategy.</p>
<p>It’s not difficult to imagine implementing a controller strat which on a regular schedule will simply adjust the parametrization of the running strategies and their allocation of cash <em>based on the performance of the strategies running in simulation</em>.</p>
<p>It&#8217;s not difficult to imagine, but implementing it inevitably poses a variety of challenges not least of which is finding the time!  For now, we&#8217;re still finding new and interesting ways to express strategies which deal with portfolios of exchange-traded instruments.  But I think that this is just a point on our technology&#8217;s maturation curve which will ultimately lead to the regular development of strategies which operate on portfolios of strategies themselves&#8230;</p>
<p>Anyway, it&#8217;s nice to see a bit of academic work formalizing what I expect is a natural step in the evolution of trading algorithms.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.puppetmastertrading.com/blog/2009/09/13/multi-strategy-trading-with-regimes/feed/</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
		<item>
		<title>why they exist: regime-switching models</title>
		<link>http://www.puppetmastertrading.com/blog/2008/11/04/why-they-exist-regime-switching-models/</link>
		<comments>http://www.puppetmastertrading.com/blog/2008/11/04/why-they-exist-regime-switching-models/#comments</comments>
		<pubDate>Tue, 04 Nov 2008 05:19:01 +0000</pubDate>
		<dc:creator>tito</dc:creator>
				<category><![CDATA[dereferenced]]></category>
		<category><![CDATA[events]]></category>
		<category><![CDATA[regime-switching]]></category>

		<guid isPermaLink="false">http://www.puppetmastertrading.com/blog-test/?p=9</guid>
		<description><![CDATA[
]]></description>
			<content:encoded><![CDATA[<p><a title="Patrick Moberg notices something different about today" href="http://www.patrickmoberg.com/november-4-2008.jpg" target="_blank"><img title="Something's different about today..." src="http://puppetmastertrading.com/images/november-4-2008.jpg" alt="Something's different about today..." /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.puppetmastertrading.com/blog/2008/11/04/why-they-exist-regime-switching-models/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
