<?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; EMS Internals</title>
	<atom:link href="http://www.puppetmastertrading.com/blog/index.php/category/ems-internals/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>lock free</title>
		<link>http://www.puppetmastertrading.com/blog/2010/02/16/lock-free/</link>
		<comments>http://www.puppetmastertrading.com/blog/2010/02/16/lock-free/#comments</comments>
		<pubDate>Wed, 17 Feb 2010 00:55:38 +0000</pubDate>
		<dc:creator>tito</dc:creator>
				<category><![CDATA[EMS Internals]]></category>
		<category><![CDATA[technology]]></category>

		<guid isPermaLink="false">http://www.puppetmastertrading.com/blog/?p=1010</guid>
		<description><![CDATA[One of the recurring technology themes in these pages has been the ongoing and dramatic move from single to multi-core systems and the need to seriously increase the parallelism in our software designs. For me, one of the seminal, large-grained design patterns was the SEDA Architecture. For years, this informed my systems&#8217; designs and formed [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignright" style="margin-left: 5px; margin-right: 5px;" src="/images/lockfree.jpg" alt="" width="310" height="324" /></p>
<p>One of the recurring technology themes in these pages has been the ongoing and dramatic move from single to multi-core systems and the need to seriously increase the parallelism in our software designs. For me, one of the seminal, large-grained design patterns was the <a title="SEDA Architecture" href="http://www.eecs.harvard.edu/~mdw/proj/seda/" target="_blank">SEDA Architecture</a>. For years, this informed my systems&#8217; designs and formed a conceptual backbone for development. That said, I&#8217;ve been broadly aware for some time that SEDA&#8217;s golden age has (incredibly!) already passed us by, but haven&#8217;t identified what might replace it as a reference point for my design efforts.</p>
<p>Before considering tools, languages or patterns that might help, we need to reflect on the problem(s) we&#8217;re trying to solve. The problems inside an EMS look to me, after years of development, a lot like network routing problems. Indeed, my current view is that this (not just concurrency as I&#8217;d suggested at the time) is why the <a title="FT: Aleynikov indicted" href="http://www.ft.com/cms/s/0/235b1260-1776-11df-87f6-00144feab49a.html" target="_blank">unfortunate</a> Aleynikov &amp; co. at GS were <a title="the other interesting thing about the serge aleynikov story" href="http://www.puppetmastertrading.com/blog/2009/07/08/the-other-interesting-thing-about-the-serge-aleynikov-story/" target="_blank">using erlang</a>.</p>
<p>Why network routing? Think about the load on an EMS. The main issue is that you&#8217;re getting many thousands of teeny little messages per second and only a relatively small number of them matter to only a relatively small subset of &#8216;agents&#8217; within the system. Reducing latency is all about making sure the time you spend on each message is minimized, and that the agents who are interested in a particular message needn&#8217;t wait for each other to do whatever they care to do based on the message. So, really you&#8217;re trying to route each message through your system with as few &#8216;hops&#8217; possible and as much parallelism as you can muster under the (radically!) new assumption that you may have hundreds or thousands of cores available to you during the lifetime of the design.</p>
<p>I spent some time thinking (hoping) that languages might help furnish an answer. Perhaps a move to a functional language like erlang, ocaml or scala might help furnish at least a partial answer. But erlang is slow and peculiar, ocaml doesn&#8217;t support intra-process concurrency and scala looks like a bloated language on a bloated platform (jvm+java class library). And none of them seem to have achieved anything near the critical mass which is so crucial for the development of usable libraries and the availability of skilled developers with long experience in the technology.  Naturally, reasonable people will disagree about such things, but this is my view (today). Java is ok (and certainly sells servers), but it&#8217;s not obvious how it&#8217;s going to help me offload my work onto a GPU anytime soon (and jni is both painful and slow) and I&#8217;ve never been able to get comfortable with just how damn big VMs get.  Image size isn&#8217;t free and if we&#8217;re looking to go deep into the sub-millisecond response time, <em>while running thousands of concurrent strategies</em>, it seems we need to disintermediate the VMs and interpreters of the world. If they&#8217;re really necessary, they can be happily used for the analysis process (as I currently use R), or they can be lit-up and bridged from some lower-level language for batch-like services.</p>
<p>The <a title="greatest technology advertisement ever?" href="http://www.youtube.com/watch?v=jqLPHrCQr2I" target="_blank">good people</a> at Intel have been thinking about this problem for a while as have many other seriously over-educated people. One of the (sensible sounding) conclusions reached as people look for ways to solve problems similar to my own, is that in such systems we should keep messages waiting as little as possible &#8211; ideally, not at all(!). This can be a problem in SEDA-like architectures which are basically made-up of (non-blocking, asynchronous) i/o processes linked to (blocking) queues linking pools of workers. Blocking queues can pile up and cause all sorts of problems like priority inversion and other such enigmatically named nasties. Lock-free queues and other data structures, algos and techniques promise some ways around this and I&#8217;ve been spending time looking into how they might be employed to address my issues.</p>
<p>Before I&#8217;m besieged by throngs of angry erlang/ocaml/scala/java developers, allow me one last observation on the topic.  (Peeved python and ruby users may rant away &#8211; vous m&#8217;amusez  ;^)</p>
<p>Why might a lock free algorithm be better than an equivalent, hardware-based locking implementation?  The answer isn&#8217;t obvious.  If locking is implemented in hardware as is typical (eg, with a compare-and-swap (CAS) instruction), then its explicit cost is measurable in (few) nanoseconds.  Hardware is fast.  The issue isn&#8217;t the speed of execution of the underlying primitives so much as it&#8217;s a consequence of the side effects of these operations at a very low level.  For real performance, cache coherence is King.  See <a title="McKenney: Memory Barriers: a Hardware View for Software Hackers" href="/images/hwViewForSwHackers.pdf" target="_blank">here</a> for an accessible discussion by IBM&#8217;s Paul McKenney and <a title="Ostrovsky: gallery of processor cache effects" href="http://igoro.com/archive/gallery-of-processor-cache-effects/" target="_blank">here</a> for some remarkable examples from Igor Ostrovsky.  This indicates that if you want the highest possible performance, you need to be aware of what is happening &#8216;in the metal.&#8217;  So we need to use a system-level language and erlang, java &amp; friends lose their candidacy in spite of any fantastic benefits they might offer.</p>
<p>Given that even the DoD has mostly given up on ADA means that we&#8217;re left with C/C++.</p>
<p>Ok, so language doesn&#8217;t seem to resolve much for us. (Indeed, it was mostly hopeful thinking on my part – design is mostly language agnostic and hardware is hardware&#8230;)</p>
<p>Apart from Intel&#8217;s own <a title="Intel's Threading Building Blocks" href="http://www.threadingbuildingblocks.org/" target="_blank">Threading Building Blocks (TBB) framework</a>, there are a variety of toolkits available for exploiting lock free parallelism. Perhaps the newest and least known is called <a title="FastFlow parallel programming framework" href="http://calvados.di.unipi.it/dokuwiki/doku.php?id=ffnamespace:about" target="_blank">FastFlow</a>, which is a C++ template library that provides a variety of facilities for writing efficient lock-free network models. It also claims to be faster than TBB, <a title="MIT's Cilk" href="http://supertech.csail.mit.edu/cilk/" target="_blank">Cilk</a> and <a title="OpenMP" href="http://openmp.org/wp/" target="_blank">OpenMP</a> while holding out the promise of one day becoming CUDA- (or more generally, GPU-) aware which would be an incredible win. Finally, it is very small &#8211; the current version (not including tests and examples), weighs in at ~5K lines of (mostly) C++ templates.  Thus, it seems to me particularly well-suited for some experimentation to assess the fit of these techniques in this space and the level of difficulty of doing so.</p>
<p>In the remainder of this post, I&#8217;ll briefly describe the FF design and then illustrate a sample C++ program which uses FastFlow to &#8216;architecturally prototype&#8217; a feed handler interacting with strategies inside an EMS / <a title="containing a strategy" href="http://www.puppetmastertrading.com/blog/2009/08/19/containing-a-strategy/" target="_blank">strategy container</a>.</p>
<p><span id="more-1010"></span></p>
<div class="wp-caption aligncenter" style="width: 509px"><img src="/images/fastflow_architecture.png" alt="FastFlow architecture" width="499" height="382" /><p class="wp-caption-text">FastFlow architecture</p></div>
<p>FastFlow&#8217;s (FF) goals seem quite ambitious, but the design is layered to allow users to work at a level that makes sense for the problems they are trying to solve, so they needn&#8217;t worry themselves (or even understand necessarily) layers below where they need to work.  At bottom is a thin layer of hardware-specific code supporting, one level up, single-producer-single-consumer (SPSC) lock-free queues and a threading model for their efficient interaction.  Above this are defined objects for generalizing from simple to arbitrary network types.  Here you see the definition of a composable Node which serves as the key abstraction for general-purpose streaming networks.  Above this are defined a variety of skeleton templates for building commonly useful graph types.  Because they are Nodes themselves, they can be nested and coupled to any depth.</p>
<p>Consider a simple pipeline:</p>
<div class="wp-caption aligncenter" style="width: 300px"><img title="pipeline" src="/images/ff_pipeline.png" alt="" width="290" height="60" /><p class="wp-caption-text">a simple FastFlow pipeline</p></div>
<p>A farm is slightly more complex and acts something like a load balancing threadpool.  The Emitter pushes &#8216;tasks&#8217; of arbitrary type to an arbitrary number of workers who then coalesce back into an (optional) Collector.  A simple Farm makes no promises about the ordering of tasks, but (I believe) FF provides mechanisms for ensuring their ordering at the collector.</p>
<div class="wp-caption aligncenter" style="width: 300px"><img title="FastFlow Farm" src="/images/ff_farm_with_coll.png" alt="" width="290" height="140" /><p class="wp-caption-text">a FastFlow Farm</p></div>
<p>Finally, because of the composable nature of Nodes, all of these graph types can be combined arbitrarily.  Here you see a Farm of pipelines with an &#8216;accelerator&#8217; (which, if I understand correctly is just an integrated thread for pushing tasks into the network) and a feedback channel.</p>
<div class="wp-caption aligncenter" style="width: 340px"><img title="Composition of subnets" src="/images/ff_composition2.png" alt="" width="330" height="140" /><p class="wp-caption-text">composition of FastFlow subnets</p></div>
<p>For a more complete (and probably accurate!) description of FastFlow, I encourage you to visit their site and <a title="FastFlow Tutorial" href="http://calvados.di.unipi.it/dokuwiki/doku.php?id=ffnamespace:usermanual" target="_blank">tutorial</a>.  The documentation remains limited, but there&#8217;s a good and growing selection of examples to examine and all of the source is available for inspection.</p>
<p><strong>a simple example</strong></p>
<p>Given my use-case, my first interest is in seeing how FastFlow might work in the context of asynchronous, non-blocking network handling.  To this end, I&#8217;ve built a simple Farm as depicted above in which the Emitter uses <strong>select()</strong> to read messages off the network which it parses and pushes into the farm for &#8216;processing&#8217; which is currently <a title="Wiki: NOP" href="http://en.wikipedia.org/wiki/NOP" target="_blank">NOP</a>-ed.  The messages/tasks are then coalesced into a collector which does nothing more than free memory allocated in the Emitter.  Within the Farm, each of the nodes inhabits its own thread and outside of the farm I&#8217;ve implemented a very simple &#8216;client&#8217; which connects to the Emitter&#8217;s socket and sends delimited Integral &#8216;messages.&#8217;  Ordinarily this would appear in its own process, but for the sake of only requiring 1 file, I&#8217;ve mashed them all together and the client lives in its own thread.  That&#8217;s it.</p>
<p>It turns out that the FastFlow part of this is, by far, the simplest.  Since the FF skeletons are implemented as templates, extending them couldn&#8217;t be much easier.  Here&#8217;s the definition of the worker and collector components.</p>
<pre class="brush: cpp; title: ; notranslate">
// typical worker: does little ;^p
class Worker: public ff_node {
public:
  void * svc(void * task) {
    return task;
  }
};

// collector that just frees the malloc'ed memory
class freeing_collector: public ff_node {
public:
  void * svc(void * task) {
    int * t = (int *)task;
    if (*t == -1) return NULL;
    else free(task);
    return GO_ON;
  }
};
</pre>
<p>They are both nodes and their only requirement is to implement the <strong>svc</strong> method which is called by the FF framework when they are meant to service a task.  They can optionally implement <strong>svc_init</strong> and <strong>svc_end </strong>methods which provide an opportunity for initialization and cleanup.  The socket-reading emitter makes use of the <strong>svc_init</strong> method to initially setup the socket.  Later, as it repeatedly reads from the socket into a buffer, it cracks the incoming stream and then calls the <strong>ff_send_out()</strong> method to push those messages out to the downstream workers.  The whole example is about 350 lines of code and nearly 200 lines are consumed by the Emitter.  Almost all of this bulk is network-related, so I won&#8217;t illustrate here.  But highlighted here you can see the main FF-specific part of the Emitter:</p>
<pre class="brush: cpp; highlight: [16,17,18,19]; title: ; notranslate">
 // handle new data coming in
 void new_data(int nbytes, const char* buf) {
   static char remainder[kMaxMsgSz];
   int *t;
   int j = 0;
   int i = 0;
   char msgbuf[kMaxMsgSz];
   for (; i &lt; nbytes; i++) {
     if ( kDelimiter == buf[i] ) {
       int rlen = (j==0) ? strlen(remainder) : 0; // remainder?
       int len = i-j;
       if (rlen&gt;0) strncpy(msgbuf,remainder,rlen);
       int start = (rlen==0) ? 0 : rlen;
       strncpy(&amp;(msgbuf[start]),&amp;(buf[j]),len);
       msgbuf[len+rlen] = '&#92;&#48;';
       t = (int *)malloc(sizeof(int));
       *t = atoi(msgbuf);
       j = i;
       ff_send_out(t);  // push message into farm
     }
   } // for

   int k = j+1;
   if (k &lt; i) { // save 'remainder'
     strncpy(remainder,&amp;(buf[k]),(i-k));
   } else remainder[0] = '&#92;&#48;';
 }
</pre>
<p>Finally, all of the pieces are assembled and launched in the<strong> main()</strong>.</p>
<pre class="brush: cpp; title: ; notranslate">
//  We construct a 'server' which is a fastflow emitter and which reads
//    integral 'msgs' from a client over a non-blocking socket.  Msgs
//    are parsed and fed into a fastflow farm for further handling.
//    The client is placed within its own thread - this is only so the
//    whole example can be placed in one file.
//
int main(int argc, char * argv[]) {
 // use: argv[0] &lt;#msgs=1024&gt; &lt;#port=9999&gt;

 int msgs = (argc &gt; 1) ? atoi(argv[1]) : 1024;
 int port = (argc &gt; 2) ? atoi(argv[2]) : 9999;

 int nworkers = 5;               // how many workers will recv msgs

 printf(&quot;main: sending #%d msgs to port &lt;%d&gt;\n&quot;,msgs,port);

 select_reader sr(port);         // we create 'server'
 freeing_collector fc;           // and a freeing collector
 ff_farm&lt;&gt; farm;                 // and a farm for it to live in
 farm.add_emitter(&amp;sr);          // add both to the farm
 farm.add_collector(&amp;fc);

 std::vector&lt;ff_node *&gt; workers; // build a collection of workers
 for(int i =0; i &lt; nworkers; i++) { workers.push_back(new Worker); }

 farm.add_workers(workers);      // add all workers to the farm

 farm.run();                     // launch the farm
 printf(&quot;main: started farm.\n&quot;);

 sr.wait_til_ready();            // don't create client til srvr ready

 // create client which will send msgs via socket
 //
 printf(&quot;main: creating client...\n&quot;);
 client_thread* client = new client_thread(msgs,port);
 if (client != NULL) client-&gt;join();

 farm.wait();                    // wait for farm to be done its workload

 // emit some stats
#if defined(TRACE_FASTFLOW)
 std::cout &lt;&lt; &quot;DONE, time= &quot; &lt;&lt; farm.ffTime() &lt;&lt; &quot; (ms)\n&quot;;
 farm.ffStats(std::cout);
#endif

 return 0;
}
</pre>
<p>The whole example can be found <a title="FF networking example: C++ source" href="/images/ttest.cpp" target="_blank">here</a>.</p>
<p>Writing this example was a bit of a &#8216;tale of two frameworks&#8217; for me as I found the FastFlow part to be really easy and powerful.  On the other hand, I wanted to try out the <a title="boost::asio" href="http://www.boost.org/doc/libs/1_37_0/doc/html/boost_asio.html" target="_blank">boost::asio</a> framework for non-blocking networking i/o (primarily in the hope it might cut down the code size a bit) and while implementing the trivial (blocking) client was, well, trivial, implementing a non-blocking server with boost::asio was a serious pain and I ultimately decided that <a title="Linus' screed on C++ and boost" href="http://thread.gmane.org/gmane.comp.version-control.git/57643/focus=57918" target="_blank">Linus just might be on to something wrt to boost</a> and scrapped that part of the effort (but kept the boost client).</p>
<p>Nothing about this example illuminates the potential performance advantages of a lock free approach, but this exercise has certainly convinced me that the FF authors have managed to combine very low-level performance considerations within a package which can be easily used from a high-level perspective.  Most problems will most likely be better served by higher-level programming languages, but some problems remain intractably bound to the metal and I suspect that writing ultra-low-latency trading systems will remain in the latter class for some time to come.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.puppetmastertrading.com/blog/2010/02/16/lock-free/feed/</wfw:commentRss>
		<slash:comments>10</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>Kooderive</title>
		<link>http://www.puppetmastertrading.com/blog/2010/02/03/kooderive/</link>
		<comments>http://www.puppetmastertrading.com/blog/2010/02/03/kooderive/#comments</comments>
		<pubDate>Wed, 03 Feb 2010 15:31:20 +0000</pubDate>
		<dc:creator>tito</dc:creator>
				<category><![CDATA[dereferenced]]></category>
		<category><![CDATA[EMS Internals]]></category>
		<category><![CDATA[monte-carlo methods]]></category>
		<category><![CDATA[open-source software]]></category>
		<category><![CDATA[options pricing]]></category>
		<category><![CDATA[technology]]></category>

		<guid isPermaLink="false">http://www.puppetmastertrading.com/blog/?p=1000</guid>
		<description><![CDATA[Some time back, I&#8217;d written about NVidia&#8217;s CUDA noting that it looked ideal for many asset-pricing and monte-carlo type problems in finance.  At the time, I was hopeful that it would be quickly integrated into existing open source efforts like QuantLib, but adoption has proved slower than I&#8217;d hoped, most likely because implementing non-trivial problems [...]]]></description>
			<content:encoded><![CDATA[<div class="wp-caption alignleft" style="width: 240px"><img class="   " src="/images/cuda_simonRogerson.jpg" alt="photo by Simon Rogerson" width="230" height="173" /><p class="wp-caption-text">photo by Simon Rogerson</p></div>
<p>Some time back, I&#8217;d <a title="TESLA &amp; CUDA" href="http://www.puppetmastertrading.com/blog/2008/11/29/nvidias-tesla-and-the-compute-unified-device-architecture/" target="_blank">written</a> about NVidia&#8217;s CUDA noting that it looked ideal for many asset-pricing and monte-carlo type problems in finance.  At the time, I was hopeful that it would be quickly integrated into existing open source efforts like <a title="QuantLib: a free/open-source library for quantitative finance" href="http://quantlib.org/" target="_blank">QuantLib</a>, but adoption has proved slower than I&#8217;d hoped, most likely because implementing non-trivial problems on CUDA is, well, even less trivial than doing them without..</p>
<p><strong>LMM on CUDA</strong></p>
<p><strong> </strong>Happily, I&#8217;ve just seen a promising first step in this direction as Über-quant and C++ artisan <a title="Mark Joshi" href="http://www.markjoshi.com/" target="_blank">Mark Joshi</a> recently announced an open-source project, <a title="Sourceforge: Kooderive" href="http://sourceforge.net/projects/kooderive/" target="_blank">Kooderive</a> which looks to implement the <a title="Wiki: LMM" href="http://en.wikipedia.org/wiki/LIBOR_market_model" target="_blank">LIBOR Market Model</a> (LMM)  on top of CUDA.  His announcement on the QuantLib mailing lists reads:</p>
<blockquote><p>Dear All,</p>
<p>various people have shown interest in the use of <span id="lw_1265210335_0">CUDA</span> with QuantLib. I<br />
have now made some progress on a CUDA implementation of the <span id="lw_1265210335_1" style="border-bottom: 1px dashed #0066cc; background: transparent none repeat scroll 0% 0%; cursor: pointer;">LIBOR<br />
market model</span>.</p>
<p>In particular, I now have a path generator for the LMM working which<br />
does 16384 paths for 40 rates, 40 steps, 5 factor model, displaced<br />
diffusion predictor-corrector that takes 0.1 seconds on my Quadro 4600.</p>
<p>The state of the project is code fragments that can be called from<br />
other code. Those who are interested can get the code via<br />
the subversion repository on <a href="http://kooderive.sourceforge.net/" target="_blank"><span id="lw_1265210335_2">kooderive.sourceforge.net</span></a> .  The only<br />
project file is currently for VC9 x64. It also uses thrust and the<br />
CUDA SDK.</p>
<p>The next stage will be writing routines, that use QuantLib for the CPU<br />
stuff and kooderive for the GPU stuff,  to actually price things.</p>
<p>A gentle reminder that I will be giving a course on the LMM and<br />
QuantLib in June in <span id="lw_1265210335_3" style="background: transparent none repeat scroll 0% 0%; cursor: pointer;">London</span>, and I will include a session on kooderive<br />
if there<br />
is sufficient interest.</p>
<p>I am happy to take code contributions for kooderive. However, I am not<br />
looking for a redesign of the library or contributions which introduce<br />
dependence on other libraries. I am interested in contributions of<br />
separate routines and of optimizations of existing routines that do<br />
not change interfaces.</p>
<p>regards</p>
<p>Mark<br />
&#8211;<br />
Pricing exotic <span id="lw_1265210335_4" style="border-bottom: 1px dashed #0066cc; background: transparent none repeat scroll 0% 0%; cursor: pointer;">interest rate derivatives</span> &#8211; The <span id="lw_1265210335_5" style="background: transparent none repeat scroll 0% 0%; cursor: pointer;">LIBOR Market Model</span> in<br />
QuantLib <span id="lw_1265210335_6" style="border-bottom: 1px dashed #0066cc; cursor: pointer;">June 2010</span>, London,<br />
<a href="http://www.moneyscience.com/training/index.html" target="_blank"><span id="lw_1265210335_7">http://www.moneyscience.com/training/index.html</span></a></p>
<p>Assoc Prof Mark Joshi<br />
Centre for Actuarial Studies<br />
<span id="lw_1265210335_8">University of Melbourne</span><br />
My website is <a href="http://www.markjoshi.com/" target="_blank"><span id="lw_1265210335_9">www.markjoshi.com</span></a></p></blockquote>
<p><span><br />
</span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.puppetmastertrading.com/blog/2010/02/03/kooderive/feed/</wfw:commentRss>
		<slash:comments>1</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 [...]]]></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[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>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[back-testing]]></category>
		<category><![CDATA[EMS Internals]]></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 [...]]]></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[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>our solid-state future</title>
		<link>http://www.puppetmastertrading.com/blog/2009/09/04/our-solid-state-future/</link>
		<comments>http://www.puppetmastertrading.com/blog/2009/09/04/our-solid-state-future/#comments</comments>
		<pubDate>Fri, 04 Sep 2009 12:58:23 +0000</pubDate>
		<dc:creator>tito</dc:creator>
				<category><![CDATA[EMS Internals]]></category>
		<category><![CDATA[market data]]></category>
		<category><![CDATA[technology]]></category>

		<guid isPermaLink="false">http://www.puppetmastertrading.com/blog/?p=577</guid>
		<description><![CDATA[I&#8217;ve never been a hardware guy. Hardware has gotten so fast throughout my professional life that it has just never been a big issue. Also, on wall st we had a robust and annual budget for h/w so I&#8217;d routinely sign-off on hundreds of thousands of dollars on all sorts of machines I&#8217;d never lay [...]]]></description>
			<content:encoded><![CDATA[<div class="wp-caption alignleft" style="width: 260px"><img src="/images/solidStateFuture.jpg" alt="Mmmm... hardware.." width="250" height="249" /><p class="wp-caption-text">Mmmm... hardware..</p></div>
<p>I&#8217;ve never been a hardware guy. Hardware has gotten so fast throughout my professional life that it has just never been a big issue. Also, on wall st we had a robust and annual budget for h/w so I&#8217;d routinely sign-off on hundreds of thousands of dollars on all sorts of machines I&#8217;d never lay eyes on and somehow they always did the trick.</p>
<p>Before 9/11, they&#8217;d be in server racks in the building or down the street, but since then they might also be in increasingly far-flung places like weehawken or long island, tampa, even texas or beyond. The machines always seemed unbelievably overpriced &#8211; I remember over the years pretty consistently paying something like $40K for a low-end db server.  But that&#8217;s what it cost and you could only purchase approved products from approved channels, so nobody spent much thought on it.  Now that I don&#8217;t have the same kinds of constraints &#8211; or budgets! &#8211; I increasingly have to think of hardware.</p>
<p>As a software engineer, the hardware itself is also insisting that I pay some uncharacteristic attention to it.  The evolution of processors has reached a point where the programming paradigms many of us have fruitfully employed over many years are no longer suited for getting full performance out of today&#8217;s machines.  The recent introduction of remarkably powerful and inexpensive parallel-computing platforms based on GPUs like <a title="CUDA" href="http://www.puppetmastertrading.com/blog/2008/11/29/nvidias-tesla-and-the-compute-unified-device-architecture/" target="_blank">nvidia&#8217;s cuda</a> also outline a future that even current university training doesn&#8217;t address in a fashion practically adapted for institutional application.  Cores are multiplying like Tribbles.</p>
<p>The lines between persistent storage and main memory are also blurring as consumer SSDs push up from the &#8216;low&#8217;-end while exotic ioDrives and the like offer a glimpse of a world where the performance gap between the two approaches nil and after their long reign myriad metallic platters will spin no more.</p>
<p><span id="more-577"></span></p>
<p style="text-align: left;">
<div class="wp-caption aligncenter" style="width: 498px"><img class=" " src="/images/power7-die.jpg" alt="troubling like Tribbles" width="488" height="386" /><p class="wp-caption-text">troubling like Tribbles</p></div>
<p>There have been some steps taken towards taming the core dilemma.  Google&#8217;s introduction of the distributed map-reduce paradigm and all of the associated plumbing on top of computers in the &#8216;cloud&#8217; is probably the boldest and most effective reaction thus far, but it&#8217;s not always obvious that you want your stuff running in someone else&#8217;s cloud amongst many other natural limitations of this approach.  This is also a solution &#8216;in the large&#8217; and sometimes you need performant solutions on a different, smaller scale.  Here, the development of functional languages and idioms may be of some help, but there certainly don&#8217;t seem to be clear winners yet.</p>
<p>Erlang, Ocaml, Haskell, Scala and others all seem to have very limited impact thus far and all face big challenges before receiving widespread welcome.  Worse, any language can be mangled into expressing things poorly so the languages can only be a meaningful aid to programmers who are able to adjust their mindset for a new world&#8217;s computing paradigm.  This likely won&#8217;t be easy for many until there is an established set of usable programming idioms and toolsets for dealing with concurrency on a whole new scale.  To me, it seems that functional programming might well be an important part of that, but it&#8217;s difficult to imagine it as the complete game changer any time soon.  As it is, many of us have already been using functional languages (in my case, sql and R) on a regular or even daily basis for a long time, so it&#8217;s difficult to cast this as the revolution, bottled.</p>
<p>As cores proliferate and the bandwidth amongst them increases, new challenges and opportunities are unveiled.  Feeding all of those hungry cores can be a chore.  If you already had problems with i/o bound processes, then adding cores is sort of like adding liquidity to a debt crisis &#8211; not obviously helpful. We faced an issue like this recently while trying to improve the throughput of our backtesting subsystem in particularly poor-performing cases.</p>
<p>In these cases, we use daily data to initialize an intraday strategy.  For example, we might look at all equities over a trailing 3 or 5-year period, and perform various analytics – like calculating correlation matrices, beta against various benchmarks, volatility, etc – to determine which names might be candidates for the strategy’s portfolio.  We found that an inordinate amount of our time was spent just performing these morning analytics and that the cost of a day’s backtest was significantly spent on this oft-repeated morning exercise.  While working through this issue, we noted that we’ve reached a point where a decent, dual nehalem, server (with 16 logical cores) could be built with 48G of RAM for something along the lines of $6K.  Seriously.  So we stuck all of our daily data into memory and the improvement has been essentially infinite.  Maybe not the best example, but hopefully illustrative of the fact that the h/w underneath us is changing qualitatively and that we need to be more active in involving it in our design decisions.</p>
<p>Of course, even a yawning expanse like 48G or even a terabyte (in not too many years, after all, I should be able to buy 1T of RAM for my boxes at a similar price point to what I pay for 48G today), eventually gets consumed and so we can’t hope to employ this solution for all our problems.  We continue to develop our historical TAQ infrastructure (most recently discussed <a title="tick data and hdf5" href="../2009/01/06/tick-data-hdf5-part-2/" target="_blank">here</a>) and this is certainly an example where buying memory isn’t going to get you very far.  But SSDs now are getting reasonable and so our current approach uses memory as much as possible but when it needs to get volumes of detailed historical data we’ve placed our indices onto SSDs while the actual stores themselves reside on much more affordable RAID arrays.  Reading indices is now much faster and adds minimal i/o overhead to a very i/o-bound problem.</p>
<p>By constantly looking at new languages and concurrency idioms, vigilantly assessing the current and projected costs of ’solid-state’-solutions to our most vexing problems, and just staying active and creative, we hold out some hope that we can transition gracefully to what is looking increasingly like a solid-state future.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.puppetmastertrading.com/blog/2009/09/04/our-solid-state-future/feed/</wfw:commentRss>
		<slash:comments>0</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>
	</channel>
</rss>

