<?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>veyronb</title>
	<atom:link href="http://veyronb.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://veyronb.wordpress.com</link>
	<description>Just another WordPress.com site</description>
	<lastBuildDate>Tue, 14 Feb 2012 23:23:21 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='veyronb.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>veyronb</title>
		<link>http://veyronb.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://veyronb.wordpress.com/osd.xml" title="veyronb" />
	<atom:link rel='hub' href='http://veyronb.wordpress.com/?pushpress=hub'/>
		<item>
		<title>The Realities of the One-Man Army</title>
		<link>http://veyronb.wordpress.com/2012/01/01/the-realities-of-the-one-man-army/</link>
		<comments>http://veyronb.wordpress.com/2012/01/01/the-realities-of-the-one-man-army/#comments</comments>
		<pubDate>Sun, 01 Jan 2012 10:03:30 +0000</pubDate>
		<dc:creator>intransigence123</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://veyronb.wordpress.com/?p=85</guid>
		<description><![CDATA[I started to catch up on emails today (call it a fresh start to 2012) and was shocked by the sheer number of people trying to start their own fund and miserably failing in the process.  Sifting through the comments, &#8230; <a href="http://veyronb.wordpress.com/2012/01/01/the-realities-of-the-one-man-army/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=veyronb.wordpress.com&amp;blog=22977769&amp;post=85&amp;subd=veyronb&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I started to catch up on emails today (call it a fresh start to 2012) and was shocked by the sheer number of people trying to start their own fund and miserably failing in the process.  Sifting through the comments, a few common questions stood out:</p>
<p>&nbsp;</p>
<p>Question: How can you handle the trading and the non-trading (e.g accounting) aspects of the business successfully?  (Many people reported that they didn&#8217;t have enough time to focus on strategies)</p>
<p>Answer: Automate everything that can be automated.  It is possible to automate every single step in the trading process, to the extent that you are not involved in the day-to-day work.  On OSX and Linux the cron system starts processes automatically.</p>
<p>Once you can mentally free yourself from those tasks, the next step is to automate the research process.  Parameter tuning is simple.  Writing larger strategies takes time, but fortunately a well-written python implementation really streamlines this process.</p>
<p>Sidenote: the python package <a href="http://pypi.python.org/pypi/pudb">PuDB</a> turned out to be indispensible.</p>
<p>&nbsp;</p>
<p>Question: How do you sleep at night?</p>
<p>Answer: It&#8217;s really hard.  You know your money is sitting with a broker that has power to steal from you, especially in light of controversies surrounding MF Global and Pensen Financial.</p>
<p>In my case, since a significant portion of my wealth is locked up, it&#8217;s pretty terrifying.  Fortunately I think I can find a job if necessary (and, furthermore, it would seem that others have found jobs at banks and hedge funds after closing their own operations)</p>
<p>&nbsp;</p>
<p>Question: How are you handling the lack of volumes in the financial markets?</p>
<p>Answer: Needless to say, a new set of strategies must be deployed.  I will discuss them in a future post, but 5 AM seems like the right time to end this post <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/veyronb.wordpress.com/85/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/veyronb.wordpress.com/85/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/veyronb.wordpress.com/85/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/veyronb.wordpress.com/85/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/veyronb.wordpress.com/85/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/veyronb.wordpress.com/85/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/veyronb.wordpress.com/85/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/veyronb.wordpress.com/85/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/veyronb.wordpress.com/85/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/veyronb.wordpress.com/85/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/veyronb.wordpress.com/85/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/veyronb.wordpress.com/85/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/veyronb.wordpress.com/85/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/veyronb.wordpress.com/85/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=veyronb.wordpress.com&amp;blog=22977769&amp;post=85&amp;subd=veyronb&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://veyronb.wordpress.com/2012/01/01/the-realities-of-the-one-man-army/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/029dda212fa2d251bde2cfa1afba3976?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">intransigence123</media:title>
		</media:content>
	</item>
		<item>
		<title>In Defense of Liquidity Rebates and other Structures in the Equity Markets</title>
		<link>http://veyronb.wordpress.com/2011/11/22/in-defense-of-liquidity-rebates-and-other-structures-in-the-equity-markets/</link>
		<comments>http://veyronb.wordpress.com/2011/11/22/in-defense-of-liquidity-rebates-and-other-structures-in-the-equity-markets/#comments</comments>
		<pubDate>Wed, 23 Nov 2011 04:28:59 +0000</pubDate>
		<dc:creator>intransigence123</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://veyronb.wordpress.com/?p=79</guid>
		<description><![CDATA[Question: Why do liquidity rebates exist?  Are they fair? Answer: It&#8217;s easy to say that rebates are unfair, possibly because of the woeful lack of simple explanations of the rules.  So consider this my attempt at a simple explanation. For &#8230; <a href="http://veyronb.wordpress.com/2011/11/22/in-defense-of-liquidity-rebates-and-other-structures-in-the-equity-markets/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=veyronb.wordpress.com&amp;blog=22977769&amp;post=79&amp;subd=veyronb&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Question: Why do liquidity rebates exist?  Are they fair?</p>
<p>Answer: It&#8217;s easy to say that rebates are unfair, possibly because of the woeful lack of simple explanations of the rules.  So consider this my attempt at a simple explanation.</p>
<p>For a trade to occur, a person must have sent an order (for this example, suppose the order is a buy order) before the trade occurred.  That buy order is sitting in the exchange&#8217;s order book.  Another person (in financial jargon, the &#8220;active party&#8221;) comes later and sends a sell order at the same price (or lower).</p>
<p>When that trade occurs, the second person is acting based on more relevant information.  Assuming the second person isn&#8217;t an idiot, he is sending the order because he believes the price is going to fall (yes there are people who have to trade for other reasons, such as hedging another exposure, but the majority of trades are not hedging trades).  So the first person (who is the &#8220;passive party&#8221; in the transaction) is ostensibly disadvantaged.  The trade is a bad trade for the passive party.</p>
<p>We can actually measure this effect quantitatively.  We will call the active party &#8220;instantaneously correct&#8221; if the next price move is favorable for him.  It should be obvious that the active party is correct if and only if the passive party is incorrect (since the passive party has the opposite exposure).</p>
<p>So the natural question is: how frequently is the passive party correct (active party is stupid)?  This is a simple test: just count each trade (comparing the mid-market price at the time of trade to the next value), weighted by share volume.  Limiting to the actual trading day, assuming positions are unwound in the closing cross, the active party is correct more than 99.95% of the time (measured since September 1).  To put it differently, the market maker is almost always wrong.</p>
<p>The subsequent questions should be straightforward, but just in case &#8230;</p>
<p>Question: Why don&#8217;t we just ask the exchanges to put some forced lifetime, preventing market makers from canceling orders too quickly?</p>
<p>Answer: that would just increase spreads, taxing the very people who are pushing for this proposal.</p>
<p>To understand why, look at the mechanics of the trade.  The ability to take a risk (by sending a buy order at a higher price or sending a sell order at a lower price) is a function of how quickly the trader can respond to an adverse event by canceling the order.  So if there is a forced lifetime, anyone sending an order is taking a risk tat the order may have to sit for some period of time.  And if you believe that you may be picked off at any time (after all, given when major events have occurred and given the quick market response, the risk is significant) you would not send orders at aggressive prices unless you strongly believed that particular trade would be profitable if picked off.  On the average, market makers would quote larger spreads, which would represent a larger expense to the other traders.</p>
<p>Question: Is ultra low latency trading risk-free?</p>
<p>Answer: No, and that&#8217;s why a rebate is needed and why order lifetimes should not be enforced <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>To understand why, take a look at certain news events during the day that cause price dislocations.  As the news comes out, every major trader is generally trading in the same direction.  Thus, the people who take the wrong side of the trade end can end up losing more than 1% of the position value.  When put in this light, the rebate does little to compensate for the risk, but it is enough to allow the passive party to take a risk.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/veyronb.wordpress.com/79/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/veyronb.wordpress.com/79/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/veyronb.wordpress.com/79/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/veyronb.wordpress.com/79/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/veyronb.wordpress.com/79/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/veyronb.wordpress.com/79/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/veyronb.wordpress.com/79/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/veyronb.wordpress.com/79/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/veyronb.wordpress.com/79/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/veyronb.wordpress.com/79/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/veyronb.wordpress.com/79/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/veyronb.wordpress.com/79/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/veyronb.wordpress.com/79/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/veyronb.wordpress.com/79/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=veyronb.wordpress.com&amp;blog=22977769&amp;post=79&amp;subd=veyronb&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://veyronb.wordpress.com/2011/11/22/in-defense-of-liquidity-rebates-and-other-structures-in-the-equity-markets/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/029dda212fa2d251bde2cfa1afba3976?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">intransigence123</media:title>
		</media:content>
	</item>
		<item>
		<title>Prototyping with Python</title>
		<link>http://veyronb.wordpress.com/2011/11/02/prototyping-with-python/</link>
		<comments>http://veyronb.wordpress.com/2011/11/02/prototyping-with-python/#comments</comments>
		<pubDate>Thu, 03 Nov 2011 03:05:24 +0000</pubDate>
		<dc:creator>intransigence123</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://veyronb.wordpress.com/?p=75</guid>
		<description><![CDATA[Question: How long did it take for you to put everything together? Answer: A month If you stare at a blank vi terminal and expect to magically spit out C code, you will get nowhere.  Same with assembly or C++ &#8230; <a href="http://veyronb.wordpress.com/2011/11/02/prototyping-with-python/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=veyronb.wordpress.com&amp;blog=22977769&amp;post=75&amp;subd=veyronb&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Question: How long did it take for you to put everything together?</p>
<p>Answer: A month <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>If you stare at a blank vi terminal and expect to magically spit out C code, you will get nowhere.  Same with assembly or C++ or with most languages.  So how do you get off the ground running?</p>
<p>Enter Python.</p>
<p>If you asked me a year ago, I probably would have said &#8220;Enter Perl&#8221;, but Python is my new favorite language.</p>
<p>&nbsp;</p>
<p>It should take no more than a day to put together a full stack in python.  At a high level:</p>
<ul>
<li>python struct module gives you a very easy way to unpack binary messages.  major gripe: what is the python equivalent of unpack(&#8216;x8 S&gt;/A&#8217;) ??</li>
<li>The simple networking commands have almost direct python analogues</li>
<li>There&#8217;s a module or builtin for pretty much any other piece you need</li>
</ul>
<p>Building a straightforward, correct implementation gives you a baseline.  You can then put together some simple regression tests.  For the order book, a simple regression test involves replaying a simple data segment (for example, you can record a day&#8217;s data and just filter for a specific ticker), passing the data through a driver program, and dumping what the book looks like (all of the orders and their relative priorities)</p>
<p>&nbsp;</p>
<p>Now, with the baseline, you can attack a C or C++ implementation.  Most people would fire up vi and start from scratch.  However, there&#8217;s a much slicker way to do this: use the python/C API to rebuild piece by piece in C, replacing pure python implementations of features with the C equivalent.  For the C++ hackers, boost::python allows you to reimplement python classes with C++ equivalents.</p>
<p>Since we have the original pure python implementation, at each stage of translation we can verify that the new program is consistent with the old one.</p>
<p>&nbsp;</p>
<p>Suddenly, a week later you have this hybrid Python and C implementation, with core features implemented in C and python used as a glue.</p>
<p>It should take less than a day to remove the python scaffold and connect the underlying C components with a C driver program.  And now you have a pure C implementation <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>&nbsp;</p>
<p>Now that you have a C implementation, you can go back and optimize components as relevant.  Now, is this the most efficient route?  Probably not.  However, two weeks into the process you should have a fully functioning C implementation.</p>
<p>&nbsp;</p>
<p>How do you reduce elements to x86 assembly?  For that, you can either use inline assembly (gcc uses the __asm__ keyword) or use an assembler like nasm to produce ELF object files, linking them with the C code using ld.</p>
<p>&nbsp;</p>
<p>Summarizing, the low-level code only enters the fray after the design has been prototyped, and the cascade of implementations allow you to develop a comfort level with each step of the process before delving further.  The steps are:</p>
<ul>
<li>Pure python implementation (1 week)</li>
<li>Python gluing PythonC/boost::python wrappers to C++ implementations (1 week)</li>
<li>C/C++ gluing the native C/C++ implementations (3 Days)</li>
<li>Tweaking the C implementations where relevant (2 Days)</li>
<li>Replacing the C code with optimized assembly routines (1 Week)</li>
</ul>
<p>And the most awesome part is, at each stage you have a fully functional platform!</p>
<p>&nbsp;</p>
<p>Question: How do you backtest or simulate strategies?</p>
<p>Answer: In python <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>The first python implementation involves a prototype that uses callbacks and other high level model-friendly techniques (simple event reactor) that allow me to quickly put together and test strategies.  Once I am happy with it, I can implement it using the low-level API (which, for various reasons, avoids the dynamic features like virtual functions that make the callback implementation so flexible).</p>
<p>I use 3 levels of simulations</p>
<ul>
<li>Python prototyping for testing strategies.  These are designed to be throwaway idea tests, complete with introspective features.  However, latency testing is futile.</li>
<li>C in-process simulator.  Each strategy program can be built in production or simulation mode.  The simulation binaries actually can be used in production trading, but there is some extra code that allow you to choose to run in simulation or in production using a command-line flag.  This allows you to test the source code to make sure that the implementation is correct.  Again, since the simulator uses a time stepping model, latency testing is futile.</li>
<li>Live simulator.  A separate server simulates the exchange, reading in a data file and interspersing strategy orders with real orders and simulating the order book.  This gives you a more accurate measure of performance, but may take longer depending on whether you choose to simulate in real time or 2x or 10x time.</li>
</ul>
<p>Generally, it flows in that order.  An idea is first modeled in python and then implemented and verified in C.  Finally, performance is tested using a simulation server.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/veyronb.wordpress.com/75/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/veyronb.wordpress.com/75/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/veyronb.wordpress.com/75/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/veyronb.wordpress.com/75/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/veyronb.wordpress.com/75/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/veyronb.wordpress.com/75/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/veyronb.wordpress.com/75/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/veyronb.wordpress.com/75/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/veyronb.wordpress.com/75/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/veyronb.wordpress.com/75/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/veyronb.wordpress.com/75/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/veyronb.wordpress.com/75/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/veyronb.wordpress.com/75/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/veyronb.wordpress.com/75/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=veyronb.wordpress.com&amp;blog=22977769&amp;post=75&amp;subd=veyronb&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://veyronb.wordpress.com/2011/11/02/prototyping-with-python/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/029dda212fa2d251bde2cfa1afba3976?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">intransigence123</media:title>
		</media:content>
	</item>
		<item>
		<title>On NIH Syndrome</title>
		<link>http://veyronb.wordpress.com/2011/11/01/on-nih-syndrome/</link>
		<comments>http://veyronb.wordpress.com/2011/11/01/on-nih-syndrome/#comments</comments>
		<pubDate>Wed, 02 Nov 2011 03:25:09 +0000</pubDate>
		<dc:creator>intransigence123</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://veyronb.wordpress.com/?p=73</guid>
		<description><![CDATA[Question: What software pieces can be purchased on the market and what software pieces should be written in-house? Answer: Ideally, everything is written in-house People sometimes think of this as a sort of &#8220;NIH Syndrome&#8221;, that there&#8217;s some sort of &#8230; <a href="http://veyronb.wordpress.com/2011/11/01/on-nih-syndrome/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=veyronb.wordpress.com&amp;blog=22977769&amp;post=73&amp;subd=veyronb&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Question: What software pieces can be purchased on the market and what software pieces should be written in-house?</p>
<p>Answer: Ideally, everything is written in-house <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>People sometimes think of this as a sort of &#8220;NIH Syndrome&#8221;, that there&#8217;s some sort of ingrained aversion to using others&#8217; code.  But that can&#8217;t be the case (after all, they are using an operating system not developed in-house).</p>
<p>At a very high level, suppose you are pushing 10M shares of volume per day.  A simple mistake at any level could blow up your operation in a matter of seconds:</p>
<p>- A broken risk check could inadvertently allow you to exceed your capital limits</p>
<p>- A broken order gateway may bomb out before you can complete your trade, leaving a large undesired naked exposure</p>
<p>- A broken strategy may over-hedge, incurring significant losses</p>
<p>- A broken feed may be pumping wrong prices, resulting in ridiculous orders and trades</p>
<p>- A broken reporting infrastructure may report the wrong position, forcing you to make poor decisions</p>
<p>- A broken kernel module or tweak can result in a kernel panic, leaving your machine a mess at the most critical time</p>
<p>When you are trading with your own money, these risks will keep you up at night.  You need to be absolutely confident that every piece is working properly.  As a concrete example, suppose that the feed is reporting bad prices.  Then, you might find that buying a particular stock is profitable and proceed to buy when in fact the trades are losing money.  In the blink of an eye, a strategy may end up buying $1M worth of a stock.  Now, of course, that&#8217;s why you have exposure control (but you are assuming that it will work <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>This is in stark contrast to how most technology vendors approach the problem.  To most vendors, 99.99% uptime is acceptable.  A blip is treated as a rare hiccup.  However, Murphy&#8217;s Law says that systems will run amok at the worst possible moments.  And in those moments, multi-million dollar losses aren&#8217;t uncommon.</p>
<p>At the end of the day, the only way to ensure that there are no problems is to build it yourself <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />   You should understand every trick employed, every potential landmine, every design decision.  It&#8217;s easy to take a shortcut and buy an off-the-shelf solution, but the cost of the first crash far exceeds the development time for a self-written solution.</p>
<p>As I discussed <a href="http://news.ycombinator.com/item?id=2828804">in another forum</a>, there are special strategies that can only be deployed with custom components.  No off-the-shelf feed handler and order gateway can run the feed spike trading strategy (as far as I have seen, third party feeds don&#8217;t give you the ability to tweak when events are triggered).</p>
<p>Having said that, there are a few pieces that could safely be outsourced.  These, as you can imagine, are not on the critical path.  For example:</p>
<p>- Software and tools for visualization (charting and order book visualization tools)</p>
<p>- Reporting and compliance software (to generate those reports)</p>
<p>&nbsp;</p>
<p>Question: Why are you prejudiced against vendors?</p>
<p>Answer: Most vendors fall into one of the following categories:</p>
<p>- Built by a pure technology firm without shaking down the system with real trading.  It&#8217;s easy to write the software, but the only way to be sure the systems work is to actually trade with the system.  I am very wary of vendors with &lt; 3 customers, because you know you are essentially beta-testing their system while risking your own capital.</p>
<p>- Built by a trading firm.  Why would the trading firm sell their platform if it is making money for the firm?  So here&#8217;s a sense in which some set of trading strategies fail to work on the platform, ostensibly because of a latency issue.</p>
<p>- Built by a trader.  This is the worst case, because the IP is of questionable origin.  There are at least 4 cases which come to mind involving people trying to steal IP to run the system elsewhere.  <a href="http://www.scribd.com/doc/68661724/Criminal-Complaint-Against-Yihao-Ben-Pu">The most recent case</a> involves a kid my age.  And there&#8217;s really no need to invite trouble by using that platform.</p>
<p>I guess the best summary is: Imagine you are running this on your own.  Would you really trust a third party feed, whose code you haven&#8217;t seen, not to blow up at the worst possible moment?  Do you trust the third party order gateway provider to keep up with changes with the exchanges?  Do you trust the reporting infrastructure to handle new exchange features like half-penny prices?</p>
<p>&nbsp;</p>
<p>Question: How can you trust the Linux kernel or libc or gcc?</p>
<p>Answer: Because I&#8217;ve been through most of the source and modified relevant parts of the code <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />   Yes, it takes that level of dedication.  When a slight hiccup threatens the solvency of your business, you have to put in enough energy to trust every piece of the system, on the hardware and on the software side.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/veyronb.wordpress.com/73/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/veyronb.wordpress.com/73/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/veyronb.wordpress.com/73/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/veyronb.wordpress.com/73/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/veyronb.wordpress.com/73/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/veyronb.wordpress.com/73/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/veyronb.wordpress.com/73/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/veyronb.wordpress.com/73/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/veyronb.wordpress.com/73/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/veyronb.wordpress.com/73/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/veyronb.wordpress.com/73/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/veyronb.wordpress.com/73/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/veyronb.wordpress.com/73/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/veyronb.wordpress.com/73/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=veyronb.wordpress.com&amp;blog=22977769&amp;post=73&amp;subd=veyronb&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://veyronb.wordpress.com/2011/11/01/on-nih-syndrome/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/029dda212fa2d251bde2cfa1afba3976?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">intransigence123</media:title>
		</media:content>
	</item>
		<item>
		<title>On Latency</title>
		<link>http://veyronb.wordpress.com/2011/11/01/on-latency/</link>
		<comments>http://veyronb.wordpress.com/2011/11/01/on-latency/#comments</comments>
		<pubDate>Tue, 01 Nov 2011 04:20:14 +0000</pubDate>
		<dc:creator>intransigence123</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://veyronb.wordpress.com/?p=69</guid>
		<description><![CDATA[Question: &#8220;I’d still like to hear about your actual latency profile! What % of your quotes come in at under 5ms latency (from the time they leave the exchange until the time your user-space software stack sees them)?&#8221; Answer: The &#8230; <a href="http://veyronb.wordpress.com/2011/11/01/on-latency/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=veyronb.wordpress.com&amp;blog=22977769&amp;post=69&amp;subd=veyronb&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Question: &#8220;I’d still like to hear about your actual latency profile! What % of your quotes come in at under 5ms latency (from the time they leave the exchange until the time your user-space software stack sees them)?&#8221;</p>
<p>Answer: The question cannot be answered as stated.  This requires you to know when quotes leave the exchange and when the software stack sees the quotes, which isn&#8217;t well defined because both use separate time sources.</p>
<p>To understand the difficulty, assume for the moment that there is no clock drift (both clocks are running at the same rate).  Imagine that the actual transmission time (measured from either time source) is (L) microseconds and that the difference between the clock times is (D) microseconds, with the sender running D microseconds slower than the receiver.  Then, the sender sends a message at some time (T).  According to the receiver, the message is sent at time T+D and is received at time T+D+L.  Supposing the sender marked the message with its local time T, the receiver can compute D+L = (receiver local recv time) &#8211; (time in the message).  However, without knowing D in advance, you cannot compute L with certainty.  This situation is muddied when you take into account clock drift and other oddities.</p>
<p>To put numbers to the situation, you could know that the difference between local recv time and exchange send time is 1 millisecond, but you can&#8217;t determine whether the latency is 1 msec or actually 50 usec (with a 950 usec skew)</p>
<p>&nbsp;</p>
<p>Question: If you can&#8217;t answer that question, what numbers can / should you quote?</p>
<p>Answer: This question rankles me in particular because some unnamed vendors like to quote average or optimistic times which aren&#8217;t accurately measured.</p>
<p>1. The start and stop times should be determined from the same clock source.  That means same machine.  You can try as hard as you wish (e.g. using ptp) to synchronize machines, but the best results use the same machine for start and stop).</p>
<p>2. The times should use a high-precision timing source.  The obvious first point is that NTP should be disabled.  Nothing should be tampering with the clock.  Whenever possible, avoid time sources for which the cost of measuring the time significantly affects the experiment.  As an example, the gettimeofday system call can cost you dearly.</p>
<p>3. There should be no assumption regarding any clock source for which you have no control.  For example, for a long time the BATS exchange would use multiple machines to generate quotes (which were coalesced by a machine later on), resulting in weird time anomalies where you would see three consecutive quotes with times T, T+1, T respectively.  Of course, if you looked on a specific ticker, the quotes were in-order.  And someone who doesn&#8217;t bother considering time source issues before reporting about timing anomalies (<a href="http://www.nanex.net/Research/fantaseconds/fantaseconds.html">are you really surprised who complained about this?</a>) shouldn&#8217;t be commenting about time issues.</p>
<p>And we should be quoting the following numbers: median, short-tail (90%), long-tail (at least 99%).  Definitely not mean and standard deviation (<a href="http://www.fixnetix.com/news/fixnetix-to-offer-low-latency-co-location-for-bats-europe/">stop</a> <a href="http://low-latency.com/article/ra-cheetah-professional-fix-engine-breaks-10-%C2%B5s-average-latency-fix-message-using-ra-generat">the</a> <a href="http://www.gpucomputing.net/node/10328">madness</a>)  Why?  Because the most profitable opportunities generally are long-tail events (99.99%+) so the standard deviation doesn&#8217;t really capture the effects.</p>
<p>Question: What are your times?</p>
<p>Answer: Using the rdtsc x86 instruction on an appropriate configured server (disabling power savings mode in bios, forcing highest clock speed in software, etc) using a dual xeon  X5650, Solarflare SFN5122 with appropriate affinity settings, and a custom tuned Linux kernel (one day I&#8217;ll clean up and post a patch):</p>
<p>A) Order entry round-trip</p>
<p>START: strategy sends an order</p>
<p>STOP: strategy receives order acknowledgement</p>
<p>PROCESS:</p>
<p>- Strategy tic</p>
<p>- Send order to gateway to buy 1 share of BAC</p>
<p>- Gateway receives request and generates outbound OUCH message</p>
<p>- Risk check processes the request and sends it to the exchange</p>
<p>- Exchange receives it, processes it, and then sends us an acknowledgement</p>
<p>- Gateway receives response, parses it, and sends a message to strategy</p>
<p>- Strategy framework acknowledges message, informs strategy that order was received</p>
<p>- Strategy toc</p>
<p>Median = 65 usec, 90th% = 74 usec, 99th%= 88 usec</p>
<p>&nbsp;</p>
<p>A) Order to feed acknowledgement</p>
<p>START: strategy sends an order</p>
<p>STOP: strategy receives quote for the original order</p>
<p>PROCESS:</p>
<p>- Strategy tic</p>
<p>- Send order to gateway to buy 1 share of BAC</p>
<p>- Gateway receives request and generates outbound OUCH message</p>
<p>- Risk check processes the request and sends it to the exchange</p>
<p>- Exchange receives it, processes it, and then sends us an acknowledgement</p>
<p>- Gateway receives response, parses it, and sends a message to strategy</p>
<p>- Strategy framework acknowledges message, informs strategy that order was received</p>
<p>- Strategy notes when the ID generated by the exchange</p>
<p>- Quote engine receives quote and informs strategy</p>
<p>- Strategy framework sees the quote, updates order book, and notifies strategy</p>
<p>- Strategy compares ID to marked ID, sees a match, and toc</p>
<p>Median = 78 usec, 90th% = 85 usec, 99th%= 98 usec</p>
<p>Note that strategies which don&#8217;t care about each individual quote (lots of speed strategies just care about top of book updates) perform better because they don&#8217;t see every quote.</p>
<p>&nbsp;</p>
<p>Question: What is your internal latency?</p>
<p>Answer: This measurement requires a second server to act as a fake exchange and mark the times.  You have to connect the two servers together and use the fake exchange to generate a fake quote.  A fake strategy, receiving the fake quote, would decide to send an order.  The second server marks the other end.  This does include wire latency, but those are basically negligible in this test.</p>
<p>Median = 11 usec, 90th% = 12 usec, 99th%= 14 usec</p>
<p>To get these aggressive numbers, there were many tricks designed to reduce the amount of work per order.  For example, when sending out orders, templates of the required messages are precomputed in advance so that only a few fields need to be populated before shooting the order (and risk checks are optimized so as to minimize the number of full checks in the critical path).  And yes, a lot of hard pieces are in hand-rolled x64 assembly &#8230;</p>
<p>&nbsp;</p>
<p>I&#8217;m pretty sure there are people out there who can beat this (on PC or on custom hardware); please post some numbers for our benefit <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>&nbsp;</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/veyronb.wordpress.com/69/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/veyronb.wordpress.com/69/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/veyronb.wordpress.com/69/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/veyronb.wordpress.com/69/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/veyronb.wordpress.com/69/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/veyronb.wordpress.com/69/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/veyronb.wordpress.com/69/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/veyronb.wordpress.com/69/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/veyronb.wordpress.com/69/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/veyronb.wordpress.com/69/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/veyronb.wordpress.com/69/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/veyronb.wordpress.com/69/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/veyronb.wordpress.com/69/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/veyronb.wordpress.com/69/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=veyronb.wordpress.com&amp;blog=22977769&amp;post=69&amp;subd=veyronb&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://veyronb.wordpress.com/2011/11/01/on-latency/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/029dda212fa2d251bde2cfa1afba3976?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">intransigence123</media:title>
		</media:content>
	</item>
		<item>
		<title>High Frequency Accounting</title>
		<link>http://veyronb.wordpress.com/2011/10/27/high-frequency-accounting/</link>
		<comments>http://veyronb.wordpress.com/2011/10/27/high-frequency-accounting/#comments</comments>
		<pubDate>Thu, 27 Oct 2011 06:22:21 +0000</pubDate>
		<dc:creator>intransigence123</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://veyronb.wordpress.com/?p=64</guid>
		<description><![CDATA[Question: Are you still alive? Answer: Yes, although it&#8217;s been tough.  I really could use some help, and one day I will write a multi-page rant about the utter incompetency of financial recruiters &#8230; It&#8217;s been months.  I apologize.  I &#8230; <a href="http://veyronb.wordpress.com/2011/10/27/high-frequency-accounting/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=veyronb.wordpress.com&amp;blog=22977769&amp;post=64&amp;subd=veyronb&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Question: Are you still alive?</p>
<p>Answer: Yes, although it&#8217;s been tough.  I really could use some help, and one day I will write a multi-page rant about the utter incompetency of financial recruiters &#8230;</p>
<p>It&#8217;s been months.  I apologize.  I didn&#8217;t intend to abandon the blog, if that&#8217;s of any consolation <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Something short for today: accounting for HFT.</p>
<p>&nbsp;</p>
<p>Question: What are the per-trade costs and commissions in equities trading?</p>
<p>Answer: The per-trade costs break down as follows:</p>
<ol>
<li>&#8220;Brokerage Commissions&#8221; &#8212; for a standard sponsored access relationship, this refers to a commission.  For self-clearing, this refers to the amortized costs.</li>
<li>&#8220;Taxes&#8221; &#8212; monies that flow to government or regulatory agencies</li>
<li>&#8220;Exchange Costs&#8221; &#8212; monies that flow to or from the exchanges.</li>
</ol>
<div>
<p>Generally, the brokerage commissions are less that $.0001 per share (1 cent per 100 shares), and these are assessed on a per-share basis for each order (buying or selling)</p>
<p>For a very long time, the tax was called an &#8220;SEC Fee&#8221;.  For PR reasons, SEC has been pushing the community to call the tax a &#8220;Trading Activity Fee&#8221;.  In any case, there is a rate which is updated each quarter.  Currently its around $.000019 per dollar sold ($19 for every million dollars sold).  Note that it&#8217;s only assessed on the seller, so you only pay this once.</p>
<p>As far as the exchange costs are concerned, they depend on whether or not you were the active party (your order caused the trade) or the passive party (your order was sitting at the exchange&#8217;s order book until another order trades against you).  If you are providing liquidity (e.g. market maker), you RECEIVE a small amount (at least $.002/sh).  If you are taking liquidity, you PAY a small amount ($.003/sh).</p>
<p>&nbsp;</p>
<p>Question: Why is BAC considered an HFT &#8220;playground&#8221;?</p>
<p>Answer: Let&#8217;s look at the cost of buying and selling 100 shares of BAC at the same price, adding liquidity on both sides (suppose the price is $ 6).  Note that, in this example, there is no return before fees since the buy price is the same as the sell price.</p>
<p>Commissions = $ &#8211; .02 (200 shares x .0001 $/sh)</p>
<p>TAF = $ &#8211; .01235 (6.5 $-sold/sh * 100 sh * .000019 $/$-sold)</p>
<p>Exchange rebate = $ .40 (200 * .002 $/sh)</p>
<p>Total return: $.368 per 100-share lot.  It&#8217;s positive!</p>
<p>Note that there is a positive return if you can manage to buy and sell at the same price, so you could theoretically churn millions of shares a day trying to buy and sell at the same price (collecting the positive returns)</p>
<p>&nbsp;</p>
<p>Question: What about AAPL?</p>
<p>Answer: Let&#8217;s re-do the calculation for AAPL (price $400/sh)</p>
<p>Commissions = $ &#8211; .02</p>
<p>TAF = $ &#8211; .76</p>
<p>Exchange rebate = $ .40</p>
<p>Total return: $-.38 per 100-share lot.  It&#8217;s negative!</p>
<p>Given that, the market maker must depend on price appreciation (the rebates just dont cut it).</p>
<p>&nbsp;</p>
<p>Question: So how can you ensure that you are always passive on your trades?</p>
<p>Answer: All of the equities exchanges support an order property referred to as &#8220;Add Liquidity Only&#8221; or &#8220;Post-Only&#8221;.  This fundamental order property was created to resolve a strange problem: supposing you wanted to buy at the offer price, you end up paying more than the stated price.  The post-only flag tells the exchange not to trade against the other side unless the final price (adjusting for the exchange fee) is better than the sent price.</p>
<p>As a numerical example, suppose that the bid/offer for a stock were 10,10.01 .  Then, sending a buy order at 10.01 would result in an effective price of 10.0130 .  Sending that order as post-only would cause the exchange to reprice your order at 10.00 (ensuring you don&#8217;t trade worse than the 10.01 price).  However, if the offer price were 10.00, then you would buy actively at 10.00 since the effective price is 10.0030 &lt; 10.01 (a slight price improvement).  So in reality, you need a platform that can quickly respond to price changes.</p>
<p>&nbsp;</p>
<p>Question: So how do you make money?</p>
<p>Answer: The &#8220;Veyron&#8221; strategy (appropriately named, given the performance) essentially seeks to buy and sell passively on both sides, collecting rebates.  You need to have a low-latency infrastructure in order to ensure that, when one order is filled, you can quickly respond with the opposing order (i.e. if your buy fills, you need to quickly shoot off a sell order to catch slower traders before the price moves further).</p>
<p>And given the costs of doing business, 1M shares per day (which can be spread amongst many tickers) should be enough to cover everything and give a small salary.  That&#8217;s less than 1% of the volume of BAC <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>&nbsp;</p>
<p>Question: So when will you be posting again?</p>
<p>Answer: Hopefully soon <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
</div>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/veyronb.wordpress.com/64/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/veyronb.wordpress.com/64/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/veyronb.wordpress.com/64/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/veyronb.wordpress.com/64/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/veyronb.wordpress.com/64/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/veyronb.wordpress.com/64/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/veyronb.wordpress.com/64/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/veyronb.wordpress.com/64/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/veyronb.wordpress.com/64/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/veyronb.wordpress.com/64/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/veyronb.wordpress.com/64/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/veyronb.wordpress.com/64/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/veyronb.wordpress.com/64/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/veyronb.wordpress.com/64/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=veyronb.wordpress.com&amp;blog=22977769&amp;post=64&amp;subd=veyronb&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://veyronb.wordpress.com/2011/10/27/high-frequency-accounting/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/029dda212fa2d251bde2cfa1afba3976?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">intransigence123</media:title>
		</media:content>
	</item>
		<item>
		<title>Dear Nanex, Please Explain This</title>
		<link>http://veyronb.wordpress.com/2011/08/30/dear-nanex-please-explain-this/</link>
		<comments>http://veyronb.wordpress.com/2011/08/30/dear-nanex-please-explain-this/#comments</comments>
		<pubDate>Tue, 30 Aug 2011 05:15:08 +0000</pubDate>
		<dc:creator>intransigence123</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://veyronb.wordpress.com/?p=56</guid>
		<description><![CDATA[As anyone watching the markets could imagine, the past month was crazy beyond imagination.  The next post is in the works, but that will have to wait a few days. Before that, a few friends asked me about a blog &#8230; <a href="http://veyronb.wordpress.com/2011/08/30/dear-nanex-please-explain-this/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=veyronb.wordpress.com&amp;blog=22977769&amp;post=56&amp;subd=veyronb&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>As anyone watching the markets could imagine, the past month was crazy beyond imagination.  The next post is in the works, but that will have to wait a few days.</p>
<p>Before that, a few friends asked me about a blog post on the Nanex site: <a href="http://www.nanex.net/StrangeDays/08252011.html">http://www.nanex.net/StrangeDays/08252011.html</a> (they found the site through a <a href="http://www.zerohedge.com/news/dear-hft-please-explain">zerohedge</a> repost)</p>
<p>On August 25, 2011, over the course of 13 hours (46,800 seconds or 46.8 B microseconds) there were 628629 messages corresponding to DELL.  The first DELL quote of the day was at 7:02:51 AM (someone tried to buy 3000 shares at 14.48) and the last quote was at 19:59:51 (a sell order at 14.90 was canceled).</p>
<p>Close inspection of these quotes reveals something very disturbing:  Nanex&#8217;s system can&#8217;t handle the recent quote volumes.</p>
<p>So let&#8217;s start from the obvious questions:</p>
<p>&nbsp;</p>
<p>Question: What happened?</p>
<p>It looks like someone was speed testing.  10K orders per second translates roughly to 100 usec per order, consistent with order entry latencies in the NASDAQ colocation.</p>
<p>&nbsp;</p>
<p>Question: Was the strategy running on other tickers as well?</p>
<p>AFAICT no.</p>
<p>The exchange assigns an internal ID to each order on the market.  For NASDAQ in particular, which is where this event happened, The strategy started saturating the market from the order id 465998436, and more than 99% of the next five thousand order id&#8217;s were for orders on DELL.</p>
<p>&nbsp;</p>
<p>Question: Nanex alleges that you would need 40 Gb/s bandwidth to handle the message rate if it indeed hit every single ticker.  Is this true?</p>
<p>Let&#8217;s try to get a better handle on the math.  Sending and canceling an order, on the ITCH 4.1 feed, takes 49 bytes (30 for the add and 19 for the cancel).  There are packet header messages, but the exchange will coalesce multiple messages into a larger packet (up to 64K).  As a result, we can amortize the cost to less than a byte per message, so lets call it 50 bytes for a round trip.  Physically, since the network roundtrip time is O(100 usec), lets suppose there are 5000 add-and-cancel units.  This yields 50 * 5000 = 250000 bytes = 2Mb per ticker.  Over 4000 stocks, you get 8 Gb/sec, well within the 10G capability (and this is taking grossly pessimistic estimates).</p>
<p>As far as the lower bandwidth customers are concerned, the feeds are shaped so that consumers will not drop packets (they will be slightly delayed to ensure that downstream clients don&#8217;t drop).  The network systems should be able to handle the flow.</p>
<p>&nbsp;</p>
<p>Question: Is this particular trading illegal?</p>
<p>Depends on who you ask.  Based on a strict interpretation of the Securities Act of 1934, given that the order size is an order of magnitude smaller than the bid and offer sizes, and given that no transactions actually occurred and no price was directly manipulated, there are grounds for arguing that this is not illegal.</p>
<p>My interpretation isn&#8217;t the only one at play here.  People like Joe Saluzzi (the CNBC guest who bitches and moans about HFT, currently blogging at http://blog.themistrading.com/) would argue that orderly markets are being disrupted by a flood of orders, and certainly some judges would buy the anti-HFT arguments.</p>
<p>&nbsp;</p>
<p>Question: Why would Nanex write this blog post?</p>
<p>I will give them credit for one thing: &#8220;This cannot be dismissed as a computer problem or glitch. This can&#8217;t be explained as stupidity or some oversight. It is not pinging for hidden liquidity. And it&#8217;s certainly not price discovery. As far as we can tell, it&#8217;s not adding liquidity or narrowing the bid/ask spread.&#8221; is a true statement.</p>
<p>I suspect that their systems weren&#8217;t able to handle the volume.  They are, after all, selling software.  I can envision a customer complaining that their feeds were delayed.  As a technology provider, it is easy for them to write a blog post blaming the markets <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Should a customer use the raw data feed?  Without at least 1G pipes, it makes absolutely no sense to get the raw feed.  The performance of a processed feed, especially given that the data rate will be orders of magnitude lower than the raw feed, far exceeds the raw feed when connecting over 100Mb/s connection.</p>
<p>&nbsp;</p>
<p>FYI: I am amazed at how many people stumbled upon this blog looking for a how to build a faster limit order book.  It&#8217;s very possible that a lot of people are suffering, so I probably should tone down my criticism a little bit.  However, they are selling software to handle the market data &#8230;</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/veyronb.wordpress.com/56/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/veyronb.wordpress.com/56/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/veyronb.wordpress.com/56/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/veyronb.wordpress.com/56/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/veyronb.wordpress.com/56/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/veyronb.wordpress.com/56/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/veyronb.wordpress.com/56/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/veyronb.wordpress.com/56/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/veyronb.wordpress.com/56/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/veyronb.wordpress.com/56/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/veyronb.wordpress.com/56/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/veyronb.wordpress.com/56/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/veyronb.wordpress.com/56/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/veyronb.wordpress.com/56/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=veyronb.wordpress.com&amp;blog=22977769&amp;post=56&amp;subd=veyronb&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://veyronb.wordpress.com/2011/08/30/dear-nanex-please-explain-this/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/029dda212fa2d251bde2cfa1afba3976?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">intransigence123</media:title>
		</media:content>
	</item>
		<item>
		<title>Bootstrapping an Ultra Low Latency Trading Firm, Part 4</title>
		<link>http://veyronb.wordpress.com/2011/08/08/bootstrapping-an-ultra-low-latency-trading-firm-part-4/</link>
		<comments>http://veyronb.wordpress.com/2011/08/08/bootstrapping-an-ultra-low-latency-trading-firm-part-4/#comments</comments>
		<pubDate>Tue, 09 Aug 2011 01:06:27 +0000</pubDate>
		<dc:creator>intransigence123</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://veyronb.wordpress.com/?p=35</guid>
		<description><![CDATA[The Kickstarter was awash.  I&#8217;m looking into other ways, but unfortunately I can only allocate  .001% of my time &#8230; and as it turns out, blogging is much harder than it looks :/  Hopefully this is interesting / useful to &#8230; <a href="http://veyronb.wordpress.com/2011/08/08/bootstrapping-an-ultra-low-latency-trading-firm-part-4/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=veyronb.wordpress.com&amp;blog=22977769&amp;post=35&amp;subd=veyronb&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>The Kickstarter was awash.  I&#8217;m looking into other ways, but unfortunately I can only allocate  .001% of my time &#8230; and as it turns out, blogging is much harder than it looks :/  Hopefully this is interesting / useful to others and conveys some of my personal zeal &#8230;</p>
<p>I was going to talk about latency numbers last week, but in light of the last few trading days (especially Thursday&#8217;s market collapse and today&#8217;s slide), a lot of people emailed me asking about risk. Someone asked me about Fixnetix, claiming &#8220;<a href="http://www.fixnetix.com/articles/display/129/">20+ pre-risk checks taking less than a 100 nano seconds</a>&#8220;.  And since time is really really hard to come by (yes, we all saw what happened over the last few trading days), I decided to answer the most commonly asked questions that I could pound out in a few minutes on my iPhone:</p>
<p>Question: How do you measure and approach risk?</p>
<p>There are quite a few measures of risk, some of which are covered in many books. VaR (value at risk) is one commonly thrown about. But for the types of strategies we are discussing, the portfolio gross exposure is the main criteria (sum of the absolute dollar positions).</p>
<p>Question: how much collateral do you need?</p>
<p>Answer: Quite simply, if you are closing positions at the end of each day, it makes no sense not to use as much intraday leverage as possible.  After all, since you are not holding overnight positions (where major moves can happen with no ability to react), you dont pose as much of a risk to a broker as a trader who holds positions overnight.  And if you don&#8217;t need to commit capital to the risk deposit, you can use the extra money to pay other expensive bills.</p>
<p>Question: How are you making money in this environment?</p>
<p>Answer: That will have to wait <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p>Question: How do you calculate the risk quickly?  is 100nsec achievable</p>
<p>Answer: Unless they are referring to average case with some very nasty tails, I call BS.  Let&#8217;s suppose you are running a basket strategy involving 500 tickers (S&amp;P index).  You need to take the total sum of dollar positions across all tickers.  Evaluating that sum itself, whilst maintaining a map with ticker as the keyword, is expensive.  Even if you incrementally update (update the gross position every time the price changes), and you are pumping a million orders per second, and prices are changing left and right as they did over the last few days, the numbers dont add up.</p>
<p>tl;dr: The most plausible explanation is that they aren&#8217;t doing all of the required checks.</p>
<p>Question: How do you decide when to take a loss on a trade (if  you hold a position for a long time)?</p>
<p>Answer: Unfortunately there is no quantitative way of defining a hardstop.  That&#8217;s where CNBC comes in handy <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />   In all seriousness, it&#8217;s very hard to quantify exactly how the decision is made, but it mostly stems from understanding the strategies, how they behave, and what conditions could cause aberrant behavior.  I really wish there were something more algorithmic involved, but in my experience algorithmic methods will be more conservative (resulting in taking losses early rather than waiting until conditions improve).</p>
<p>Question: How do you efficiently implement the order book?</p>
<p>Answer: I realized I wrote hash implementation, but the starting point is how to most efficiently implement a hash function.</p>
<p>All implementations require a hash off the top (for symbols &#8212; you can&#8217;t mix orders from different symbols).  Some extremely parsimonious implementations may require another table for order id, since some basic info like symbol and side are fixed throughout the life of the order.</p>
<p>Some people have asked for some hints, and also asked that I don&#8217;t spoil it immediately, so the full solution will have to wait.  However, I will mention one thing: most strings you will have to hash are generally 8 characters long.  For example, if you decide to work with CUSIPs and throw out the check digit, you are left with 8 characters.</p>
<p>That being said, and I&#8217;m really disappointed I have to mention this (a lot of self-professed C / C++ experts were unaware that this was even possible):</p>
<p>Assuming that you are dealing with ascii 8-bit characters (true of all data interchange formats that I&#8217;m aware of), you can convert between 8-character strings and 64-bit numbers:</p>
<p>char *t = &#8220;VEYRONB &#8220;;</p>
<p>uint64_t u =*(uint64_t *)t</p>
<p>I believe C++ has a special keyword reinterpret_cast:</p>
<p>uint64_t u = *reinterpret_cast&lt;uint64_t *&gt;(t);</p>
<p>Lots of basic operations are easy to implement.  As a warmup to the people who asked, I suggested they implement some stuff from libc (like strncmp) using this representation.</p>
<p>Question: Are you going to take this site down, like the WK Selph character?</p>
<p>Answer: Unequivocally no.  Unless, of course, this turns out to be a personal liability, in which case as much as possible will be preserved.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/veyronb.wordpress.com/35/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/veyronb.wordpress.com/35/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/veyronb.wordpress.com/35/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/veyronb.wordpress.com/35/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/veyronb.wordpress.com/35/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/veyronb.wordpress.com/35/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/veyronb.wordpress.com/35/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/veyronb.wordpress.com/35/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/veyronb.wordpress.com/35/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/veyronb.wordpress.com/35/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/veyronb.wordpress.com/35/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/veyronb.wordpress.com/35/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/veyronb.wordpress.com/35/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/veyronb.wordpress.com/35/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=veyronb.wordpress.com&amp;blog=22977769&amp;post=35&amp;subd=veyronb&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://veyronb.wordpress.com/2011/08/08/bootstrapping-an-ultra-low-latency-trading-firm-part-4/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/029dda212fa2d251bde2cfa1afba3976?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">intransigence123</media:title>
		</media:content>
	</item>
		<item>
		<title>Bootstrapping an Ultra Low Latency Trading Firm, Part 3.1</title>
		<link>http://veyronb.wordpress.com/2011/08/06/bootstrapping-an-ultra-low-latency-trading-firm-part-3-1/</link>
		<comments>http://veyronb.wordpress.com/2011/08/06/bootstrapping-an-ultra-low-latency-trading-firm-part-3-1/#comments</comments>
		<pubDate>Sat, 06 Aug 2011 05:48:24 +0000</pubDate>
		<dc:creator>intransigence123</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://veyronb.wordpress.com/?p=42</guid>
		<description><![CDATA[I would hope that anyone who stumbles upon this blog noticed the absolute mayhem over the past few days (and naturally concluded that I was too busy This gets a .1 because it&#8217;s too long for a comment, too short &#8230; <a href="http://veyronb.wordpress.com/2011/08/06/bootstrapping-an-ultra-low-latency-trading-firm-part-3-1/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=veyronb.wordpress.com&amp;blog=22977769&amp;post=42&amp;subd=veyronb&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I would hope that anyone who stumbles upon this blog noticed the absolute mayhem over the past few days (and naturally concluded that I was too busy <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>This gets a .1 because it&#8217;s too long for a comment, too short for &#8216;Part 4&#8242;, and I can barely stay awake at this point (haven&#8217;t slept since Wednesday, unfortunately)</p>
<p>Question: Can you provide market data to play with?</p>
<p>Answer: I would have to register as a vendor of record for various exchanges and other companies, and even then I wouldn&#8217;t be able to just share it with the rest of the world.  That being said, I had the following link in my history:</p>
<p>ftp://emi.nasdaq.com/ITCH/</p>
<p>This is for NASDAQ data in ITCH 4.1 format, but other NASDAQ OMX exchanges (e.g. BX) use the same format.</p>
<p>There are many vendors of record who will be able to resell market data at reasonable prices.</p>
<p>Question: Can you provide timestamped market data?</p>
<p>Answer: All of the aforementioned links are provided by the exchanges themselves. They only contain the exchange timestamps.</p>
<p>Question: What if I pay you?</p>
<p>Answer: There is significant economic overhead to become a vendor of record.  This might be the kind of thing for kickstarter ( <a href="http://www.kickstarter.com/profile/proposals/83047">http://www.kickstarter.com/profile/proposals/83047</a> )</p>
<p>Email me (intransigence123@gmail.com) if you are interested in such a service.  Would you be willing to pay, say, 10$ a month + some initial signing fee (I&#8217;m guessing it will be something like $100) for current market data?</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/veyronb.wordpress.com/42/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/veyronb.wordpress.com/42/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/veyronb.wordpress.com/42/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/veyronb.wordpress.com/42/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/veyronb.wordpress.com/42/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/veyronb.wordpress.com/42/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/veyronb.wordpress.com/42/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/veyronb.wordpress.com/42/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/veyronb.wordpress.com/42/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/veyronb.wordpress.com/42/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/veyronb.wordpress.com/42/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/veyronb.wordpress.com/42/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/veyronb.wordpress.com/42/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/veyronb.wordpress.com/42/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=veyronb.wordpress.com&amp;blog=22977769&amp;post=42&amp;subd=veyronb&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://veyronb.wordpress.com/2011/08/06/bootstrapping-an-ultra-low-latency-trading-firm-part-3-1/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/029dda212fa2d251bde2cfa1afba3976?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">intransigence123</media:title>
		</media:content>
	</item>
		<item>
		<title>Bootstrapping an Ultra Low Latency Trading Firm, Part 3</title>
		<link>http://veyronb.wordpress.com/2011/08/03/bootstrapping-an-ultra-low-latency-trading-firm-part-3/</link>
		<comments>http://veyronb.wordpress.com/2011/08/03/bootstrapping-an-ultra-low-latency-trading-firm-part-3/#comments</comments>
		<pubDate>Wed, 03 Aug 2011 05:37:35 +0000</pubDate>
		<dc:creator>intransigence123</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://veyronb.wordpress.com/?p=26</guid>
		<description><![CDATA[The next question provides a great segue into a discussion about the technology. Question: How can a small guy make money when companies like Goldman Sachs have phalanxes of traders and developers scanning the markets for each asset class? Answer: &#8230; <a href="http://veyronb.wordpress.com/2011/08/03/bootstrapping-an-ultra-low-latency-trading-firm-part-3/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=veyronb.wordpress.com&amp;blog=22977769&amp;post=26&amp;subd=veyronb&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>The next question provides a great segue into a discussion about the technology.</p>
<p>Question: How can a small guy make money when companies like Goldman Sachs have phalanxes of traders and developers scanning the markets for each asset class?</p>
<p>Answer: technology. And cleverness.  But let&#8217;s focus on technology for the moment.</p>
<p>At a high level the trading platform must do the following:</p>
<p>1) receive market data and order information from the exchange<br />
2) organize the data in a meaningful way<br />
3) decide to do something.<br />
4) tell the exchange what you want to do.</p>
<p>Discount brokerage houses like interactive brokers provide tools to abstract away some of the nuances of 1,2,4 by providing an API.</p>
<p>In many of the banks and larger hedge funds, there are actual traders who do not necessarily care about the nitty gritty implementation details, so on-staff developers try hard to provide a low latency API. Still, at the end of the day, they are providing a wrapper that introduces delays in the critical path.  This allows for a class of &#8220;burst&#8221; strategies (which I vaguely<a href="http://news.ycombinator.com/item?id=2828804"> outlined in a HN post</a>).</p>
<p>Many of those larger entities have been around for a very long time, and it&#8217;s hard to migrate a hundred-man team from one platform to a new one.  There are so many operational risks involved, and missing a trading day could cost millions of dollars.  This is true in many software houses, and <a href="http://www.joelonsoftware.com/articles/fog0000000069.html">Joel Spolsky wrote about this more than a decade ago</a>.</p>
<p>Question: So you are starting from a blank slate.  How do you start developing?</p>
<p>Answer: For various reasons, (2) is the natural entry point (historical data can be used in lieu of real data, strategy requires data, and building an order book simulator can initially obviate the need for true exchange order entry), so let&#8217;s start here.</p>
<p>At the end of the day, no matter what asset class, for each symbol there are four few numbers we are interested in:</p>
<p>- Price at which I can buy the asset (Pb)</p>
<p>- Price at which I can sell the asset (Pa)</p>
<p>- Amount that I can buy (Qb)</p>
<p>- Amount that I can sell (Qa)</p>
<p>Note: There are nontrivial amounts of information that can be calculated.  A common interpolated fair-value measure used in many predictive signals, called the weighted-mid-market-price, can be calculated as WMM = (Pb * Qa + Pa * Qb) / (Qa + Qb), but I will save this for a more quant-oriented post.</p>
<p>Data comes in one of a few forms.  The easiest form to handle is the price-level feed.  The Consolidated Quote feed (CQS), which is a regulatory feed that describes the top of book prices for each exchange, is a price feed.  Each message tells you, for some ticker, the price and quantity at the top of the book (so there&#8217;s no need to do any extra legwork).  You could store this information in a simple C struct for each ticker, using some sort of dictionary to simplify the ticker to struct mapping.  Updating is straight forward: just overwrite the last data point.</p>
<p>A more complicated form is the order feed.  Check the <a href="http://nasdaqtrader.com/content/technicalsupport/specifications/dataproducts/NQTV-ITCH-V4_1.pdf">NASDAQ ITCH 4.1 Specification</a> for an example.  The exchange manages all of the open buy and sell orders in two priority-sorted structures, where new orders are placed in their proper place based on their relative priority (the comparison function involves the prices and the time that the order was sent).  Historically, the actual mechanism involved a physical ledger, hence the name &#8220;Order Book&#8221;.</p>
<p>The trade mechanism is straightforward: When a new buy order is sent, if there is someone willing to sell at the order price or lower, a trade occurs.  The highest priority sell order is offset with the buy, and then the next orders is considered until the entire buy order is filled or there are no sell orders at the buy price.</p>
<p>Most of these exchanges use a price-time priority rule.  To understand, lets use a simple example:</p>
<p>Alice sends an order to buy 100 shares of BAC at 1.01</p>
<p>Bob sends an order to buy 100 shares of BAC at 1.02</p>
<p>Eve sends an order to buy 100 shares of BAC at 1.01</p>
<p>Now, Sally sends an order to sell 150 shares of BAC at 1.00.  Since Sally&#8217;s sell price is lower than the largest buy price (1.02), a trade will occur.  Who will actually end up buying Sally&#8217;s shares?</p>
<p>We start at the best price and walk down.  In this case, since Bob&#8217;s order is the largest price, his order is filled first.  Bob&#8217;s order for 100 shares is fully executed, and Sally receives a notification that 100 shares were filled.  Then, there are 50 shares left for Sally at 1.00.  Now, Alice and Eve&#8217;s orders are at the same price.</p>
<p>Order feeds are direct in the sense that it shows you every limit order** and action that enters the exchange.  The traditional way to make sense of order data is to effectively replicate what the exchange does: maintain the order book structure and update every time a new message comes in.  There are three fundamental types of messages:</p>
<p>- New Order (someone sends a limit order, and the exchange accepts it without offsetting against another order)</p>
<p>- Cancel Order (someone cancels part or all of the order and the exchange removes it from their book)</p>
<p>- Trade (an actual trade occurs)</p>
<p>Other actions, such as &#8216;Replace Order&#8217;, can be described in terms of the base actions (in this case, a Replace is an atomic Cancel + Add).</p>
<p>Question: Price-level feeds make sense.  How do you process Order feeds?</p>
<p>Answer: Depending on the type of strategy you want to run, you may need quick access to certain pieces of information.  Most strategies just need to know the 4 pieces of information from above.  Some require more.  The development pathway, as you can imagine, is:</p>
<p>What does the strategy do? &#8211;&gt; What pieces of information do I need?  When do I need it?  How frequently must it be updated? &#8211;&gt; What is the best order book structure?</p>
<p>Question: What are some common types of order book structure?</p>
<p>Answer: I may not end up describing every part of the structure.  For example, to optimize order lookup and still keep the structure, the most obvious approach is to keep a parallel hash table mapping order ids to order information to basic order information.  If some details sound vague, it&#8217;s because I&#8217;ve glossed over most implementation details &#8212; and yes, the devil is in the details here.</p>
<p>- List-of-Lists or Array-of-List: All of the orders for a price level are stored in a linked list, and these linked lists are arranged in another linked list or array.  Visually, an array of list would look like this:</p>
<p>102 &#8211;&gt; Bob</p>
<p>101 &#8211;&gt; Alice &#8211;&gt; Eve</p>
<p>This structure makes it very easy to answer questions like &#8220;how many shares do people want to buy at price 1.01?&#8221; or &#8220;How many shares are behind my order?&#8221; It also benefits from locality (action at or close to the inside market can be processed quickly).  However, other operations take many steps or require too much memory (how would you implement adding an order?  Most likely, it either involves a hash table lookup  or walking the linear price list)</p>
<p>- Priority queue (e.g. heap): Just forget the elaborate structures and keep all of the orders in sorted order.  Locality is a bit harder to exploit, but there are definitely fewer moving parts than the list of lists.</p>
<p>- Skip lists: These structures involve multiple linked lists with increasing distance so as to reduce the number of steps required to walk to a particular order.</p>
<p>Now, some operations are fast in some implementations but could require a linear scan or other slow operation in other implementations.  For example, there&#8217;s no simple way given the priority queue implementation to count how many shares are behind yours.</p>
<p>Question: So how do you efficiently implement the underlying primitives (such as hash tables)?</p>
<p>Answer: That will come in the next post <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>**Caveat: Not every order is transmitted in the feed.  In particular, for venues that support it, hidden orders are not disseminated until a trade occurs, and the order-level feeds explicitly mark those trades in a different way from normal trades.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/veyronb.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/veyronb.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/veyronb.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/veyronb.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/veyronb.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/veyronb.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/veyronb.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/veyronb.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/veyronb.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/veyronb.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/veyronb.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/veyronb.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/veyronb.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/veyronb.wordpress.com/26/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=veyronb.wordpress.com&amp;blog=22977769&amp;post=26&amp;subd=veyronb&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://veyronb.wordpress.com/2011/08/03/bootstrapping-an-ultra-low-latency-trading-firm-part-3/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/029dda212fa2d251bde2cfa1afba3976?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">intransigence123</media:title>
		</media:content>
	</item>
	</channel>
</rss>
