<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>WK&#039;s High Frequency Trading Blog</title>
	<atom:link href="http://howtohft.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://howtohft.wordpress.com</link>
	<description>An experienced quant/developer discusses the practice of high frequency trading.</description>
	<lastBuildDate>Wed, 06 Apr 2011 21:10:50 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='howtohft.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>WK&#039;s High Frequency Trading Blog</title>
		<link>http://howtohft.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://howtohft.wordpress.com/osd.xml" title="WK&#039;s High Frequency Trading Blog" />
	<atom:link rel='hub' href='http://howtohft.wordpress.com/?pushpress=hub'/>
		<item>
		<title>The Quant Cup</title>
		<link>http://howtohft.wordpress.com/2011/03/04/the-quant-cup/</link>
		<comments>http://howtohft.wordpress.com/2011/03/04/the-quant-cup/#comments</comments>
		<pubDate>Fri, 04 Mar 2011 15:54:09 +0000</pubDate>
		<dc:creator>wkselph</dc:creator>
				<category><![CDATA[Trading]]></category>

		<guid isPermaLink="false">http://howtohft.wordpress.com/?p=39</guid>
		<description><![CDATA[My friend Max Dama is holding a $15,000 programming contest for university students to build the fastest implementation of a limit order book.  Check it out at quantcup.org.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=howtohft.wordpress.com&amp;blog=20091585&amp;post=39&amp;subd=howtohft&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>My friend <a href="http://maxdama.com">Max Dama</a> is holding a $15,000 programming contest for university students to build the fastest implementation of a <a title="How to Build a Fast Limit Order Book" href="http://howtohft.wordpress.com/2011/02/15/how-to-build-a-fast-limit-order-book/">limit order book</a>.  Check it out at <a href="http://www.quantcup.org">quantcup.org</a>.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/howtohft.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/howtohft.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/howtohft.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/howtohft.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/howtohft.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/howtohft.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/howtohft.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/howtohft.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/howtohft.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/howtohft.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/howtohft.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/howtohft.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/howtohft.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/howtohft.wordpress.com/39/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=howtohft.wordpress.com&amp;blog=20091585&amp;post=39&amp;subd=howtohft&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://howtohft.wordpress.com/2011/03/04/the-quant-cup/feed/</wfw:commentRss>
		<slash:comments>20</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">howtohft</media:title>
		</media:content>
	</item>
		<item>
		<title>Modeling and Smoothness</title>
		<link>http://howtohft.wordpress.com/2011/03/01/modeling-and-smoothness/</link>
		<comments>http://howtohft.wordpress.com/2011/03/01/modeling-and-smoothness/#comments</comments>
		<pubDate>Tue, 01 Mar 2011 08:02:17 +0000</pubDate>
		<dc:creator>wkselph</dc:creator>
				<category><![CDATA[Modeling]]></category>
		<category><![CDATA[Trading]]></category>
		<category><![CDATA[high frequency trading]]></category>
		<category><![CDATA[modeling]]></category>
		<category><![CDATA[trading systems]]></category>

		<guid isPermaLink="false">http://howtohft.wordpress.com/?p=34</guid>
		<description><![CDATA[When designing trading models, the sensitivity of the algorithm to both the market and the model parameters is a key concern.  Ideally, a model should be &#8220;smooth&#8221; in the sense that small variations in parameters or market conditions should cause small (for some definition of small) variations in the model behavior.  Non-smooth models will of [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=howtohft.wordpress.com&amp;blog=20091585&amp;post=34&amp;subd=howtohft&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><!-- p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica} p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px} -->When designing trading models, the sensitivity of the algorithm to both the market and the model parameters is a key concern.  Ideally, a model should be &#8220;smooth&#8221; in the sense that small variations in parameters or market conditions should cause small (for some definition of small) variations in the model behavior.  Non-smooth models will of course have behavior that is much harder to predict because future market conditions and optimal parameterizations are never known with certainty, meaning that a region of the parameter space that is expected to perform well could actually perform poorly.  This probably seems like a fairly obvious point to most readers but avoiding this difficulty isn&#8217;t necessarily trivial&#8211;many modeling ideas with intuitive appeal have this problem.</p>
<p>One of the most common signs of a non-smooth model is the presence of triggers or switches that toggle the behavior between different modes.  For example, consider a simple model trading a single stock with one parameter p: the model sells one hundred shares when the stock price reaches p but doesn&#8217;t do anything else.  If the price of the stock starts at p-a and goes to p-1 then back down to p-a, the model makes 0 dollars profit.  If instead the price does something slightly different and goes from p-a to p then back to p-a, the model makes 100*a dollars.  This model is therefore very sensitive to both small variations in the market and the parameter p, which will make deciding what p should be difficult.</p>
<p>In analysis of models with non-smooth surfaces, very often the &#8220;optimal&#8221; region of the parameter space will be near the edge of one of these discontinuities because this is where the profit potential is often highest.  The discontinuity makes the model unpredictable, but it can also make the model very profitable when it happens to be correct.  Naive optimizations on these non-smooth surfaces will simply pick which points along the edges of a discontinuity happen to have performed best, turning what should be a well-behaved continuous optimization that considers the shape of the parameter space into an operation that simply totals up a number of discrete events.</p>
<p>If we modify the model above to sell shares continuously as the price moves from p-a to p, we suddenly have a much smoother model.  It will not make as much money as the price moves from p-a to p back to p-a, but it will make money for any p &gt; p-a and price movement from p-a to p-b back to p-a, with b &lt; a.  This will result in a much broader &#8220;optimal&#8221; region in the parameter space and give it a well defined shape that can be analyzed.</p>
<p>In general, it is best to make the state of a trading system be as much as possible a smooth function of market variables rather than a piecemeal summation of discrete events.  This tends to both make the parameter space easier to analyze and give the model a more stable behavior.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/howtohft.wordpress.com/34/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/howtohft.wordpress.com/34/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/howtohft.wordpress.com/34/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/howtohft.wordpress.com/34/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/howtohft.wordpress.com/34/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/howtohft.wordpress.com/34/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/howtohft.wordpress.com/34/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/howtohft.wordpress.com/34/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/howtohft.wordpress.com/34/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/howtohft.wordpress.com/34/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/howtohft.wordpress.com/34/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/howtohft.wordpress.com/34/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/howtohft.wordpress.com/34/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/howtohft.wordpress.com/34/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=howtohft.wordpress.com&amp;blog=20091585&amp;post=34&amp;subd=howtohft&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://howtohft.wordpress.com/2011/03/01/modeling-and-smoothness/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">howtohft</media:title>
		</media:content>
	</item>
		<item>
		<title>Trading System Testability</title>
		<link>http://howtohft.wordpress.com/2011/02/16/trading-system-testability/</link>
		<comments>http://howtohft.wordpress.com/2011/02/16/trading-system-testability/#comments</comments>
		<pubDate>Wed, 16 Feb 2011 07:44:51 +0000</pubDate>
		<dc:creator>wkselph</dc:creator>
				<category><![CDATA[Trading]]></category>
		<category><![CDATA[high frequency trading]]></category>
		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">http://howtohft.wordpress.com/?p=26</guid>
		<description><![CDATA[Testability is, in my opinion, the single most important requirement of a trading system design. The reason is pretty obvious: running a buggy high frequency trading system is a very efficient way to lose money.  The question, then, of how the system will be thoroughly tested needs to be answered from the outset. Because of the massive data volumes, [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=howtohft.wordpress.com&amp;blog=20091585&amp;post=26&amp;subd=howtohft&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><!-- p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Times} p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Times; min-height: 14.0px} -->Testability is, in my opinion, the single most important requirement of a trading system design. The reason is pretty obvious: running a buggy high frequency trading system is a very efficient way to lose money.  The question, then, of how the system will be thoroughly tested needs to be answered from the outset.</p>
<p>Because of the massive data volumes, a high frequency trading system is very likely to have to deal with extraordinary or unanticipated situations that a system under less stringent performance requirements might be able to ignore or handle outside of the normal mode of operation.  Some typical &#8220;unanticipated&#8221; situations are:</p>
<ul>
<li>Messages arriving out of order from the market and/or brokerage</li>
<li>Race conditions between in-transit messages</li>
<li>Missing messages</li>
<li>Unintended concurrent states among components of the trading system</li>
</ul>
<p>It is very difficult to anticipate these situations and handle them correctly. But if they are not handled, then the system will (probably) lose a lot of money when they&#8217;re encountered.  That a trading system can be tested for its response to unanticipated situations without money on the line is therefore an absolute requirement.</p>
<p>(The system should also, of course, have very good unit test coverage, but unit tests only test anticipated situations.)</p>
<p>How does one test for unanticipated situations?  Automated trading systems are driven by market data and, fortunately, most data feeds provide many years of historical data that can be used in place of a live feed.  So building a trading system to be able to run offline against historical data is a very good way to do it.  Random data can also be generated from a limit order book model (see <a href="http://papers.ssrn.com/sol3/papers.cfm?abstract_id=970358">this paper</a>, for example).</p>
<p>Data feeders for every source of trading system input can be built to simulate a real market day as realistically as possible.  For systems that take in multiple data feeds, this means joining the feeds and delivering the messages in the order they would appear live. Simulated execution messages can also be generated and delivered in a realistic way.  Features like the ability to play back a feed at real time speeds (so events that happened two seconds apart arrive at the trading system two seconds apart) can also be very useful.</p>
<p>Ideally, the offline trading system will be identical to the online system, running through all the same code, just with different sources of input.  To be efficient, though, so that many days of data can be tested very quickly, it is usually best to run offline tests in a single threaded mode.  If information is passed between system components with message queues, this can be done by reimplementing the message queue interfaces so that messages are just passed through and processed instead of enqueued.  These singly-threaded processes can then be run concurrently on a multiprocessor machine to rapidly test many days of data.</p>
<p>It is easiest to make a trading system like this testable if the state and behavior of the trading logic are fully determined by a set of incident messages, that is, the message queue is the only source of information for making trading decisions.  If it is not, it will be more difficult to have confidence that a given testing setup will present realistic scenarios to the trading system.</p>
<p>Trading system testability is a large topic, however, and I&#8217;ve only talked about some of the key ideas in this post.  Future posts will go into more detail and tie them to discussions of market modeling and data analysis.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/howtohft.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/howtohft.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/howtohft.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/howtohft.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/howtohft.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/howtohft.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/howtohft.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/howtohft.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/howtohft.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/howtohft.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/howtohft.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/howtohft.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/howtohft.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/howtohft.wordpress.com/26/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=howtohft.wordpress.com&amp;blog=20091585&amp;post=26&amp;subd=howtohft&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://howtohft.wordpress.com/2011/02/16/trading-system-testability/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">howtohft</media:title>
		</media:content>
	</item>
		<item>
		<title>Bootstrapping a HFT Firm</title>
		<link>http://howtohft.wordpress.com/2011/02/15/bootstrapping-a-hft-firm/</link>
		<comments>http://howtohft.wordpress.com/2011/02/15/bootstrapping-a-hft-firm/#comments</comments>
		<pubDate>Tue, 15 Feb 2011 18:56:04 +0000</pubDate>
		<dc:creator>wkselph</dc:creator>
				<category><![CDATA[Business]]></category>
		<category><![CDATA[bootstrapping]]></category>
		<category><![CDATA[high frequency trading]]></category>
		<category><![CDATA[negotiation]]></category>
		<category><![CDATA[startups]]></category>

		<guid isPermaLink="false">http://howtohft.wordpress.com/?p=20</guid>
		<description><![CDATA[In my first post I described two &#8220;chicken and egg&#8221; problems that any startup high frequency trading firm will need to solve: that of acquiring trading capital without a track record, and that of negotiating a low per-trade (or per-share) cost without having high trading volume. In this post I&#8217;m going to describe some of [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=howtohft.wordpress.com&amp;blog=20091585&amp;post=20&amp;subd=howtohft&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>In my first post I described two &#8220;chicken and egg&#8221; problems that any startup high frequency trading firm will need to solve: that of acquiring trading capital without a track record, and that of negotiating a low per-trade (or per-share) cost without having high trading volume. In this post I&#8217;m going to describe some of the tactics we used to overcome these problems. Hopefully some of these ideas will be useful to would-be startup HF traders.</p>
<p>The nature of a HFT startup is such that the trading technology and the business agreements must evolve together&#8211;which is a point I touched on in my first post&#8211;because one very rigidly defines the constraints on the other. For this reason, I believe that starting a HFT firm, without a large amount of capital to burn, requires beginning with a lower frequency model that can be made economical with whatever trading costs are presently achievable and then scaling up to higher frequencies as they become feasible. Fortunately, there is more than one way to scale up a model&#8217;s volume: it can either trade the same instruments more frequently (or with larger trade sizes), or it can trade more instruments at the same frequency. Unfortunately, the differences between trading at low and high frequencies make it unlikely that a single algorithm, however parameterized, will be able to achieve this, which implies that bootstrapping a firm&#8217;s trading to high frequencies will require several fundamental shifts in the trading technology&#8211;each of which must be successful.</p>
<p>The goal at each technology iteration is to build a track record of success while trading at the highest speeds that are economical because, unsurprisingly, acquiring lower trading costs means convincing those that have them to give that they will benefit from providing them. &#8220;Economical&#8221; in this case, though, does not necessarily mean profitable; arguing, with the benefit of a sizable trading record, that a strategy would have been profitable if trading costs were lower is a good way to get trading costs lowered. It may in fact be a prudent business strategy to trade &#8220;too fast&#8221; for the extant commission structure so that this argument can be made.</p>
<p>Smaller brokerages will be especially receptive to this kind of argument. They will often be more willing to take risks to increase the volume they handle because having more volume to offer will in turn allow them to negotiate better terms with clearing firms and exchanges and allow them to attract higher quality clients. It is important, though, to not get too entangled with any particular brokerage because a primary source of negotiating leverage will be the threat to take one&#8217;s business elsewhere.</p>
<p>Of course arguments based on a real track record will also be convincing to those that have trading capital to invest, especially if the track record is built with an eye to demonstrating scalability. Scalability across instruments is the most straightforward to demonstrate, arguing, for example, &#8220;we traded instruments A and B for a month and then traded C and D another month and were profitable both months, so we&#8217;ll be even more profitable if we can trade all four.&#8221; Scalability within a strategy is also valuable to demonstrate: it can be done by varying the capital allocation between strategies even when it would be more prudent from a financial perspective to allocate the capital more evenly. Ultimately the only way to be able to trade with a large amount of capital is to trade successfully with a smaller amount.</p>
<p>Building a track record of success while bootstrapping the trading technology is the key to solving the &#8220;chicken and egg&#8221; problems of starting a HFT firm. This requires that one trade tactically, however, not just with respect to the market but also with respect to ongoing business relationships. Depending on the profitability of the trading strategies, the amount of capital a firm has available to trade may not be enough to make focusing on profit worthwhile; the sole purpose of trading, then, should be to make the strongest case possible that trading costs should be lowered and more capital provided. Making this case repeatedly is how to build a HFT firm.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/howtohft.wordpress.com/20/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/howtohft.wordpress.com/20/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/howtohft.wordpress.com/20/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/howtohft.wordpress.com/20/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/howtohft.wordpress.com/20/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/howtohft.wordpress.com/20/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/howtohft.wordpress.com/20/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/howtohft.wordpress.com/20/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/howtohft.wordpress.com/20/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/howtohft.wordpress.com/20/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/howtohft.wordpress.com/20/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/howtohft.wordpress.com/20/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/howtohft.wordpress.com/20/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/howtohft.wordpress.com/20/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=howtohft.wordpress.com&amp;blog=20091585&amp;post=20&amp;subd=howtohft&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://howtohft.wordpress.com/2011/02/15/bootstrapping-a-hft-firm/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">howtohft</media:title>
		</media:content>
	</item>
		<item>
		<title>Message Queues</title>
		<link>http://howtohft.wordpress.com/2011/02/15/message-queues/</link>
		<comments>http://howtohft.wordpress.com/2011/02/15/message-queues/#comments</comments>
		<pubDate>Tue, 15 Feb 2011 18:55:00 +0000</pubDate>
		<dc:creator>wkselph</dc:creator>
				<category><![CDATA[Trading]]></category>
		<category><![CDATA[high frequency trading]]></category>
		<category><![CDATA[message queues]]></category>
		<category><![CDATA[threading]]></category>

		<guid isPermaLink="false">http://howtohft.wordpress.com/?p=18</guid>
		<description><![CDATA[In an earlier post I talked about the need to make the implementation of a limit order book as fast as possible because of the very high data rate typical of market data feeds. Another important set of structures to make correct are the queues the trading system will use to pass messages between threads. [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=howtohft.wordpress.com&amp;blog=20091585&amp;post=18&amp;subd=howtohft&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>In an earlier post I talked about the need to make the implementation of a limit order book as fast as possible because of the very high data rate typical of market data feeds. Another important set of structures to make correct are the queues the trading system will use to pass messages between threads. Since a market data feed can burst to rates of 200,000+ messages/sec, the performance of the mechanisms that relay these messages is key.</p>
<p>Using a standard blocking queue implementation may not meet performance requirements because of the synchronization that will happen every time a message is enqueued, though using an implementation that allows blocks of messages to be enqueued or dequeued at one time can help. An alternative is to build lock-free implementation of the required queues using atomic operations. A very good, clear explanation of how to implement a lock-free single reader/single writer queue was written by Herb Sutter <a href="http://www.drdobbs.com/high-performance-computing/210604448">here</a>. This implementation can be modified to handle multiple writers by using an atomic swap operation in the enqueue method.</p>
<p>One problem with using lock-free queues, however, is that the reading thread may spin waiting for the next element(s) to be added, wasting cpu time. For queues that are being constantly filled this may still be efficient, but for queues written to in bursts, a good implementation can be to let the reading thread toggle the queue behavior, switching from lock-free to blocking after a set number of read attempts return nothing, and switching back to lock-free mode after a blocking read succeeds. Special care must be taken in designing the mechanism for switching queue modes, however, as a poor implementation can leave the reader blocked while messages sit in the queue.</p>
<p>Another problem with lock-free queues is that their performance tends to degrade relative to blocking queues as the number of writers increases so, as with limit order books, which implementation is best very much depends on the context.</p>
<p>Regardless of the specific queueing implementation, it is important to be able to enqueue and dequeue blocks of multiple messages at once because of a point I mentioned in an earlier post: market events arrive serially but some are actually simultaneous, so it is important for the correctness of a trading model that simultaneous events appear in the model&#8217;s message queue all at the same time.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/howtohft.wordpress.com/18/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/howtohft.wordpress.com/18/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/howtohft.wordpress.com/18/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/howtohft.wordpress.com/18/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/howtohft.wordpress.com/18/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/howtohft.wordpress.com/18/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/howtohft.wordpress.com/18/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/howtohft.wordpress.com/18/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/howtohft.wordpress.com/18/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/howtohft.wordpress.com/18/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/howtohft.wordpress.com/18/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/howtohft.wordpress.com/18/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/howtohft.wordpress.com/18/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/howtohft.wordpress.com/18/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=howtohft.wordpress.com&amp;blog=20091585&amp;post=18&amp;subd=howtohft&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://howtohft.wordpress.com/2011/02/15/message-queues/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">howtohft</media:title>
		</media:content>
	</item>
		<item>
		<title>Clocks and Latency</title>
		<link>http://howtohft.wordpress.com/2011/02/15/clocks-and-latency/</link>
		<comments>http://howtohft.wordpress.com/2011/02/15/clocks-and-latency/#comments</comments>
		<pubDate>Tue, 15 Feb 2011 18:54:00 +0000</pubDate>
		<dc:creator>wkselph</dc:creator>
				<category><![CDATA[Trading]]></category>
		<category><![CDATA[data feeds]]></category>
		<category><![CDATA[high frequency trading]]></category>
		<category><![CDATA[latency]]></category>
		<category><![CDATA[trading systems]]></category>

		<guid isPermaLink="false">http://howtohft.wordpress.com/?p=16</guid>
		<description><![CDATA[Update:  I should make clear that the &#8220;trading clock&#8221; I talk about will have an expectation that is the market time minus the network latency and an error that is a function of the variability of the network latency.  Whether this is good enough of course depends on the usage.  Synchronizing the system clock to [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=howtohft.wordpress.com&amp;blog=20091585&amp;post=16&amp;subd=howtohft&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><em>Update:  I should make clear that the &#8220;trading clock&#8221; I talk about will have an expectation that is the market time minus the network latency and an error that is a function of the variability of the network latency.  Whether this is good enough of course depends on the usage.  Synchronizing the system clock to an external source, like a GPS clock, may be a better option as long as the machine configuration is such that small adjustments to the clock throughout the day don&#8217;t result in bad interval measurements.</em></p>
<p><em>Update 2: tr8dr in the comments makes the important point that accessing the system clock has a cost that should be considered, and also highlights a couple more points I should address.  One is that data feeds from multiple venues will have different latencies, so obtaining a picture of the current total market state across all venues is a not a trivial one, and a topic for another post.  Another is that, generally speaking, trading models are going to be responding to market ticks directly, not the values read off a clock.  When trying to get a &#8220;jump&#8221; on particular events that happen at a certain time, like market open or perhaps another pattern that has shown up in analysis, then an absolute measure of time is most useful.  tr8dr also has an interesting post on his blog about <a href="http://tr8dr.wordpress.com/2011/02/05/hf-simulation/">order book simulation</a>, something I&#8217;d planned to talk about myself.</em></p>
<p>Standard computer clocks are generally terrible at maintaining an accurate time over long periods.  This is because a clock on a computer is just a counter, and the counter needs to be updated at exact time intervals to be accurate; computers are incapable of doing this, however, because they only perform operations at discrete times defined by their chip clock frequency, the period of which will never be an <em>exact</em> multiple of the required time interval.  <a href="http://www.eecis.udel.edu/~ntp/ntpfaq/NTP-s-sw-clocks.htm">Here is a link</a> to a more complete description of this and related issues.</p>
<p>One way to deal with this is to ignore the system clock and use timestamps from a data feed as the &#8220;clock.&#8221;  Of course, the timestamps will be irregular and when the data is sparse achieving a required precision may be impossible.</p>
<p>Recognizing the fact that while computers are bad at maintaining clock accuracy over large time periods because of accumulating error, they are good at measuring time over short intervals, the best way I&#8217;ve found to build a trading clock is to measure time as the last timestamp from a data feed plus the time delta since that timestamp was received, measured by the system clock.  This can be implemented by simply recording the data feed timestamp and the system clock at once, with the only tricky part being to make sure that these two values are written in a single atomic operation so that calls to access the trading clock don&#8217;t need to be synchronized.  Also note that the timestamp/system time pair does not need to be updated with every market tick; how often it needs to be updated is a function of the system clock drift, which should definitely be measured on any machine that trades.</p>
<p>Keeping a log of the timestamp/system time pairs is a good idea, as well, because the difference between these times should grow at the system clock drift rate.  If it does not, this usually indicates a backlog in the data feed and should be investigated.  When handling multiple data feeds, comparing the timestamps and drift rates between the feeds will give even more information about potential problems.  In fact maintaining a matrix of the different measures of time at different points in the system is a very good way to monitor the health of the system.</p>
<p>Data latency, the time it takes for data to get to the trading system from the market, is one of the primary latencies of a HFT system that needs to be minimized, and the other is trading latency.  For models that are tick driven (models that trade as fast as possible after receiving a particular data event), I measure trading latency as the timestamp of the resulting event on the data feed minus the timestamp of the tick that sparked the trade.  This is a measure of the true system responsiveness.  Note that no call to the system clock is involved in the calculation, and it also does not include the data latency.</p>
<p>When trading directly with the market, the reference number required to identify an order sent by the trading system on the market data feed will of course be known.  If trading through an intermediary brokerage, probably via FIX, the order reference number can usually be provided as a field in the FIX execution reports. Either way it&#8217;s very important to have this information.</p>
<p>One last point I want to make regarding latency is that the dynamics of latency for similarly capable market participants sets up a kind of sub-&#8221;poker game&#8221;, separate from the &#8220;poker game&#8221; of the larger price movements.  When a trading system has sent off an order in response to the (delayed) state of the market, it knows before anyone else the &#8220;card&#8221; it is going to play and so has some knowledge of the future state of the market.  A good trading model will work to anticipate other&#8217;s responses to this &#8220;card&#8221; as well as anticipate the &#8220;cards&#8221; of others.  Assuming competitors have similar latencies, the &#8220;cards&#8221; of others will show up on the data feed within one round trip time (data latency plus trading latency) and their responses to the original &#8220;card&#8221; will show up within two round trip times.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/howtohft.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/howtohft.wordpress.com/16/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/howtohft.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/howtohft.wordpress.com/16/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/howtohft.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/howtohft.wordpress.com/16/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/howtohft.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/howtohft.wordpress.com/16/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/howtohft.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/howtohft.wordpress.com/16/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/howtohft.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/howtohft.wordpress.com/16/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/howtohft.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/howtohft.wordpress.com/16/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=howtohft.wordpress.com&amp;blog=20091585&amp;post=16&amp;subd=howtohft&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://howtohft.wordpress.com/2011/02/15/clocks-and-latency/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">howtohft</media:title>
		</media:content>
	</item>
		<item>
		<title>How to Build a Fast Limit Order Book</title>
		<link>http://howtohft.wordpress.com/2011/02/15/how-to-build-a-fast-limit-order-book/</link>
		<comments>http://howtohft.wordpress.com/2011/02/15/how-to-build-a-fast-limit-order-book/#comments</comments>
		<pubDate>Tue, 15 Feb 2011 18:41:32 +0000</pubDate>
		<dc:creator>wkselph</dc:creator>
				<category><![CDATA[Trading]]></category>
		<category><![CDATA[high frequency trading]]></category>
		<category><![CDATA[limit order book]]></category>
		<category><![CDATA[limit orders]]></category>

		<guid isPermaLink="false">http://howtohft.wordpress.com/?p=9</guid>
		<description><![CDATA[The response to my first few posts has been much larger than I&#8217;d imagined and I&#8217;d like to thank everyone for the encouragement. If you&#8217;re interested in building a trading system I recommend first reading my previous post&#160;on general ideas to keep in mind. My first really technical post will be on how to build [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=howtohft.wordpress.com&amp;blog=20091585&amp;post=9&amp;subd=howtohft&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>The response to my first few posts has been much larger than I&#8217;d imagined and I&#8217;d like to thank everyone for the encouragement.</p>
<p><i>If you&#8217;re interested in building a trading system I recommend first reading my <a href="http://howtohft.wordpress.com/2011/02/15/building-a-trading-system-general-considerations/">previous post</a>&nbsp;on general ideas to keep in mind.</i></p>
<p>My first really technical post will be on how to build a limit order book, probably the single most important component of a trading system. &nbsp;Because the data structure chosen to represent the limit order book will be the primary source of market information for trading models, it is important to make it both absolutely correct and extremely fast.</p>
<p>To give some idea of the data volumes, the <a href="http://www.nasdaqtrader.com/content/technicalsupport/specifications/dataproducts/nqtv-itch-v4_1.pdf">Nasdaq TotalView ITCH feed</a>, which is every event in every instrument traded on the Nasdaq, can have data rates of 20+ gigabytes/day with spikes of 3 megabytes/second or more. &nbsp;The individual messages average about 20 bytes each so this means handling 100,000-200,000 messages per second during high volume periods.</p>
<p>There are three main operations that a limit order book (LOB) has to implement: add, cancel, and execute. &nbsp;The goal is to implement these operations in O(1) time while making it possible for the trading model to efficiently ask questions like &#8220;what are the best bid and offer?&#8221;, &#8220;how much volume is there between prices A and B?&#8221; or &#8220;what is order X&#8217;s current position in the book?&#8221; </p>
<p>The vast majority of the activity in a book is usually made up of add and cancel operations as market makers jockey for position, with executions a distant third (in fact I would argue that the bulk of the useful information on many stocks, particularly in the morning, is in the pattern of adds and cancels, not executions, but that is a topic for another post). &nbsp;An add operation places an order at the end of a list of orders to be executed at a particular limit price, a cancel operation removes an order from anywhere in the book, and an execution removes an order from the inside of the book (the inside of the book is defined as the oldest buy order at the highest buying price and the oldest sell order at the lowest selling price). &nbsp;Each of these operations is keyed off an id number&nbsp;(Order.idNumber in the pseudo-code below), making a hash table a natural structure for tracking them.</p>
<p>Depending on the expected sparsity of the book (sparsity being the average distance in cents between limits that have volume, which is generally positively correlated with the instrument price), there are a number of slightly different implementations I&#8217;ve used. &nbsp;First it will help to define a few objects:</p>
<blockquote><p>
Order<br />
&nbsp;&nbsp;int idNumber;<br />
&nbsp;&nbsp;bool buyOrSell;<br />
&nbsp;&nbsp;int shares;<br />
&nbsp;&nbsp;int limit;<br />
&nbsp;&nbsp;int entryTime;<br />
&nbsp;&nbsp;int eventTime;<br />
&nbsp;&nbsp;Order *nextOrder;<br />
&nbsp;&nbsp;Order *prevOrder;<br />
&nbsp;&nbsp;Limit *parentLimit;</p>
<p>Limit &nbsp;// representing a single limit price<br />
&nbsp;&nbsp;int limitPrice;<br />
&nbsp;&nbsp;int size;<br />
&nbsp;&nbsp;int totalVolume;<br />
&nbsp;&nbsp;Limit *parent;<br />
&nbsp;&nbsp;Limit *leftChild;<br />
&nbsp;&nbsp;Limit *rightChild;<br />
&nbsp;&nbsp;Order *headOrder;<br />
&nbsp;&nbsp;Order *tailOrder;</p>
<p>Book<br />
&nbsp;&nbsp;Limit *buyTree;<br />
&nbsp;&nbsp;Limit *sellTree;<br />
&nbsp;&nbsp;Limit *lowestSell;<br />
&nbsp;&nbsp;Limit *highestBuy;</p></blockquote>
<p>The idea is to have a binary tree of Limit objects sorted by limitPrice, each of which is itself a doubly linked list of Order objects. &nbsp;Each side of the book, the buy Limits and the sell Limits, should be in separate trees so that the inside of the book corresponds to the end and beginning of the buy Limit tree and sell Limit tree, respectively. &nbsp;Each order is also an entry in a map keyed off idNumber, and each Limit is also an entry in a map keyed off limitPrice. </p>
<p>With this structure you can easily implement these key operations with good performance:</p>
<p>Add &#8211; O(log M) for the first order at a limit, O(1) for all others<br />
Cancel &#8211; O(1)<br />
Execute &#8211; O(1)<br />
GetVolumeAtLimit &#8211; O(1)<br />
GetBestBid/Offer &#8211; O(1)</p>
<p>where M is the number of price Limits (generally &lt;&lt; N the number of orders). &nbsp;Some strategy for keeping the limit tree balanced should be used because the nature of markets is such that orders will be being removed from one side of the tree as they&#8217;re being added to the other. &nbsp;Keep in mind, though, that it is important to be able to update Book.lowestSell/highestBuy in O(1) time when a limit is deleted (which is why each Limit has a Limit *parent) so that GetBestBid/Offer can remain O(1).</p>
<p>A variation on this structure is to store the Limits in a sparse array instead of a tree. &nbsp;This will give O(1) always for add operations, but at the cost of making deletion/execution of the last order at the inside limit O(M) as Book.lowestSell/highestBuy have to be updated (for a non-sparse book you will usually get much better than O(M) though). &nbsp;If you store the Limits in a sparse array and linked together in a list then adds become O(log M) again while deletes/executions stay O(1). &nbsp;These are all good implementations; which one is best depends mainly on the sparsity of the book.</p>
<p>Generally, it&#8217;s also wise to use batch allocations, or if using a garbage collecting language like Java, object pools for these entities. &nbsp;Java can be made fast enough for HFT as long as the garbage collector isn&#8217;t allowed to run.</p>
<p>Strategies for safely and robustly providing access to the book&#8217;s data from multiple threads will be the subject of another post.</p>
<p>To conclude, this is how I&#8217;ve learned to build a high performance limit order book. &nbsp;If anyone has questions about how specifically to implement some of the operations I talk about, please post in the comments.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/howtohft.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/howtohft.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/howtohft.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/howtohft.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/howtohft.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/howtohft.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/howtohft.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/howtohft.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/howtohft.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/howtohft.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/howtohft.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/howtohft.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/howtohft.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/howtohft.wordpress.com/9/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=howtohft.wordpress.com&amp;blog=20091585&amp;post=9&amp;subd=howtohft&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://howtohft.wordpress.com/2011/02/15/how-to-build-a-fast-limit-order-book/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">howtohft</media:title>
		</media:content>
	</item>
		<item>
		<title>Building a Trading System &#8211; General Considerations</title>
		<link>http://howtohft.wordpress.com/2011/02/15/building-a-trading-system-general-considerations/</link>
		<comments>http://howtohft.wordpress.com/2011/02/15/building-a-trading-system-general-considerations/#comments</comments>
		<pubDate>Tue, 15 Feb 2011 18:38:15 +0000</pubDate>
		<dc:creator>wkselph</dc:creator>
				<category><![CDATA[Trading]]></category>
		<category><![CDATA[high frequency trading]]></category>
		<category><![CDATA[order management systems]]></category>
		<category><![CDATA[trading systems]]></category>

		<guid isPermaLink="false">http://howtohft.wordpress.com/?p=7</guid>
		<description><![CDATA[One of the biggest lessons I&#8217;ve learned is the important of separating the trading models&#8211;the mathematical or algorithmic logic that analyzes data and decides how to trade&#8211;from the the trading system&#8211;the general framework which provides interfaces for receiving data and interacting with the market to the trading models.  The nature of high frequency trading is [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=howtohft.wordpress.com&amp;blog=20091585&amp;post=7&amp;subd=howtohft&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<div>
<p>One of the biggest lessons I&#8217;ve learned is the important of separating the trading models&#8211;the mathematical or algorithmic logic that analyzes data and decides how to trade&#8211;from the the trading system&#8211;the general framework which provides interfaces for receiving data and interacting with the market to the trading models.  The nature of high frequency trading is such that it is critical to be able to rapidly iterate to adapt models to market conditions.  If a trading system has what is truly model logic strewn throughout, it can become a nightmare to modify model behavior; new, fundamentally different, models may have to be foregone because implementing them will take too much time.</p>
</div>
<div></div>
<div>
<p>The above point, I&#8217;m sure the reader is thinking, sounds obvious: of course concerns should be separated.  The problem is that it is often very difficult in practice to distinguish what should belong to the model from what should belong to the trading system before it has become an issue.  Let me give an example:</p>
</div>
<div></div>
<div>
<p>Suppose we have built a model that takes one tick of market data (either an execution or another message altering the limit order book), does some calculations, and then decides whether or not to place an order.  <em>Prima facie</em>, this looks like a reasonable general model, but it is not: in some cases it will leave us making trading decisions based on a false view of the market.  The reason for this is that while a stream of market data is serial, the events the data represents are not: some of the events are truly simultaneous.  For example, a large market order that sweeps the book will generate a set of executions at the range of limits the order filled at, all of which happened at the time the market order was placed.  A model that trades off of the first of these ticks will have an incorrect belief about the current price.  A correct implementation would allow a model to detect simultaneous events and delay a trading decision until they have all been processed.</p>
</div>
<div></div>
<div>
<p>A general trading model should be the source for every behavior that we could conceivably want to control or vary, and its interface with the trading system should be very carefully defined and limited so that it can be easily tested.  A trading system, on the other hand, should be everything that is static, primarily the connectivity with markets, databases, and other computers, an order management system, and interfaces for the models to access these resources.  If I was starting a HFT system from scratch, I would treat the development of the trading system as if I was writing an API&#8211;as opposed to a focused system for a specific task&#8211;to allow myself maximum flexibility during the process of model development.</p>
<p>The order management system (OMS), mentioned previously, is one of the most important parts of the trading system and, like the trading model interface, it is one where the most obvious implementations will lead to headaches down the road.  The primary mistake made in designing an OMS that I&#8217;ve seen, and not just ones used for HFT, is in coupling the intention to place an order with the actual placement of an order.  This can happen because the system was designed without an explicit OMS, so models generate orders which are sent directly to the market, with no intermediary object that has information about all open orders.  It can also happen when the OMS is designed as a simple conduit for reaching the market, so logic that requires orders to be in a certain state must block waiting for a response.  There are two main problems with these OMS designs: one, a blocked model will be unable to react to changing market conditions and will likely build up a backlog of stale market data while it waits for trading confirmations and two, these designs preclude the possibility of optimizing the trading behavior across all of the models that are using the OMS (An example of such an optimization might be two models placing orders in opposite directions for the same security.  An intelligent OMS might combine them into a single net order depending on their limit prices and whether it expects positive or negative net commissions).</p>
<p>In general, the best implementation I&#8217;ve found for an OMS is separate the intentions of a trading model&#8211;such as &#8220;place limit orders at $10.15 and $10.10&#8243; or &#8220;buy 300 shares of INTC immediately&#8221;&#8211;from the resulting actual positions.  With this design, a trading model can, asynchronous from actual trading, update its intentions and the OMS can intelligently work to implement them, notifying the model when they are fulfilled.  This leaves the model free to continuously process data and potentially change intentions before they are fulfilled.  An extremely &#8220;intelligent&#8221; OMS, however, might be better thought of as a special kind of model that gathers and transforms the trading requests of all of the other models, since it is likely that an &#8220;intelligent&#8221; OMS would need to be tuned and otherwise parameterized.  Further discussion of implementing a high performance OMS will be the subject of future posts.</p>
<p>Before beginning the task of modeling financial markets, it is important to understand the capabilities and limitations of the trading system that will drive the models.  Oftentimes, a model that is extremely profitable in theory is impossible to implement because of things like system latency or the fundamental nature of limit order books.  Discussion of these capabilities and limitations will be the subject of future posts, especially those covering the implementation of synthetic option models.</p>
<p>This post attempted to touch on several important considerations to keep in mind when designing a trading system.  Future posts will go into more depth on implementation details.</p>
</div>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/howtohft.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/howtohft.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/howtohft.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/howtohft.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/howtohft.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/howtohft.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/howtohft.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/howtohft.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/howtohft.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/howtohft.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/howtohft.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/howtohft.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/howtohft.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/howtohft.wordpress.com/7/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=howtohft.wordpress.com&amp;blog=20091585&amp;post=7&amp;subd=howtohft&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://howtohft.wordpress.com/2011/02/15/building-a-trading-system-general-considerations/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">howtohft</media:title>
		</media:content>
	</item>
		<item>
		<title>How I Built a Startup HFT Firm, Intro</title>
		<link>http://howtohft.wordpress.com/2011/02/15/intro/</link>
		<comments>http://howtohft.wordpress.com/2011/02/15/intro/#comments</comments>
		<pubDate>Tue, 15 Feb 2011 17:56:21 +0000</pubDate>
		<dc:creator>wkselph</dc:creator>
				<category><![CDATA[Business]]></category>
		<category><![CDATA[high frequency trading]]></category>
		<category><![CDATA[startups]]></category>

		<guid isPermaLink="false">http://howtohft.wordpress.com/?p=1</guid>
		<description><![CDATA[Fresh out of college, with no background in finance, I learned high frequency trading (HFT) first hand while bootstrapping my startup from nothing to trading tens of millions of shares daily for a billion-dollar hedge fund.  I&#8217;m starting this blog to discuss the technical challenges related to building world class HFT system, including developing the trading [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=howtohft.wordpress.com&amp;blog=20091585&amp;post=1&amp;subd=howtohft&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Fresh out of college, with no background in finance, I learned high frequency trading (HFT) first hand while bootstrapping my startup from nothing to trading tens of millions of shares daily for a billion-dollar hedge fund.  I&#8217;m starting this blog to discuss the technical challenges related to building world class HFT system, including developing the trading algorithms, handling the data feeds, building the high performance data structures, structuring the threading model, and designing the system for maximum reliability.</p>
<p>While my focus will be mainly on the technical challenges I faced as the engineering half of a two person HFT startup, the business challenges, such as acquiring trading capital and negotiating ever-lower trading costs, were similarly massive.  With many tech startups, the &#8220;business&#8221; and &#8220;technical&#8221; sides can be separated to some degree: a minimum product can be created and then a company built around it as the product is developed further.  With a trading firm, on the other hand, no one will provide the capital required to trade without a track record, and there can be no track record without trading capital; even if a trading strategy could be shown to work with a small amount of money, it is difficult to show that it would scale to the capital levels needed to make it an attractive investment.  So while my work was mainly in developing trading algorithms and the systems to run them, I also had to build models to convince investors that the algorithms would scale.</p>
<p>Another problem, especially acute in high frequency trading, is that the cost per trade directly impacts the profitability of a trading strategy so, for a given per-trade cost, strategies that would otherwise be profitable are not. Clearing firms will only provide a low per-trade cost to customers that execute many trades, but to execute many trades one needs a low per-trade cost.  So in addition to the purely technical challenges, building a HFT firm from scratch means solving two chicken-and-egg problems, that of building a track record and that of negotiating a low per-trade cost, simultaneously.</p>
<p>The mid 2000&#8242;s when I finished college turned out to be a kind of &#8220;wild west&#8221; environment for high  frequency trading.  Exchanges were at that point almost entirely computer driven and this meant trading at sub-second intervals was becoming feasible.  At the same time, the old ways of trading and the inefficiencies they produced were still extant and could be captured by HFT.  When the opportunity to build a startup doing HFT presented itself, I jumped at the chance.</p>
<p>Early on in the company there wasn&#8217;t any money to hire more people and later on, when it was apparent that the technology was viable, the risk of the technology getting out was decided to be too great to hire more people.  This left me as the sole developer and &#8220;quant&#8221; analyst and I had to learn very quickly how to do those jobs.  At most HFT firms, these are considered separate jobs done to be done by different people, which is a mistake, I believe.  Having built the systems for handling the market data and placing the orders has given me a greater understanding of how the market functions at the micro level and so improved the quality of my financial models, which is something I plan to talk about in a future post.</p>
<p>My firm finally went out of business in 2010 for a number of reasons.  A post-mortem will also be the subject of a future post.</p>
<p>Posts on this blog will fall into three main categories: anecdotes of my experiences as a developer of automated HFT systems, building and validating financial (mathematical and algorithmic) models, and building the trading systems to reliably execute those models.  The secretive nature of trading firms in general, and HFT firms in particular, makes good sources on the workings of real HFT systems pretty hard to come by.  Hopefully this blog will become a good source for practical information on the subject.</p>
<p>Please post in the comments questions you have or things you&#8217;d like to see me address or expand on.  As the purpose of this blog is to illuminate a cryptic subject, I will be happy to discuss whatever readers will find most interesting.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/howtohft.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/howtohft.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/howtohft.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/howtohft.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/howtohft.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/howtohft.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/howtohft.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/howtohft.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/howtohft.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/howtohft.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/howtohft.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/howtohft.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/howtohft.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/howtohft.wordpress.com/1/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=howtohft.wordpress.com&amp;blog=20091585&amp;post=1&amp;subd=howtohft&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://howtohft.wordpress.com/2011/02/15/intro/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">howtohft</media:title>
		</media:content>
	</item>
	</channel>
</rss>
