<?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; portfolio management</title>
	<atom:link href="http://www.puppetmastertrading.com/blog/index.php/category/portfolio-management/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.puppetmastertrading.com/blog</link>
	<description>algorithmic trading experiences</description>
	<lastBuildDate>Sat, 20 Nov 2010 14:46:57 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.3</generator>
		<item>
		<title>pairs portfolio</title>
		<link>http://www.puppetmastertrading.com/blog/2010/04/08/pairs-portfolio/</link>
		<comments>http://www.puppetmastertrading.com/blog/2010/04/08/pairs-portfolio/#comments</comments>
		<pubDate>Thu, 08 Apr 2010 15:51:48 +0000</pubDate>
		<dc:creator>tito</dc:creator>
				<category><![CDATA[back-testing]]></category>
		<category><![CDATA[dereferenced]]></category>
		<category><![CDATA[EMS Internals]]></category>
		<category><![CDATA[portfolio management]]></category>
		<category><![CDATA[strategy development]]></category>

		<guid isPermaLink="false">http://www.puppetmastertrading.com/blog/?p=1175</guid>
		<description><![CDATA[People have asked me how I go about implementing a strategy in Stratbox.  While I&#8217;ve illustrated a good number of strategies running in Stratbox in these pages, I&#8217;ve never walked through a non-trivial example from conception, through design, implementation and iteration.  Today we&#8217;ll go through a reasonably complex example in total (I&#8217;ll provide source) detail. [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignright" src="/images/pairs.jpg" alt="" width="269" height="180" />People have asked me how I go about implementing a strategy in Stratbox.  While I&#8217;ve illustrated a good number of strategies running in Stratbox in these pages, I&#8217;ve never walked through a non-trivial example from conception, through design, implementation and iteration.  Today we&#8217;ll go through a reasonably complex example in total (I&#8217;ll provide source) detail.</p>
<p>The example I&#8217;ve chosen is, I think, very nice because it&#8217;s a portfolio-oriented strategy, which is pretty much the only kind I care to explore; it&#8217;s also based around the concept of pairs trading, which is something which most can easily relate to; and finally, it&#8217;s already public domain and yet almost certainly has some juice in it for those who care to understand it and extend it intelligently.</p>
<p>The example comes from the blog of a company, <a title="Palantir" href="http://www.palantirtech.com/" target="_blank">Palantir</a> which does (something like?) analytical / decision support software for both finance and intelligence-gathering services (quants and spooks &#8211; spooky quants?).  The specific example is <a title="Palantir: pairs trading strategy" href="http://www.palantirfinance.com/analysis-blog/?p=194" target="_blank">here</a> and is described thusly:</p>
<p><span id="more-1175"></span></p>
<blockquote><p>In this study we explore a trading strategy that isolates pairs of  instruments within a sector that are highly correlated. We enter a trade  if the price paths of these instruments diverge, going long one  instrument and short the other, with the assumption that their price  paths will converge.</p>
<p>We construct our strategy in four parts: (1) isolate the target set  of tradable instruments, (2) choose a rule for finding correlated pairs  within that set, (3) pick criteria for entering trades, and (4) test the  trading strategy.</p>
<p>&#8230;</p>
<p>For this study we want to isolate pairs of instruments whose  correlation is above a certain threshold.  At the beginning of each  quarter, we restrict our target stocks to the top 5 in the sector by  252-day correlation to the S&amp;P 500.  Then our <a href="http://www.palantirfinance.com/apps/strategy.html">Strategy</a> uses a metric that, for a given group of stocks, outputs a list of pairs  with a correlation above our target threshold of .60 over the same time  period.</p>
<p><strong>&#8230;<br />
</strong></p>
<p>Across every day and every pair in our trading list, we check the  21-day z-score (number of standard deviations from the mean) of the  difference between the two series. We classify the stocks as diverging  when the absolute value of the z-score is between 1.5 and 3.0. When this  condition is met we short the stock that is rising and long the stock  that is falling, sizing our position relative to the z-score and the  number of pairs currently trading.</p></blockquote>
<p><strong>~(sectors) ; reframing the strategy<br />
</strong></p>
<p>While I&#8217;ll implement a strategy broadly based on their description, I will use some poetic license to modify it in ways that seem to me sensible.  First, I have good experience writing equity strategies which deal with sectors and have pretty uniformly found that sectors, as defined by S&amp;P or whomever, are more trouble than they&#8217;re worth.  Instead, looking at correlation matrices and determining on that basis who should be paired, is much more fruitful in my experience.  Tr8der has some very nice posts illustrating (very prettily!) a similar point <a title="Tr8der: equity clusters 2" href="http://tr8dr.wordpress.com/2009/12/31/equity-clusters-2/" target="_blank">here</a> and <a title="Tr8der: equity clusters" href="http://tr8dr.wordpress.com/2009/12/30/equity-clusters/" target="_blank">here</a>.  (Actually, his point is a bit broader and represents an area of possibly promising development of this strategy which I won&#8217;t pursue here.)</p>
<p>So, we&#8217;re going to chunk the idea of explicitly using sectors.  Instead, we&#8217;ll simply construct, on a monthly basis (Palantir did this quarterly) a <em><strong>TrailDays</strong></em> correlation matrix from which we&#8217;ll extract the set of pairs which have a correlation greater than <em><strong>MinCorrelation</strong></em>.  On a daily basis, we will calculate the <em><strong>ZScoreDays</strong></em> z-scores of each of these pairs and sort them by absolute value, tossing those whose values are less than <em><strong>MinZScore </strong></em>or exceed <em><strong>MaxZScore</strong></em>.  Since I don&#8217;t like the idea of having an open-ended number of pairs/positions in my portfolio, I will constrain the portfolio to a maximum of <em><strong>N</strong></em> names and will <em><strong>Allocate</strong></em> $1M to the strategy.   Finally, we will look at the effect of trading an <em><strong>EvenlyWeight</strong></em>ed portfolio or a z-score weighted portfolio (as Palantir had done).</p>
<p>The initial &#8216;universe&#8217; of equities across which we will calculate our correlations will be filtered from my database of daily equity data going back to 2005 where the closing price is over $1, the average daily dollar-volume is over $50M and the data is relatively clean (few if any gaps).  This yields an initial universe of ~600 equities and ~180K pairs.</p>
<p>Assuming that we keep <em><strong>N</strong></em> above 20 or so and we keep our allocation constant at $1M, and assume execution at the close price, we should expect our results to be reasonably believable as it&#8217;s unlikely that the size we&#8217;re trading in would distort the market.  Scaling any strategy presents its own set of challenges which we&#8217;re not going to go into for this example, but an obvious direction for scaling the strategy would be to simply run it over intraday data and scale into and out of positions as conditions permit.</p>
<p>Ok, so that&#8217;s what our strategy is going to look like.  Now, how do we &#8220;make it so&#8221;?</p>
<p><strong>structure of a stratpart</strong></p>
<p>Within Stratbox, strategies are represented as composites made-up of &#8216;stratparts&#8217; each of which has its own metadata descriptor containing parameters.  Stratparts can be composed together within a strategy to enhance or modify the behavior of a strategy.  Thus, one can have a stratpart which implements the above logic paired with another stratpart which will e.g., modify the portfolio to impose beta neutrality, damp volatility or some other form of reporting or risk management.  Given that this example is already complexish, we&#8217;ll just stick to the one stratpart.</p>
<p>A stratpart has a few key elements.  One is the metadata descriptor which allows the strategy container (stratbox) to interact with it for back-testing, optimization or forward-walking purposes, or to allow a &#8216;trader&#8217; to interact with it dynamically during run-time (the so-called &#8216;gray box&#8217;).  Beyond that, it has an essentially event-driven design.  The method <strong>quote() </strong>is called when relevant (i.e., subscribed) market data arrives.  The method <strong>execution()</strong> is called when executions for orders that originated with this strategy are received.  And the method <strong>strategyEvent()</strong> is invoked on a variety of &#8216;interesting&#8217; events that the strategy implementer might care about.  None of these methods are required, so in its simplest form, a stratpart is a very simple piece of code to write.</p>
<p><strong>services in a stratpart</strong></p>
<p>Once one has complied with the minimal requirements for implementing a stratpart, one is rewarded with a variety of useful services: subscription-based market data feeds as well as a fast snapshot db and an in-memory historical db for quick correlation analyses cover market data needs.  Position management is handled at both the strategy level and at the exchange level (if you&#8217;re trading across multiple exchanges).  There is more, including performance analysis (e.g., sharpe, and its various analytic friends) and hierarchical cash allocation within and across strategies, but we won&#8217;t look at these in this example.</p>
<p><strong>implementing metadata</strong></p>
<p>So, the first thing we need to do is define our metadata.  This is done through the use of a conventionally-named static method <strong>Descriptor().<br />
</strong></p>
<pre class="brush: java; title: ; notranslate">
public static Descriptor Descriptor() {

 ArrayList&lt;Param&gt; params = new ArrayList&lt;Param&gt;();

 String cd = &quot;Unleveraged capital to apply&quot;;
 params.add(new Param(InitialBalance, cd, false, 1000000.0));

 String n = &quot;# of instruments to hold in portfolio&quot;;
 params.add(new Param(N, n, true, 20));

 String tc = &quot;Trailing days over which to calculate correlations&quot;;
 params.add(new Param(TrailDays, tc, true, 252));

 String mc = &quot;the minimum correlation of pairs to consider&quot;;
 params.add(new Param(MinCorrelation, mc, true, .75));

 String zd = &quot;trailing days over which to calc z-score&quot;;
 params.add(new Param(ZScoreDays, zd, true, 21));

 String mizs = &quot;minimum z-score&quot;;
 params.add(new Param(MinZScore, mizs, true, 1.5));

 String mazs = &quot;maximum z-score&quot;;
 params.add(new Param(MaxZScore, mazs, true, 3.0));

 String ew = &quot;evenly-weight portfolio? (or weight by z-score)&quot;;
 params.add(new Param(EvenlyWeight, ew, true, true));

 Descriptor _desc = new Descriptor
   (&quot;puppetmaster.strats.Pairs&quot;, _Desc, params);

 return _desc;
}

public Pairs(Strategy strat, Descriptor d) { super(strat, d); }
</pre>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p>Not the most interesting chunk of code, but pretty straightforward and its inclusion opens up a lot of functionality within the environment as each of these parameters can now be systematically or manually modified in-flight.  The third parameter to the Param constructor, a boolean, indicates if we want to allow the system to optimize this parameter.  Thus, the allocation/initialBalance parameter isn&#8217;t optimizable as it wouldn&#8217;t make any sense to do so.  Even so, we can (ourselves or through an allocation algorithm) modify this value to force the strategy to lighten or extend its financial footprint.  The others are fair game for optimization.</p>
<p>The constructor is also required &#8211; with that exact signature.  This is pretty much it for the &#8216;boilerplate&#8217; code required.</p>
<p><strong>&#8216;installing&#8217; the stratpart</strong></p>
<p>Now that we&#8217;ve met the minimum requirements for a stratpart, we can install it into stratbox.  This requires adding one line to your personal stratparts.xml config file.  Like so:</p>
<pre class="brush: xml; highlight: [5]; title: ; notranslate">
&lt;?xml version='1.0'?&gt;
&lt;stratParts&gt;
 &lt;descriptor class='puppetmaster.model.strategy.FwdWalker'/&gt;
 &lt;descriptor class='puppetmaster.model.strategy.StrategyPortfolio'/&gt;
 &lt;descriptor class='puppetmaster.strats.Pairs'/&gt;
 &lt;descriptor class='puppetmaster.strats.AMBO'/&gt;
 &lt;descriptor class='puppetmaster.strats.meta.AdjMeanReverter'/&gt;
 &lt;descriptor class='puppetmaster.strats.meta.AdjTrendFollower'/&gt;
 &lt;descriptor class='puppetmaster.strats.meta.Binary'/&gt;
</pre>
<p>Once we&#8217;ve informed stratbox of the new stratpart we&#8217;ve written, we can view it within our library of stratparts within the strategy wizard in stratbox:</p>
<div class="wp-caption aligncenter" style="width: 454px"><img src="/images/plib.jpg" alt="" width="444" height="481" /><p class="wp-caption-text">Our Pairs strategy in the Strategy Wizard&#39;s stratparts library</p></div>
<p>And all of the parameters we defined within our descriptor show up on the next page where we can parameterize or optimize the strategy:</p>
<div class="wp-caption aligncenter" style="width: 453px"><img src="/images/pcfg.jpg" alt="" width="443" height="554" /><p class="wp-caption-text">Configuring the Pairs stratpart within the strategy wizard</p></div>
<p>This means that the stratpart can be combined with other stratparts to create new strategies as I&#8217;ve described  and that it can partake in the rich set of functionality within the stratbox gui.  Including actually trading.  But first, we must make the strategy actually do something&#8230;</p>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p><strong>implementing event handling</strong></p>
<p>To that end, we must implement the event handling methods I&#8217;d described previously.  Since we&#8217;re not going to do any detailed execution handling in this strategy, we&#8217;ll only implement the <strong>quote()</strong> method and a subset of the events sent to the <strong>strategyEvent() </strong>method. In particular, we&#8217;ll listen to activation events (so we can initialize cleanly), changes to our descriptor and changes to our positions.</p>
<pre class="brush: java; title: ; notranslate">
/** listen for select strategyEvents */
public void strategyEvent(StrategyEvent event) {
  super.strategyEvent(event);
  switch (event.type) {
    case Activated:            _init();                 break;
    case DescriptorChanged:    _readDesc();             break;
    case PositionChanged:      _posnChange(event);      break;
  }
}
&lt;pre&gt;</pre>
<p>For quotes, we&#8217;ll just listen to the Beginning of Day (BOD) event.  If we wanted to trade intraday, we&#8217;d have to listen to tick events, but we&#8217;ll leave that for another day&#8230;</p>
<p>From a high-level, our code is pretty simple.  We determine the universe of pairs we might trade, we select from among them, we determine what our new portfolio should look like and then we trade to transition from our current state to our desired state.  That&#8217;s it.</p>
<pre class="brush: java; title: ; notranslate">
/** mkt data goes here, but we only listen for the BOD
 * (&quot;Beginning of day&quot;) event */
public void quote(Quote q) {
  if (q.type() != Quote.Type.BOD) return; // daily strat...

  try {
    List&lt;_Pair&gt; pairs = _getPairs();
    List&lt;_Pair&gt; sel = _selectPairs(pairs);
    List&lt;Position&gt; dp = (List&lt;Position&gt;)_desiredPfolio(pairs,sel);
    _Log.debug(&quot;PORTFOLIO: &quot;+dp);
    _trade(dp);
  } catch(Exception e) { _Log.error(e.getMessage(),e); }
}
</pre>
<p><strong>the messy details</strong></p>
<p>Digging into the details gets more complex, but not horrifically so, as stratbox already has basic analytics like correlation matrices, z-scores, volatility built into it.  Likewise with basic portfolio analytics and transformations. Thus, our code to trade a (pairs-based) long-short portfolio with an arbitrary number of elements is surprisingly simple:</p>
<pre class="brush: java; title: ; notranslate">
/** given a desired portfolio, trade to make it so */
void _trade(List&lt;? extends Position&gt; desiredFolio) {
  PositionRecord[] currFolio = posns();
  // Given our current portfolio (posns) and our desired state (dfolio),
  //  we generate the set of orders which will transform from the former
  //  to the latter
  //
  List&lt;Order&gt; orders = PortfolioComposer.TransformPortfolio
    (currFolio, desiredFolio, _orderF(), _strat, _strat.account());

  // place the orders for execution
  for (Order order : orders) {
    try {
      order.setType(Order.Type.MOC); // we trade at the close only
      _subscribe(order.contract());
      _execP().placeOrder(order);
    } catch (Exception e) { _Log.error(e.getMessage(), e); }
  }
}
</pre>
<p>As promised, I provide the full source listing below for those interested, but won&#8217;t over burden the discussion with a complete description of every little piece of it.</p>
<p><strong>a telling omission and some results</strong></p>
<p>Early in my career, working as a software engineer in a wall st front office technology department, I was befriended by a manager who told me he had once been a trader.  I asked him why he wasn&#8217;t a trader anymore.  He quipped:</p>
<blockquote><p>I was half of a talented trader.  I knew, in my bones, when to get into a trade.  Sadly, I was never really sure when to get out&#8230;</p></blockquote>
<p>It seems that the author of the Palantir example suffers a similar characteristic to my old friend (or is just being understandably cagey) &#8211; she specifies an entry condition, but not an exit!  Since she doesn&#8217;t impose any costs for trading, this has no big side effects, but in stratbox we do impose (pretty onerous -&gt; realistic!) costs for trading.</p>
<p>In any case, since this is just a simple example I&#8217;ve maintained the &#8216;no exit&#8217; policy and simply exit a trade once its pair goes out of the acceptable ranges for either correlation or z-score.  This has a bad effect on the strategy as you end up churning a lot of trades at the high end of the z-score range.  That is, if we set our upper boundary for z-score to be 3, then we might enter and exit a position multiple times as the z-score oscillates between, say, 2.9 and 3.1.  A more careful implementation could minimize this effect.</p>
<p>Another difference imposed by our more realistic simulation as opposed to the original example is that I&#8217;m restricting the portfolio size explicitly and explicitly limiting myself to trading a given contract within one pair as opposed to allowing a contract to trade across multiple pairs (invoking higher costs but allowing positions to offset and thus providing a neat little optimization &#8211; assuming trading costs nothing!).</p>
<p>All the same, the strategy clearly has some positive characteristics and when parameterized to take advantage of its naive exit strategy (by making the z-score low-end quite low, e.g., 0.5) takes on the character of a hedged trend-following strategy.  How so?  Well, while we are getting churned around the high-end (entry) z-scores, our profitable exits only happen once the z-scores have diminished (the prices have converged) considerably.  So we take more, smaller losses while our winners are held a bit longer.</p>
<div class="wp-caption aligncenter" style="width: 628px"><img src="/images/pairsOpt.jpg" alt="" width="618" height="260" /><p class="wp-caption-text">some Pairs results in &#39;10</p></div>
<p>Adding to my portfolio size improves things generally (and also increases the strategy&#8217;s scalability) while increasing the <em><strong>MinCorrelation </strong></em>parameter seems to hurt performance<em><strong> </strong></em>(not sure why, honestly &#8211; perhaps because if they&#8217;re very highly correlated and already diverging so strongly it may mean they&#8217;re actually diverging fundamentally).<strong> </strong>Returning to the topic of costs, each of these strategies incurred costs of over $5K for the period in question.<strong> </strong>And returning to the parameter which governs the weighting strategy employed, although I haven&#8217;t illustrated it here (as I haven&#8217;t looked at it very carefully), my initial finding is that it changed very little.  <em><strong><br />
</strong></em></p>
<p>There&#8217;s a great many areas where this strategy could be improved &#8211; that&#8217;s the fun, after all! &#8211; but hopefully even in its primitive form this example brings to light both an interesting baseline portfolio pairs strategy, while answering the question of how one goes about concretely implementing it within stratbox.</p>
<p>The entire strategy weighs-in at ~400 LOC including comments, boilerplate and individualized imports.  The source is here: <a href="/images/Pairs.java" target="_blank">Pairs.java</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.puppetmastertrading.com/blog/2010/04/08/pairs-portfolio/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<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>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[back-testing]]></category>
		<category><![CDATA[EMS Internals]]></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>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[dereferenced]]></category>
		<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=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>containing a strategy</title>
		<link>http://www.puppetmastertrading.com/blog/2009/08/19/containing-a-strategy/</link>
		<comments>http://www.puppetmastertrading.com/blog/2009/08/19/containing-a-strategy/#comments</comments>
		<pubDate>Wed, 19 Aug 2009 19:46:33 +0000</pubDate>
		<dc:creator>tito</dc:creator>
				<category><![CDATA[EMS Internals]]></category>
		<category><![CDATA[FIX Protocol]]></category>
		<category><![CDATA[portfolio management]]></category>
		<category><![CDATA[strategy development]]></category>
		<category><![CDATA[technology]]></category>

		<guid isPermaLink="false">http://www.puppetmastertrading.com/blog/?p=543</guid>
		<description><![CDATA[My son recently had his first birthday and amazes me daily with his new feats as he runs around increasingly stably exploring the world around him.  It occurs to me that the system I use to trade every day, Stratbox, is approaching its fourth &#8220;birthday&#8221; in the next few months.  I hadn&#8217;t originally intended to [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignleft" style="margin: 3px 5px;" src="/images/theChase.jpg" alt="" width="240" height="194" />My son recently had his first birthday and amazes me daily with his new feats as he runs around increasingly stably exploring the world around him.  It occurs to me that the system I use to trade every day, Stratbox, is approaching its fourth &#8220;birthday&#8221; in the next few months.  I hadn&#8217;t originally intended to write a system &#8211; an algorithmic trading platform &#8211; but found that existing products were limited, expensive and didn&#8217;t fit my mental model of what they should do.</p>
<p>This isn&#8217;t surprising as I wanted the system to support all of the activities associated with our algorithmic trading.  It turns out that that&#8217;s a lot to ask of a system.  It also turns out that you learn as you go and so the system continues to evolve.  A few years ago I&#8217;d <a title="putting the pieces together" href="http://www.puppetmastertrading.com/blog/2007/10/12/putting-the-pieces-together/" target="_blank">posted</a> about the basics of a strategy container and in this post I&#8217;m going to come back to this topic and describe some of the layers of code and thought developed since then.</p>
<p>First, let&#8217;s consider the role of a strategy container.  Its job is to intermediate between trading strategies and the external environments with which they interact.  It must also provide services that strategies can use (e.g., position management) and that it wouldn&#8217;t make sense for each strategy to re-implement.  In the past I&#8217;ve focused on the former responsibility of adapting strategies to external environments.  Why is this necessary and interesting?  Because it allows us to take the same exact strategy and run it live, or in simulation or in backtest, etc.  Interesting and necessary, but not what I want to focus on this time.  Instead, I want to look at the services provided to strategies; the &#8216;ecosystem&#8217; a strategy container provides in the hope that strategies might flourish within it.</p>
<p><span id="more-543"></span></p>
<p>We&#8217;ll go from the bottom up.  At the bottom you have one or more pipes of market data coming in.  You might also have news feeds, weather feeds or other such things coming in and we&#8217;re just going to conflate them all and say &#8220;market data.&#8221;  Still at the bottom, you also have one or more  two-way pipes with your oms or broker or directly with exchanges or with an exchange simulator.  Within Stratbox we call this abstraction an &#8220;ExecutionPlatform&#8221; because it&#8217;s conceptually where trades get executed.  The lingua franca for execution platforms is FIX, so the baseline object model of a strategy container is likely going to look a lot like messages described by the FIX spec.  Here we have orders, executions and the like.  Within Stratbox we&#8217;ve implemented an exchange simulator, a <a title="QuickFIX: Open source FIX engine" href="http://www.quickfixengine.org/" target="_blank">QuickFIX</a>-based FIX interface and a couple broker-specific APIs and they are all of type ExecutionPlatform.  To a strategy, they all look the same.  Likewise with market data.  Within the strategy container, we provide a publish-subscribe model wherein any kind of market data can be subscribed to regardless of the ultimate source of the data.  The intention is always to intermediate between the strategy and its external environment.</p>
<p><strong>the baseline object model</strong></p>
<p>Great.  But now I want to write a trading strategy.  What&#8217;s that going to look like?   And this is where things get increasingly interesting as we get to decide what kind of facilities we&#8217;re going to provide.  We also need to manage concurrency in some fashion as trading is an intrinsically asynchronous activity.  For this lowest level of strategy, we&#8217;ll say that each market feed is handled by a thread which timestamps and enqueues a &#8220;Quote&#8221; for later consumption and redistribution to relevant subscribers by a MarketDataService within the container.  Likewise, each execution platform will be serviced by a thread who similarly enqueus &#8220;Execution&#8221; objects from exchanges real and simulated.  The threads handling executions should likely have a higher priority than the threads handling market data.  So, the strategy is naturally exposed to the markets&#8217; asynchronicity right off the bat.  What baseline facilities will our strategy have at its disposal?  Well, it needs to be able to manage orders and positions, so it needs some kind of a &#8220;blotter&#8221; facility.  With this in place, a strategy can safely assume that it doesn&#8217;t need to listen to each execution coming in just to have a correct picture of its book.  It needs access to a MarketDataSvc and it likely also needs access to historical data.  But, staying simple, that&#8217;s more or less all we have to provide and we&#8217;re going to provide all of these things to the strategy through a single handle: a strategy context.  By swapping out a strategy&#8217;s context, we can move the strategy among environments (eg, from simulation to live execution).</p>
<p>With these facilities in place, basic algorithms can be implemented within a strategy and you should be able to test and trade them.</p>
<p>But you&#8217;re dealing with very low-level stuff.  You&#8217;ll also find that you&#8217;re writing the same kind of code over and over.  This inspired the introduction of a layer on top of the baseline object model which I&#8217;ve described before: <a title="StratParts" href="http://www.puppetmastertrading.com/blog/2008/04/12/stratparts-a-strategy-component-model/" target="_blank">StratParts</a> &#8211; a strategy component model.</p>
<p><strong>StratParts &#8211; a component model for strategies</strong></p>
<p>With StratParts, we introduced metadata and composition (in the <a title="Composites" href="http://en.wikipedia.org/wiki/Composite_pattern" target="_blank">&#8220;composite pattern&#8221;</a> sense) to our Strategy object model.  A strategy is itself a stratpart which contains other stratparts.  Thus, stratparts introduce a hierarchical structure to a strategy.  Each stratpart publishes a metadata descriptor which is aggregated at the strategy level.  The descriptor contains all of the modifiable characteristics of the strategy and can be changed while a strategy is executing thus giving a sort of grey box capability wherein a trader (or another strategy etc) can modify the behavior of a strategy as it&#8217;s running.  Stratparts also create an effective means of providing scoping within your strategy environment.  Stratparts can &#8220;see&#8221; the activity of other stratparts within the same strategy &#8211; they&#8217;re all peers in this sense.  This scoping can also be used for allocation of resources across different elements of a strategy.  For example, one stratpart might be allocated 80% of the cash available to the strategy while another stratpart manages the remaining 20%.</p>
<p>Stratparts have proved to be very powerful and we&#8217;ve written many of them though we&#8217;ll sometimes write strategies as one monolithic stratpart where it makes sense.</p>
<p>Stratparts have a lot of uses but one thing they don&#8217;t do is help manage the low-level complexity inherent in trading activities.  This was best described by a trader with whom I&#8217;d collaborated.  He&#8217;s a reservist in the IDF and uses military metaphors like I use sports metaphors.  He bemoaned the low-level handling of orders required for a very close-to-the-market strategy we were working on and said that:</p>
<blockquote><p>we need an order like a &#8216;smart&#8217; missile: fire it and forget it</p></blockquote>
<p>He was right and that inspired the next level of abstraction/support that we built into the system.</p>
<p><strong>&#8216;smart&#8217; orders and the tradeflow stratpart</strong></p>
<p>The strategy we were developing was meant to look at a universe of futures spreads and generate all of the &#8216;cycles&#8217; that might result in an arbitrage opportunity.  Since these are rare at best, we were really looking for circumstances where it looked like we had an advantage based on depth-of-market and various heuristics we&#8217;d apply.  Among the functionality that he wanted was an &#8216;order&#8217; which would act as a limit unless some conditions obtained in which case it might pay the spread or otherwise stop being a fixed limit order.  He didn&#8217;t want to handle this inside the strategy but instead wanted to fire these things off and forget about them unless they required attention (eg, if they&#8217;re rejected by the exchange or his firm&#8217;s risk management checks).  Although we ended up calling these smart orders, they&#8217;re really a sort of very localized execution strategy themselves.</p>
<p>To support them, we utilized the same workflow (= state machine) framework we&#8217;d implemented for our ExchangeSimulator as we wanted to ensure that these smart orders had a very well-defined life-cycle with a clear set of states and guarantees about transitions among them.  We embedded this workflow engine into a stratpart which supported smart orders operating within this &#8220;tradeflow&#8221;.  Thus, the extra functionality (and weight/expense) of this functionality is only achieved/incurred when actually required or desired.  This has proven to be a powerful addition to the system and raises the level of services enjoyed by prospective strategies substantially, particularly given the variety of orders we&#8217;ve implemented which stand ready for use by any new strategy that might want to employ them.</p>
<p>At this point, it should be clear that we&#8217;re blurring the lines between the strategies themselves and the container.  Another way of thinking of it is that one container can have a set of pre-made building blocks that can be applied for families of strategies.  Each one provides a particular grammar with which a strategy&#8217;s aims can be expressed.  For very close-to-the-market strategies where very low-level handling of orders is required, the tradeflow stratpart provides a set of really useful facilities, but if I&#8217;m just trading with limits then it might not be so interesting.</p>
<p><strong>portfolio-oriented strategies and beyond<br />
</strong></p>
<p>I&#8217;ve mentioned <a title="portfolio strategy" href="http://www.puppetmastertrading.com/blog/2008/09/13/portfolio-atomic-element-of-a-trading-strategy/" target="_blank">before</a> that I only care to think of strategies that operate on a portfolio.  As such, we&#8217;ve written a good deal of facilities for creating, analyzing and manipulating portfolios within strategies.  By using these facilities within a tradeflow stratpart, I can express quite complex strategies relatively simply by using portfolio analytics to determine my current &#8216;model&#8217; portfolio and then using smart orders to most effectively transition me from my current state to my model state.  For the kind of trading I do, this provides a rich &#8216;vocabulary&#8217; for the development of strategies.  All the same, my brain is having a <em>tip-of-the-tongue moment</em> as I feel that there&#8217;s an entirely different model possible for portfolio-oriented strategies just at the periphery of my imagination&#8230;  oh well, there&#8217;s always something new to explore.</p>
<p>Different trading styles, perspectives or trading problems are undoubtedly better served by different sorts of facilities.  I&#8217;m finding that just as language constrains and shapes thought, the strategy container that you employ shapes and constrains the kinds of strategies that you can implement.</p>
<p>If you have any ideas about such facilities for any kind of trading you do, I&#8217;d love to hear them.</p>
<p>&#8211;</p>
<p><strong>a note about Stratbox</strong></p>
<p><img class="alignright" src="/images/sb.jpg" alt="" width="161" height="161" />Although I&#8217;m talking about our system in this blog, we&#8217;re not marketing the system and happily &#8220;just&#8221; use it for our own trading activities.  We had looked into marketing the system previously but ultimately feel the same about selling stratbox as <a title="pimp that strat" href="http://www.puppetmastertrading.com/blog/2009/03/18/pimp-that-strat/" target="_blank">selling strategies</a>&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.puppetmastertrading.com/blog/2009/08/19/containing-a-strategy/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>doubling down with levered ETFs</title>
		<link>http://www.puppetmastertrading.com/blog/2009/04/22/doubling-down-with-levered-etfs/</link>
		<comments>http://www.puppetmastertrading.com/blog/2009/04/22/doubling-down-with-levered-etfs/#comments</comments>
		<pubDate>Wed, 22 Apr 2009 14:10:16 +0000</pubDate>
		<dc:creator>tito</dc:creator>
				<category><![CDATA[dereferenced]]></category>
		<category><![CDATA[portfolio management]]></category>
		<category><![CDATA[strategy development]]></category>

		<guid isPermaLink="false">http://www.puppetmastertrading.com/blog/?p=455</guid>
		<description><![CDATA[This weekend I read Jason Zweig&#8217;s &#8220;Will leveraged ETFs Put Cracks in Market Close?&#8221; which references a paper by Minder Cheng and Ananth Madhaven at Barclay&#8217;s.   I tried, but couldn&#8217;t find their original paper over the weekend.  As luck would have it from across the internets Paul Kedrosky came to the rescue with a [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignleft" src="/images/DoubleDown.jpg" alt="" width="363" height="500" />This weekend I read Jason Zweig&#8217;s &#8220;<a title="Leveraged ETFS" href="http://online.wsj.com/article/SB124000593149930309.html" target="_blank">Will leveraged ETFs Put Cracks in Market Close?</a>&#8221; which references a paper by Minder Cheng and Ananth Madhaven at Barclay&#8217;s.   I tried, but couldn&#8217;t find their original paper over the weekend.  As luck would have it from across the <em>internets</em> Paul Kedrosky came to the rescue with a <a title="Leveraged ETFs and Portfolio insurance" href="http://paul.kedrosky.com/archives/2009/04/leveraged_etfs.html">post</a> referencing that paper, &#8220;<a title="The Dynamics of Leveraged and Inverse Exchange-Traded Funds" href="http://www.barclaysglobal.com/secure/repository/publications/usa/ResearchPapers/Leveraged_ETF.pdf" target="_blank">The Dynamics of Leveraged and Inverse Exchange-Traded Funds</a>&#8220;.</p>
<p>If you have any interest in ETFs, then you should read this paper carefully as it provides a very nice and accessible mathematical treatment of leveraged and inverse ETFs.</p>
<p>I&#8217;ve had success using ETFs in portfolio-oriented strategies to conveniently provide specific exposures, eg, to emerging markets.  I&#8217;ve also explored strategies that pit ETFs against futures and similar arbs that <a title="USO and the roll" href="http://v2.ftalphaville.ft.com/blog/2009/02/18/52635/a-cancer-in-the-oil-markets" target="_blank">take advantage of contract rolls</a> or other anomalous behaviors across the markets.  But I&#8217;ve never looked at ETFs the way they really should be understood: as structured products that should have well-defined (if not necessarily obvious) properties.</p>
<p>Like many structured products, some of these characteristics are not obvious and may be quite unintuitive but are always important to understand.  For instance, the hedging required to implement these funds is both non-linear and asymmetric.</p>
<blockquote><p>Specifically, leveraged ETFs must re-balance their exposures on a daily basis to produce the promised leveraged returns. What may seem counterintuitive is that irrespective of whether the ETFs are leveraged, inverse or leveraged inverse, their re-balancing activity is <em>always </em>in the same direction as the underlying index&#8217;s daily performance. The hedging flows from equivalent long and short leveraged ETFs thus do not &#8220;offset&#8221; each other. [...]</p>
<p>The impact is particularly significant for inverse ETFs. For example, a double-inverse ETF promising -2X the index return requires a hedge equal to 6X the day&#8217;s change in the fund&#8217;s Net Asset Value (NAV), whereas a double-leveraged ETF requires only 2X the day&#8217;s change. This daily re-leveraging has profound microstructure effects, exacerbating the volatility of the underlying index and the securities comprising the index.</p></blockquote>
<p>Hence Mr Zweig&#8217;s concern that these ETFs feed the volatility we&#8217;ve seen for the last 8 months or so near the market close.  If the day has been up then both &#8220;bull&#8221; and &#8220;bear&#8221; levered ETFs will need to buy in order to stay hedged &#8211; reinforcing the trend and effectively supporting serial correlation of returns.</p>
<p><span id="more-455"></span></p>
<p>Another important property of levered and inverse ETFs is that they are designed to track the <em>daily</em> returns of their underlying index which does not mean that over the long term they will faithfully track the returns of their index.  Cheng and Madhaven illustrate that this can be viewed as an embedded path-dependent option within the product.  This is graphically illustrated with two charts of DIG and DUG over a shorter and longer period.  Over a short period, they track each other admirably, mirror-like, as one would expect.  But over a longer period they diverge quite spectacularly.  In fact, in the example below, one would have lost money betting on either over the same period!</p>
<div class="wp-caption alignnone" style="width: 675px"><img title="DIG &amp; DUG" src="/images/digdug.gif" alt="Heads I win, tails you lose - ProShares" width="665" height="506" /><p class="wp-caption-text">&quot;Heads I win, tails you lose&quot; - ProShares</p></div>
<p>Another interesting result of Cheng &amp; Madhaven&#8217;s research is that the &#8220;[hedging] demand as a fraction of closing volume is a non-linear function of return&#8230;&#8221;.  Thus, the greater the move in the underlying index, the hedging activities of these ETFs will have a (non-linearly!) greater market impact on the close.</p>
<p>There are other gems in here as well including hints at pricing options on these ETFs, and techniques for quantifying the market impact of hedging activities.  But don&#8217;t take my word for it.  Go read the original!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.puppetmastertrading.com/blog/2009/04/22/doubling-down-with-levered-etfs/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>NVIDIA&#8217;s TESLA and Compute Unified Device Architecture</title>
		<link>http://www.puppetmastertrading.com/blog/2008/11/29/nvidias-tesla-and-the-compute-unified-device-architecture/</link>
		<comments>http://www.puppetmastertrading.com/blog/2008/11/29/nvidias-tesla-and-the-compute-unified-device-architecture/#comments</comments>
		<pubDate>Sat, 29 Nov 2008 20:42:27 +0000</pubDate>
		<dc:creator>tito</dc:creator>
				<category><![CDATA[monte-carlo methods]]></category>
		<category><![CDATA[options pricing]]></category>
		<category><![CDATA[portfolio management]]></category>
		<category><![CDATA[technology]]></category>

		<guid isPermaLink="false">http://www.puppetmastertrading.com/blog/?p=164</guid>
		<description><![CDATA[While the war over the latest+greatest video cards for the current generation of graphics intensive games seems always to ebb and flow between nVidia and its arch-rival ATI, I&#8217;ve long preferred nVidia for their better support of Linux.  Thus, all of my machines have some sort of nVidia Graphics Processing Unit (GPU) in them. For [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignleft" title="NVIDIAs Tesla" src="/images/tesla_logo.jpg" alt="" width="288" height="278" /> While the war over the latest+greatest video cards for the current generation of graphics intensive games seems always to ebb and flow between nVidia and its arch-rival ATI, I&#8217;ve long preferred nVidia for their better support of Linux.  Thus, all of my machines have some sort of nVidia Graphics Processing Unit (GPU) in them.</p>
<p>For those who spend their workdays in the markets and their weekends pondering derivatives pricing, latency, oceans of market data, portfolio optimization, and how to make every last damn thing <em>faster</em>, a preference for nVidia cards could prove to yield an unexpected benefit.</p>
<p>nVidia has recently unveiled a product line dubbed &#8220;TESLA&#8221; which leverages their absurdly fast GPUs to provide a supercomputer-like High Performance Computing (HPC) platform at a previously unimaginable price point.  TESLA computers are regular machines that have a set of slightly modified GPUs in them; modified such that they have no video out, but instead become additive processing clusters which the machine can use for compute intensive tasks.  For about $10K you can buy a 1U machine with some 4 teraflops of capacity.  By way of comparison, this is over 20 times faster than the funky Helmer project I&#8217;d been drooling over a few months <a title="Billions and billions" href="http://www.puppetmastertrading.com/blog/2008/08/22/billions-and-billions/" target="_blank">ago </a>in a production-worthy package ready for the server room today.</p>
<p>So, <a title="Personal Super Computing" href="http://www.nvidia.com/object/personal_supercomputing.html" target="_blank">TESLA</a> refers to the machines built with these specialized GPUs.  Making all this power usable is what <a title="CUDA" href="http://www.nvidia.com/object/cuda_home.html" target="_blank">CUDA</a> is about&#8230;</p>
<p><span id="more-164"></span></p>
<p>CUDA is nVidia&#8217;s model for parallel programming that provides a C-based software environment for the development of applications that take can advantage of nVidia&#8217;s GPU architecture.  These advantages center around parallelism, torrential memory bandwidth and obscene floating point performance.   The below graphs illustrate these advantages against high-end Intel hardware.</p>
<p><img class="aligncenter" title="The advantages" src="/images/cudaPerf.jpg" alt="" width="548" height="830" /></p>
<p>Although I haven&#8217;t yet taken the plunge and purchased one of the trick new TESLA machines, I have been able to dip my toe into the waters as CUDA will work with most newer nVidia cards.  All you need to do is download the CUDA environment and SDK and you can very quickly get up and running.  They have an expansive and well-documented set of examples including many of interest to algorithmic traders &#8211; particularly surrounding derivatives pricing and monte-carlo methods.  I haven&#8217;t tried yet under linux, but was able to successfully modify their sample programs under vista after less than an hour of fiddling.</p>
<p>I had seen some flashes of interest in CUDA on the <a title="Quantlib" href="http://quantlib.org" target="_self">Quantlib</a> mailing lists, but I&#8217;m not sure if there&#8217;s been any real follow-up.  Even if it takes some time for the open source community to get plugged-in, there are already a number of finance-oriented commercial offerings including a plugin to Matlab which allows some operations within Matlab to be offloaded to whatever CUDA subsystems are available.</p>
<p>If you&#8217;re comfortable with C and happen to have an nVidia card handy, I encourage you to take a look-see. The price/performance advantage is remarkable and if you have a problem that can profitably make use of it, one of these boxes might pay for itself in a big hurry!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.puppetmastertrading.com/blog/2008/11/29/nvidias-tesla-and-the-compute-unified-device-architecture/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>portfolio: atomic element of a trading strategy</title>
		<link>http://www.puppetmastertrading.com/blog/2008/09/13/portfolio-atomic-element-of-a-trading-strategy/</link>
		<comments>http://www.puppetmastertrading.com/blog/2008/09/13/portfolio-atomic-element-of-a-trading-strategy/#comments</comments>
		<pubDate>Sat, 13 Sep 2008 17:23:56 +0000</pubDate>
		<dc:creator>tito</dc:creator>
				<category><![CDATA[performance analysis]]></category>
		<category><![CDATA[portfolio management]]></category>
		<category><![CDATA[strategy development]]></category>

		<guid isPermaLink="false">http://www.puppetmastertrading.com/blog-test/?p=85</guid>
		<description><![CDATA[A friend recently asked me what I considered to be the &#8220;axioms&#8221; of alpha-seeking trading strategies. I think there are a few, but probably the one that seems to me most important is that the atomic element of a trading strategy should always be a portfolio as opposed to a single instrument. In a scenario [...]]]></description>
			<content:encoded><![CDATA[<p><img hspace="5" align="left" alt="A wall st risk manager's favorite pastime?" title="A wall st risk manager's favorite pastime?" src="http://puppetmastertrading.com/images/eggs_in_one_basket.jpg" /> A friend recently asked me what I considered to be the &#8220;axioms&#8221; of alpha-seeking trading strategies.  I think there are a few, but probably the one that seems to me most important is that the atomic element of a trading strategy should always be a portfolio as opposed to a single instrument.</p>
<p>In a scenario of perfect knowledge, this wouldn&#8217;t be true.  If you somehow *know* with certainty that crude will go up or that Citigroup will go down, then concentrating all of your resources into a position based on that belief might be reasonable.  But knowledge seldom comes in such a neat package (and will frequently be illegal to act upon when it does!).</p>
<p>Instead, knowledge will typically come in more conditional and less certain forms: &#8220;commodities tend to rise during periods of FUD [Fear-Uncertainty-Doubt]&#8221; or &#8220;companies who announce stadium naming rights deals tend to under-perform.&#8221;  In some cases, perhaps the knowledge on which you&#8217;ll base your strategy can be quantified probabilistically.</p>
<p>Depending on the nature and quality of the knowledge or hypothesis that forms the basis for a given strategy, one can adapt one&#8217;s portfolio construction/optimization based on customized relationships amongst the potential portfolio constituents.  But one doesn&#8217;t need to be so fancy to see the concrete benefits of our first axiom.  Below I detail a simple strategy I&#8217;ve put together to explore the forces involved.</p>
<p><span id="more-85"></span></p>
<p>The strategy I&#8217;ve built constructs a completely random, equally weighted long-short portfolio every day and liquidates the portfolio at the end of the day.  Specifically, everyday the strategy:</p>
<ol>
<li>Looks at all equities in the database that are available to trade.  There were a bit more than ~4K equities available on any given day for this test.</li>
<li>Constructs a portfolio composed of N equities selected at random from the available equities.Â  The portfolio has a fixed number of dollars available to it ($500K) and thus each position within the portfolio will be of size $500K/N or less.  Orders are always scaled down so that we&#8217;re trading round lots (ie, qty%100=0) and if we can&#8217;t buy 100 shares of a particular name (eg, Berkshire Hathaway) then that money goes unused until the following day.</li>
<li>Half of the components in the portfolio are bought and half are sold so that we have a dollar-neutral portfolio.</li>
<li>Positions are entered at the open and exited at the close.  (For these kinds of position sizes, this turns out to be a reasonable assumption, as we&#8217;ve illustrated <a target="_blank" title="Execution quality at the open &#038; close" href="http://puppetmastertrading.com/blog/2008/08/01/execution-quality-at-the-open-close/">here</a>.)Â  No stops are employed.</li>
</ol>
<p>That&#8217;s it.  The strategy only exposes ONE parameter for tweaking: N &#8211; how many names to hold in the portfolio.  I varied this parameter across the set { 2, 4, 6,&#8230;, 12 } and ran each value 100 times across one year of data.</p>
<p>By selecting the portfolio&#8217;s components randomly, I&#8217;m trying to ensure that the strategies are truly non-predictive and thus should have an expected return of $0 without applying friction.  By creating a dollar-neutral portfolio, I&#8217;m trying to ensure that we&#8217;re not accidentally capturing beta.  What I&#8217;m looking to illustrate is the relationship between the number of elements comprising the portfolio and the risk-adjusted performance of the strategy.</p>
<p>As the following distributions illustrate, the strategy does indeed seem appropriately non-predictive. The distributions are normal and shifted to the left due to the application of realistic fees &#038; commissions.  As I&#8217;d warned in my <a target="_blank" title="fools gold" href="http://puppetmastertrading.com/blog/2007/09/26/fools-gold/">very first series of posts</a>, the random set of strategies did produce some nice-looking outliers, but we&#8217;re past being fooled by this pyrite of data-mining bias.</p>
<p><img title="Distributions" alt="Distributions" src="http://puppetmastertrading.com/images/eggDistr.jpg" /></p>
<p>Also in terms of showing volatility&#8217;s relation to (even trivial) diversification, the experiment did not disappoint.  While there&#8217;s essentially no relation between the profitability of a strategy and the portfolio size, there is a strong negative relationship between the volatility of the strategy and the diversification employed.  Furthermore, the benefits of diversification happen quickly and soon taper off as we can see when we look at the table and chart comparing the number of elements in our portfolio with the average vol across the hundred relevant strategies.</p>
<p><img title="volatility vs diversification" alt="volatility vs diversification" src="http://puppetmastertrading.com/images/eggStats.jpg" /></p>
<p>There&#8217;s nothing new about this result.  <a target="_blank" title="Harry Markowitz" href="http://en.wikipedia.org/wiki/Harry_Markowitz">Harry Markowitz</a> had explained these phenomena with infinitely greater rigor over half a century ago!  But judging from what is published in popular &#8220;trading strategies&#8221; books and periodicals and even the baseline capabilities of algorithmic trading platforms, it appears that people persist in trying to beat the market without using what is perhaps their most potent weapon.</p>
<p>There&#8217;s an <em>almost </em>good reason for this that&#8217;s like the parable of the fellow who loses his key on the street but decides to limit his search to the area illuminated by a nearby lamppost.  When asked where he&#8217;d lost the key, he indicates that he&#8217;d lost it somewhere on the street but was searching under the lamppost because the light was so much better there.Â  Writing a single instrument strategy can be difficult enough on its own and adding instruments can make it substantially more difficult.  But that&#8217;s also not a good reason to persist in limiting the scope of one&#8217;s efforts!<br />
<img alt="lamppost fallacy" title="lamppost fallacy" src="http://puppetmastertrading.com/images/streetlight.jpg" /></p>
<p>While there&#8217;s no claim to originality in this example, I hope that it&#8217;s nonetheless illuminating to see that even an <em>intentionally</em> non-predictive strategy can be mechanically improved.  And we haven&#8217;t even applied all of the lessons of portfolio construction that we might have.  Thus, while writing a worthwhile strategy remains difficult, one can see that there are some very well understood baseline tools that can be mechanically applied to any strategy that will yield material improvements.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.puppetmastertrading.com/blog/2008/09/13/portfolio-atomic-element-of-a-trading-strategy/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>evolution of a strategy</title>
		<link>http://www.puppetmastertrading.com/blog/2008/07/21/evolution-of-a-strategy/</link>
		<comments>http://www.puppetmastertrading.com/blog/2008/07/21/evolution-of-a-strategy/#comments</comments>
		<pubDate>Mon, 21 Jul 2008 15:37:42 +0000</pubDate>
		<dc:creator>tito</dc:creator>
				<category><![CDATA[performance analysis]]></category>
		<category><![CDATA[portfolio management]]></category>
		<category><![CDATA[strategy development]]></category>

		<guid isPermaLink="false">http://www.puppetmastertrading.com/blog-test/?p=73</guid>
		<description><![CDATA[I mentioned several weeks ago that I&#8217;ve been developing and trading a strategy that&#8217;s proven to be quite interesting and profitable.Â In that post, I described how I&#8217;d tried to improve the strategy through the use of a dynamic hedge. The results of that crude hedge were quite good, but just as no worthwhile software [...]]]></description>
			<content:encoded><![CDATA[<p><img alt="(d)evolution" title="(d)evolution" src="http://puppetmastertrading.com/images/devolution.jpg" /></p>
<p>I mentioned several weeks ago that I&#8217;ve been developing and trading a strategy that&#8217;s proven to be quite interesting and profitable.Â  In <a target="_blank" title="Unsung virtues of a dynamic hedge" href="http://puppetmastertrading.com/blog/2008/06/04/unsung-virtues-of-a-dynamic-hedge/">that post</a>, I described how I&#8217;d tried to improve the strategy through the use of a dynamic hedge.  The results of that crude hedge were quite good, but just as no worthwhile software project is ever really complete, trading strategies demand constant iterative development.</p>
<p>Below I describe some of the steps I&#8217;ve taken to incrementally improve this strategy, discarding the relatively expensive hedge I&#8217;d developed earlier in favor of a complementary strategy.  We see that when you combine two positive and uncorrelated results, you end up with a product that is literally better than the sum of its parts.</p>
<p><span id="more-73"></span></p>
<p>The core strategy has remained the same, though the universe of instruments it trades has been both expanded &#8211; through the inclusion of a broader set of equities &#038; ETFs &#8211; and contracted &#8211; through the application of some filters which prevent trading of some of the instruments under various conditions.  These change have yielded a few more points of annualized return with minimal impact on volatility.</p>
<p>As I&#8217;d mentioned, the core strategy builds a portfolio of shorts which is sold at the open and bought back at the close.  One of the problems with the original hedge is that it had a cost &#8211; literally.  In order to hedge my portfolio, I needed to cut-back the size of my portfolio to accommodate the cost of the hedge.  I mitigated this issue to some degree by employing futures instead of a broad market ETF, but this still reduced my usable capital by approximately 10-15%.  I also had my money sitting idle overnight which seemed a particularly profligate behavior.</p>
<p>This led to the study I described <a title="to dream" target="_blank" href="http://puppetmastertrading.com/blog/2008/07/14/to-dream/">last time</a> in which I observed the relative out-performance of the broad US equity markets overnight.  If I could somehow find a way to capture some of this overnight alpha, I&#8217;d be able to both hedge my main strategy and better utilize my capital.</p>
<p>My first effort at such a strategy happily achieves both aims by assembling a long portfolio which is held overnight.  In the chart below, I capture the returns of the two strategies independently and combined.  The core daytime strategy is denoted as &#8220;OpenClose&#8221; or OC whilst the night-time strategy isÂ  &#8220;CountingSheep&#8221; or CS.  Both assume an initial capitalization of $1M, employ no leverage and do not reinvest returns &#8211; each day or night they assemble a portfolio with the same $1M and profits are put aside and don&#8217;t generate interest.</p>
<p><img align="middle" title="NightAndDay NAV Chart" alt="NightAndDay NAV Chart" src="http://puppetmastertrading.com/images/nightAndDayChart.jpg" /></p>
<p>The chart is nice and certainly a big improvement over the earlier hedged approach, but the real power of combining these two strategies is revealed in the two tables below.  The first characterizes their risk-adjusted performance independently and then when combined.  Both have a Sharpe ratio of around 2.0, but when combined they yield a new strategy which is about 25% better on a risk-adjusted basis.  These cells are highlighted.<br />
<img align="middle" title="Returns" alt="Returns" src="http://puppetmastertrading.com/images/nightAndDayReturns.jpg" /></p>
<p>The key to their compatibility is their correlation.  Or, actually, their absence of correlation.  In the below table, you can see the correlations of their returns to one another and broad market ETFs. The short daytime strategy is, not surprisingly, negatively correlated with the broad market while the long night time strategy is positively correlated. The beauty of their combination lies in the lack of correlation between the two of them (highlighted) &#8211; they&#8217;re essentially uncorrelated.</p>
<p><img align="middle" alt="Correlation matrix" title="Correlation matrix" src="http://puppetmastertrading.com/images/nightAndDayCorrs.jpg" /></p>
<p>I hope this post illustrates a couple of different vectors along which strategies can be evolved; in this case, to better manage risk and utilize capital.</p>
<p>One of the key remaining limitations of this particular strategy is its capacity. Increasing the capacity of a relatively short-term strategy like this one requires optimization of the trade executions which is its own black art but one that plenty of smart people are constantly addressing. Perhaps in a future post I&#8217;ll review some of the techniques applied to this problem for another perspective on the iterative development/evolution of trading strategies.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.puppetmastertrading.com/blog/2008/07/21/evolution-of-a-strategy/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>a stat arb story</title>
		<link>http://www.puppetmastertrading.com/blog/2008/07/12/a-stat-arb-story/</link>
		<comments>http://www.puppetmastertrading.com/blog/2008/07/12/a-stat-arb-story/#comments</comments>
		<pubDate>Sat, 12 Jul 2008 15:20:37 +0000</pubDate>
		<dc:creator>tito</dc:creator>
				<category><![CDATA[dereferenced]]></category>
		<category><![CDATA[hedge funds]]></category>
		<category><![CDATA[portfolio management]]></category>
		<category><![CDATA[strategy development]]></category>

		<guid isPermaLink="false">http://www.puppetmastertrading.com/blog-test/?p=67</guid>
		<description><![CDATA[The always excellent Wilmott Magazine has recently posted a series of articles by Ed Thorp (pictured) in which he describes his experiences developing and evolving a statistical arbitrage product.Â Part I provides some insights into his current operation, revealing that he maintains a dollar-neutral portfolio as I&#8217;d discussed in another post, they trade some 1.5 [...]]]></description>
			<content:encoded><![CDATA[<p><img hspace="7" align="left" alt="Ed Thorp" title="Ed Thorp" src="http://puppetmastertrading.com/images/ed_thorp.jpg" />The always excellent <a target="_blank" title="Wilmott" href="http://wilmott.com">Wilmott Magazine</a> has recently posted a series of articles by <a target="_blank" title="Ed Thorp" href="http://en.wikipedia.org/wiki/Edward_O._Thorp">Ed Thorp</a> (pictured) in which he describes his experiences developing and evolving a <a target="_blank" title="Statistical Arbitrage" href="http://en.wikipedia.org/wiki/Statistical_arbitrage">statistical arbitrage</a> product.Â  <a target="_blank" title="Ed Thorp, Statistical Arbitrage - Part I" href="http://puppetmastertrading.com/images/080617_thorp.pdf">Part I</a> provides some insights into his current operation, revealing that he maintains a dollar-neutral portfolio as I&#8217;d discussed in another <a target="_blank" title="Unsung virtues of a dynamic hedge" href="http://puppetmastertrading.com/blog/2008/06/04/unsung-virtues-of-a-dynamic-hedge/">post</a>, they trade some 1.5 billion shares / year, and that they limit position sizes to 2.5% on the long side of the portfolio and 1.5% on the short side. In <a target="_blank" title="Ed Thorp, Statistical Arbitrage - Part II" href="http://puppetmastertrading.com/images/080630_thorp.pdf">Part II</a>, he explains why a stat arb system is considered an &#8220;arbitrage&#8221; and how, with the help of a talented team and led by the insights of Gerry Bamberger, they developed the first iteration of a stat arb product.  <a title="Ed Thorp, Statistical Arbitrage - Part III" target="_blank" href="http://puppetmastertrading.com/images/080709_thorp.pdf">Part III</a> details the evolution of the system from a set of dollar-neutral sector-oriented portfolios to the more general sets of portfolios generated through statistical factor analysis.  He concludes with some anecdotes including the emergence of <a title="David E Shaw" target="_blank" href="http://www.deshaw.com/Founder.html">David E Shaw</a>.  Very recommended.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.puppetmastertrading.com/blog/2008/07/12/a-stat-arb-story/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

