<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Hack the market &#187; monte-carlo methods</title>
	<atom:link href="http://www.puppetmastertrading.com/blog/index.php/category/monte-carlo-methods/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.puppetmastertrading.com/blog</link>
	<description>Algorithmic trading experiences</description>
	<lastBuildDate>Wed, 21 Apr 2010 23:11:41 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Kooderive</title>
		<link>http://www.puppetmastertrading.com/blog/2010/02/03/kooderive/</link>
		<comments>http://www.puppetmastertrading.com/blog/2010/02/03/kooderive/#comments</comments>
		<pubDate>Wed, 03 Feb 2010 15:31:20 +0000</pubDate>
		<dc:creator>tito</dc:creator>
				<category><![CDATA[EMS Internals]]></category>
		<category><![CDATA[dereferenced]]></category>
		<category><![CDATA[monte-carlo methods]]></category>
		<category><![CDATA[open-source software]]></category>
		<category><![CDATA[options pricing]]></category>
		<category><![CDATA[technology]]></category>

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

		<guid isPermaLink="false">http://www.puppetmastertrading.com/blog/?p=392</guid>
		<description><![CDATA[
During some recent travels, I read William Poundstone&#8217;s ramblingly entertaining Fortune&#8217;s Formula.  It had been sitting on my shelf after I&#8217;d originally gotten it, perused it and offhandedly discarded it as yet another of these science-is-fun-and-full-of-wacky-characters books for the butch humanities student.  My initial impression was a bit harsh as the book proved entertaining and [...]]]></description>
			<content:encoded><![CDATA[<p><applet width="500" height="500" code="examples.sd" archive="/randomWalk/sd.jar" codebase="sd"></applet></p>
<p>During some recent travels, I read William Poundstone&#8217;s ramblingly entertaining <a title="Fortune's Formula" href="http://www.amazon.com/Fortunes-Formula-Scientific-Betting-Casinos/dp/0809045990/ref=pd_bbs_sr_1?ie=UTF8&amp;s=books&amp;qid=1236042231&amp;sr=8-1" target="_blank">Fortune&#8217;s Formula</a>.  It had been sitting on my shelf after I&#8217;d originally gotten it, perused it and offhandedly discarded it as yet another of these science-is-fun-and-full-of-wacky-characters books for the butch humanities student.  My initial impression was a bit harsh as the book proved entertaining and covered a lot of ground including significant coverage of Ed Thorp and his stat arb alchemy (see <a title="a stat arb story" href="http://www.puppetmastertrading.com/blog/2008/07/12/a-stat-arb-story/" target="_blank">here </a>for his own papers on the topic).</p>
<p>One of the more compelling segments of the book relates <a title="Claude Shannon" href="http://en.wikipedia.org/wiki/Claude_Shannon" target="_blank">Claude Shannon</a>&#8217;s <strong><em>demon</em></strong> which is a nice thought-experiment / trading-strategy which illustrates the tractability of the problem of trading on a random walk market with fixed properties.  I wrote the above applet to explore the impacts of applying friction and otherwise modifying the behaviors of the market and the demon.</p>
<p>The original demon posited a world with no friction in which the market contains one instrument which doubled or halved in value each day.  Shannon&#8217;s demon looks to take advantage of this volatility by maintaining a portfolio which was rebalanced each day to ensure a 50/50 split between cash and the market.  The applet implements a very simple monte-carlo test-bed for Shannon&#8217;s Demon.  You can configure the demon and the marketplace along a variety of parameters, and then run many instances of the demon, each on its own self-contained random-walk market.</p>
<p>Although Shannon&#8217;s demon is a highly &#8220;stylized&#8221; case in the sense that it operates on a very synthetic, unrealistic and favorable formulation of a random-walk marketplace, it has spawned a great deal of interest and serious research.</p>
<p>Most of all, it&#8217;s a revealing illustration of the kind of reasoning one must embrace in order to address stat arb strategy development.  Enjoy.</p>
<p>&#8212;<br />
Updated: March 4th &#8211; made price axis logarithmic to better reveal mc paths.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.puppetmastertrading.com/blog/2009/03/03/shannons-demon/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>NVIDIA&#8217;s TESLA and Compute Unified Device Architecture</title>
		<link>http://www.puppetmastertrading.com/blog/2008/11/29/nvidias-tesla-and-the-compute-unified-device-architecture/</link>
		<comments>http://www.puppetmastertrading.com/blog/2008/11/29/nvidias-tesla-and-the-compute-unified-device-architecture/#comments</comments>
		<pubDate>Sat, 29 Nov 2008 20:42:27 +0000</pubDate>
		<dc:creator>tito</dc:creator>
				<category><![CDATA[monte-carlo methods]]></category>
		<category><![CDATA[options pricing]]></category>
		<category><![CDATA[portfolio management]]></category>
		<category><![CDATA[technology]]></category>

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

		<guid isPermaLink="false">http://www.puppetmastertrading.com/blog-test/?p=3</guid>
		<description><![CDATA[
One of these days I’m going to give an overview of all the excellent open-source software I use on a daily basis.  Until that day comes, I’ll observe that finance remains one of the big areas where open-source software has made relatively limited inroads.
Two production-quality packages fight that unhappy state: QuantLib &#8211; a comprehensive [...]]]></description>
			<content:encoded><![CDATA[<p><img title="A free/open-source library for quantitative finance" src="http://puppetmastertrading.com/images/QL-title.jpg" alt="A free/open-source library for quantitative finance" /></p>
<p>One of these days I’m going to give an overview of all the excellent open-source software I use on a daily basis.  Until that day comes, I’ll observe that finance remains one of the big areas where open-source software has made relatively limited inroads.<img title="Java" src="/images/javabrew.jpg" alt="Java" align="right" /></p>
<p>Two production-quality packages fight that unhappy state: <a title="QuantLib: A free/open-source library for quantitative finance" href="http://quantlib.org" target="_blank">QuantLib</a> &#8211; a comprehensive framework for quantitative finance &#8211; and <a title="QuickFix: Open-source FIX engine" href="http://www.quickfixengine.org/" target="_blank">QuickFix</a> &#8211; a full-featured <a title="Financial Information eXchange" href="http://fixprotocol.org" target="_blank">FIX</a> engine.   Both are C++ libraries and both provide very nice interfaces to facilitate integration with other languages, including Java.  QuantLib is a big and complicated library and integrating it with Java is not totally obvious. Below, I’ll describe how to build and use QuantLib from Java.</p>
<p><a id="more-29"></a> These instructions are based on a unix installation.  I’m not really a windows developer and don’t have all the shiny tools that windows developers use, so it’s not an area of focus for me.  That said, I have managed to build QuantLib under windows by using <a title="MIinGW+MSYS: Linux in a box" href="http://www.mingw.org/" target="_blank">MinGW+MSYS</a> but it wasn’t terribly easy and I don’t currently have a working installation, so I won’t cover that here.  If this is your aim, don’t be dismayed as it is possible and it had all the functionality I enjoy under linux.</p>
<p><strong>Using QuantLib from Java (on linux)</strong></p>
<ul>
<li>Build QuantLib
<ul>
<li>Requires a working version of <a title="Boost C++ Library" href="http://www.boost.org/" target="_blank">Boost</a>.   This may prove to be the hardest step of all and you’ll need to use the ample documentation provided by the Boost team.</li>
<li>Once you have a working copy of Boost, building QuantLib should require little more than</li>
<p><code>sh autogen.sh</code><br />
<code>./configure</code></p>
<p><code>make</code><br />
<code>sudo make install</code></ul>
</li>
<li>Build QuantLib-SWIG
<ul>
<li>Requires a working copy of <a title="SWIG - Simplified Wrapper and Interface Generator" href="http://www.swig.org/" target="_blank">SWIG</a>.  Again, look to the SWIG instructions, but it should be easy.</li>
<li>Once SWIG is available, building the QuantLib/SWIG interfaces should only require:</li>
<p><code>sh autogen.sh</code><br />
<code>./configure \</code></p>
<p>&#8211;with-jdk-include=${JAVA_HOME}/include \<br />
&#8211;with-jdk-system-include=${JAVA_HOME}/include/linux<br />
<code>make -C Java</code><br />
<code>sudo make install</code></ul>
</li>
</ul>
<ul>
<li>Now you’ll have a Jar file with all of the SWIG/JNI stubs in it available in /usr/local/lib/QuantLib.jar.  Add this to your classpath.</li>
<li>Programs which call QuantLib functionality will need to have the <code>LD_LIBRARY_PATH</code> set.  This can be done by invoking the vm with something like:</li>
<p><code>-Djava.library.path=/usr/local/lib </code></ul>
<ul>
<li>Programs which call QuantLib functionality will also need to explicitly load the QuantLib libraries.  This can be done with something like the following static block appearing before your main method:</li>
<p><code> static {  // Load QuantLib<br />
try { System.loadLibrary("QuantLibJNI"); }<br />
catch (RuntimeException e) { e.printStackTrace(); }<br />
} </code></p>
<li>That’s it.  Now test your configuration by running the examples in Quantlib-SWIG/Java/examples.</li>
</ul>
<p>It’s worth understanding how Quantlib is being used from java.  SWIG is creating a JNI interface into those methods within Quantlib which have been exposed through their declaration in the swig *.i files.  These files are found in Quantlib-SWIG/SWIG and they determine what functionality from Quantlib will be available to you.  You’ll likely need to get familiar with a subset of those files that you care about. If you find that some functionality you care about isn’t exposed in those files, you may need to expose it yourself.</p>
<p>There’s a learning curve, but it’s worth traversing so you can get at all the rich functionality so many smart people have put together.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.puppetmastertrading.com/blog/2008/06/14/using-quantlib-from-java/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>monte-carlo a go-go</title>
		<link>http://www.puppetmastertrading.com/blog/2008/04/16/monte-carlo-a-go-go/</link>
		<comments>http://www.puppetmastertrading.com/blog/2008/04/16/monte-carlo-a-go-go/#comments</comments>
		<pubDate>Wed, 16 Apr 2008 14:34:26 +0000</pubDate>
		<dc:creator>tito</dc:creator>
				<category><![CDATA[dereferenced]]></category>
		<category><![CDATA[monte-carlo methods]]></category>
		<category><![CDATA[technology]]></category>

		<guid isPermaLink="false">http://www.puppetmastertrading.com/blog-test/?p=56</guid>
		<description><![CDATA[
I came across this article on a Go-playing program and thought it was interesting.  Particularly this aspect of it (from wikipedia):
One major alternative to using hand-coded knowledge and searches is the use of Monte-Carlo methods. This is done by generating a list of potential moves, and for each move playing out thousands of games [...]]]></description>
			<content:encoded><![CDATA[<p><img align="middle" title="Monte-carlo go" alt="Monte-carlo go" src="/images/mc-go.jpg" /></p>
<p>I came across <a target="_blank" title="Computer Wins a Game Against a Go Master" href="http://www.prnewswire.com/cgi-bin/stories.pl?ACCT=104&#038;STORY=/www/story/04-09-2008/0004789446&#038;EDATE=">this article</a> on a Go-playing program and thought it was interesting.  Particularly <a target="_blank" title="Wikipedia: GO and Monte-Carlo methods" href="http://en.wikipedia.org/wiki/Computer_Go#Monte-Carlo_methods">this aspect</a> of it (from wikipedia):</p>
<blockquote><p>One major alternative to using hand-coded knowledge and searches is the use of <a title="Monte-Carlo method" target="_blank" href="http://en.wikipedia.org/wiki/Monte-Carlo_method">Monte-Carlo methods</a>. This is done by generating a list of potential moves, and for each move playing out thousands of games at random on the resulting board. The move which leads to the best set of random games for the current player is chosen as the best move. The advantage of this technique is that it requires very little domain knowledge or expert input, the tradeoff being increased memory and processor requirements.</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.puppetmastertrading.com/blog/2008/04/16/monte-carlo-a-go-go/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mao&#8217;s formulation seemed more broadly applicable&#8230;</title>
		<link>http://www.puppetmastertrading.com/blog/2008/03/01/maos-formulation-seemed-more-broadly-applicable/</link>
		<comments>http://www.puppetmastertrading.com/blog/2008/03/01/maos-formulation-seemed-more-broadly-applicable/#comments</comments>
		<pubDate>Sat, 01 Mar 2008 14:26:01 +0000</pubDate>
		<dc:creator>tito</dc:creator>
				<category><![CDATA[events]]></category>
		<category><![CDATA[monte-carlo methods]]></category>
		<category><![CDATA[portfolio management]]></category>

		<guid isPermaLink="false">http://www.puppetmastertrading.com/blog-test/?p=46</guid>
		<description><![CDATA[
This week I attended another of the excellent quant seminars I&#8217;ve written about before.  This time the talk was about stochastic modeling of equity markets and was presented by Robert Fernholz of Intech.  Intech is evidently a subsidiary of Janus which manages some large amount of money presumably based on some of the [...]]]></description>
			<content:encoded><![CDATA[<p><img align="middle" alt="Mao's formulation seemed more broadly applicable..." title="Mao's formulation seemed more broadly applicable..." src="http://puppetmastertrading.com/images/mathIsPower.jpg" /></p>
<p>This week I attended another of the excellent quant <a title="Modeling Equity Markets" target="_blank" href="http://www.cfe.columbia.edu/seminars/NY_Quantitative_Finance/2007-2008/spring/Robert_Fernholz_2_28_08/seminar.html">seminars</a> I&#8217;ve written about <a title="What happened to the quants..." target="_blank" href="http://puppetmastertrading.com/blog/2008/02/04/prudent-and-disastrous/">before</a>.  This time the talk was about stochastic modeling of equity markets and was presented by Robert Fernholz of <a title="Where " target="_blank" href="http://www.intechjanus.com">Intech</a>.  Intech is evidently a subsidiary of Janus which manages some large amount of money presumably based on some of the portfolio management theory on which Dr. Fernholz is an expert.  If you visit their site, you&#8217;ll be greeted by a bigger version of their credo which I&#8217;ve, um, honored as this post&#8217;s banner: &#8220;Math is power.&#8221;</p>
<p>Right then.  While Mao would likely have been capable of convincing me otherwise, it&#8217;s probably best for everyone involved that portfolio managers are running around with esoteric mathematical models rather than the sorts of munitions favored by 20th century Chinese revolutionaries&#8230;</p>
<p><span id="more-46"></span><br />
My interest in the talk was largely spurred by my interest in a variant of a problem I&#8217;ve discussed <a title="Engineering Randomness" target="_blank" href="http://puppetmastertrading.com/blog/2008/01/06/engineering-randomness/">here</a> namely, how-to generate useful synthetic markets.  As I&#8217;d written before, the problem isn&#8217;t impossibly difficult for a constrained set of instruments.  So, generating useful models for analyzing a pair trading strategy across pairs of correlated instruments is possible and it allows you to apply option-pricing techniques to the analysis of trading strategies.  Swell.  But if I want to do the same thing for a portfolio management strategy that&#8217;s looking at, say, the entire US market things become more complex.</p>
<p>As an example, consider applying this technique to a sector rotation model.  In order for the synthetic markets you generate to produce meaningful or interesting results would seem to require that you capture the behavior of how equities within a sector interrelate and also how sectors relate to one another.  It gets complicated pretty quickly.</p>
<p>Robert Fernholz has spent many years working on this kind of problem applying tools of a mathematical sophistication I will never wield, so hearing what he had to say had to be interesting.  And it was.  I think.  His talk was very mathematically rigorous and unless you had read and digested his earlier papers beforehand, I don&#8217;t think you&#8217;d have a great shot at following him in great detail.  The high point of his talk, for me, was his sequitur following a particularly dense bunch of proofs that &#8220;&#8230;now we will leave the world of math for that of statistics&#8221;.</p>
<p>After he had spoken for an hour packed with dense slides showing increasingly realistic (and complex) models he stopped to field questions.  A couple of the professors who had hosted the event gamely tried with a few inquiries, but the rest of the crowd blinked and emitted a stony silence and a few sideways glances meant to ascertain if they were the only ones lost in space&#8230;</p>
<p>While I don&#8217;t think I was <em>deep-space-nine</em> lost, I certainly didn&#8217;t  master every point made during the talk and I don&#8217;t think I came away from it any closer to achieving my own, limited, goals wrt developing concrete techniques for applying MC simulation across so diffuse a set of instruments as a nation&#8217;s equity markets.   But it did give me an appreciation for the different approaches taken to related problems.</p>
<p>While the extremely precise theoretical approach taken by academics is ultimately necessary, the fact that Dr Fernholz spent an awful lot of work just coming up with a model in which markets didn&#8217;t necessarily devolve to one uber instrument reminded me of one of the more distasteful characteristics of philosophy.  While it may not be possible to formally prove that the chair I&#8217;m sitting on exists to the satisfaction of some kind of philosopher, it certainly isn&#8217;t profitable to argue about it.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.puppetmastertrading.com/blog/2008/03/01/maos-formulation-seemed-more-broadly-applicable/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Engineering Randomness</title>
		<link>http://www.puppetmastertrading.com/blog/2008/01/06/engineering-randomness/</link>
		<comments>http://www.puppetmastertrading.com/blog/2008/01/06/engineering-randomness/#comments</comments>
		<pubDate>Sun, 06 Jan 2008 13:46:41 +0000</pubDate>
		<dc:creator>tito</dc:creator>
				<category><![CDATA[EMS Internals]]></category>
		<category><![CDATA[monte-carlo methods]]></category>
		<category><![CDATA[open-source software]]></category>
		<category><![CDATA[performance analysis]]></category>

		<guid isPermaLink="false">http://www.puppetmastertrading.com/blog-test/?p=36</guid>
		<description><![CDATA[  
It turns out that one can actually sculpt or engineer randomness.  Further, this ability can shed remarkable light on otherwise mysterious phenomena &#8211; like the value of an option or the performance of a complex trading strategy.  The applet above is governed by the equation (for Geometric Brownian Motion) below.  [...]]]></description>
			<content:encoded><![CDATA[<p><applet width="500" height="350" codebase="/randomWalk" code="examples.RandomWalk" archive="rw.jar">  </applet><br />
It turns out that one can actually <em>sculpt </em>or engineer randomness.  Further, this ability can shed remarkable light on otherwise mysterious phenomena &#8211; like the value of an option or the performance of a complex trading strategy.  The applet above is governed by the equation (for Geometric Brownian Motion) below.  It provides you with the ability to produce a random stream with three modifiable characteristics: an initial value (in this case fixed at 100), volatility (or &#8216;diffusion&#8217;) and expected return (or &#8216;drift&#8217; or slope).  Every five seconds it will generate a new path based on the current settings.  <img title="path generator" src="/images/GeometricBrownianMotionSDE.png" alt="path generator" align="bottom" /> Hopefully, this applet provides a little insight into the machinery of a powerful algorithmic trading tool: monte-carlo methods.  <span id="more-36"></span>Just as we can permute a strategy&#8217;s parameters over some period of historical data, we can also permute synthetic data as input to our strategy.  This is one of the classic methods for pricing a wide variety of derivative instruments and it can be productively applied to the performance analysis of algorithmic trading strategies.  As a technique, it has several advantages over historical back-testing.  It doesn&#8217;t require costly market data, it allows a user to engineer key characteristics of the market(s) to be tested, and it eliminates many of the messy characteristics of the real world.  We&#8217;ll look at each of these advantages in turn.  Market data is one of the inevitable nightmares for an algorithmic trader.  It costs more than gold, comes in many forms from many sources and is all too frequently dirty.  Even when you have perfect data, the world intercedes.  Equities have splits, reverse splits, de-listings, re-listings, mergers, dividends and probably a host of other corporate actions not to mention the gazillions of &#8216;dark pools&#8217; which might all act as sources of data or at least confusion.  Futures are constantly rolling and exchanges will not infrequently change their contract specs.  Options share all of the difficulties of their underlying instruments but add a bewildering array of contracts as well as the problem of very sparse data streams for far out of the money contracts.  In sum, managing real-time and historical market data is simply an expensive and messy endeavor.  While I wouldn&#8217;t recommend going data-free, it is helpful to be able to generate synthetic data to order when a particular period or variety of market data isn&#8217;t available.  The ability to actually engineer the data that acts as input to your monte-carlo simulations is particularly powerful.  In the simple example above, I&#8217;ve only allowed you to modify a constant slope and volatility of the sequences you generate, but a sophisticated user can do much more powerful tricks.  To list just a few, one can introduce term structures for volatility, dividends, coupons and interest rates; one can spice-up one&#8217;s models with the introduction of some flavor of jump-diffusion or one can scale the process by introducing correlated multi-path sequences.  This last capability, the ability to <a title="correlated random sequence" href="http://sitmo.com/doc/Generating_Correlated_Random_Numbers" target="_blank">generate sequences of correlated random data</a>, is especially useful as it allows you to generate data for correlated markets &#8211; say gold and silver &#8211; or even simulate market micro-structure including depth of market.  This ability to engineer markets with characteristics that you define also gives you the ability to create circumstances for which you may not have available historical precedent.  This is not so uncommon as one might think.  This point is colorfully illustrated by <a title="Dr. Andrew Lo" href="http://web.mit.edu/alo/www/" target="_blank">Dr Andrew Lo&#8217;s</a> hypothetical <a title="Recipe for capital decimation" href="http://papers.ssrn.com/sol3/papers.cfm?abstract_id=671443" target="_blank">Capital Decimation Partners</a>&#8216; trading strategy which simply wrote puts on the s&amp;p500 throughout the 90&#8217;s to produce spectacular gains in the face of massive risk.  It&#8217;s a curious fact of our modern financial history that one needs to go pretty far back in time to see the US equity markets do anything extraordinarily nasty.  Building trading strategies or a business without at least considering such risks is ill-considered and the techniques we&#8217;re discussing are one way of analyzing those out-of-sample risks within one&#8217;s strategy development process.  The practice of engineering markets &#8211; writing markets &#8211; inevitably leads to an increased understanding of how to read them.  If a particular strategy works well under some kinds of market conditions, one can attempt to identify such market conditions as they unfold so the strategy can be deployed conditionally.  It&#8217;s interesting to note that while many algorithmic trading products feature some form  of back-testing and some feature some type of parameter optimization, few if any offer the kind of functionality which I describe here and which is a critical element of the Puppetmaster Trading platform.  A final comment/credit before completing this post &#8211; the applet above uses <a title="Dave Gilbert" href="http://www.jroller.com/dgilbert/" target="_blank">Dave Gilbert&#8217;s</a> excellent open source <a title="JFreeChart" href="http://www.jfree.org/jfreechart/" target="_blank">JFreeChart</a> package.  Although the applet uses its own very simple brownian motion implementation, I wouldn&#8217;t generally recommend trying to write your own monte-carlo primitives but would instead recommend using those from a mature library like that supplied by <a title="QuantLib" href="http://quantlib.org/" target="_blank">QuantLib.</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.puppetmastertrading.com/blog/2008/01/06/engineering-randomness/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A trading strategy is an option</title>
		<link>http://www.puppetmastertrading.com/blog/2007/10/10/a-trading-strategy-is-an-option/</link>
		<comments>http://www.puppetmastertrading.com/blog/2007/10/10/a-trading-strategy-is-an-option/#comments</comments>
		<pubDate>Wed, 10 Oct 2007 13:34:36 +0000</pubDate>
		<dc:creator>tito</dc:creator>
				<category><![CDATA[back-testing]]></category>
		<category><![CDATA[books]]></category>
		<category><![CDATA[monte-carlo methods]]></category>
		<category><![CDATA[open-source software]]></category>
		<category><![CDATA[options pricing]]></category>
		<category><![CDATA[performance analysis]]></category>
		<category><![CDATA[strategy development]]></category>
		<category><![CDATA[technology]]></category>

		<guid isPermaLink="false">http://www.puppetmastertrading.com/blog-test/?p=27</guid>
		<description><![CDATA[
The best way to reason about a trading strategy&#8217;s performance, that is valuing it, is as an option.
Or perhaps as a collection or portfolio of them.
I have to assume that people reading this have a working idea of what an option is, so I&#8217;m not going to provide definitions that can be readily found elsewhere. [...]]]></description>
			<content:encoded><![CDATA[<p><img alt="options, options, ..." title="options, options, ..." src="http://puppetmastertrading.com/blog/images/oneway.jpg" /></p>
<p>The best way to reason about a trading strategy&#8217;s <em>performance</em>, that is <strong><em>valuing</em></strong> it, is as an option.</p>
<p>Or perhaps as a collection or portfolio of them.</p>
<p>I have to assume that people reading this have a working idea of what an option is, so I&#8217;m not going to provide definitions that can be readily found <a target="_blank" title="option definition" href="http://en.wikipedia.org/wiki/Option_%28finance%29">elsewhere.</a> I will note that my favorite book on the trading of options is by <a target="_blank" title="Option Market Making" href="http://www.amazon.com/Option-Market-Making-Financial-Commodity/dp/0471578320/ref=pd_bbs_sr_4/102-4760953-2767316?ie=UTF8&#038;s=books&#038;qid=1192021949&#038;sr=8-4">Allen Jan Baird.</a></p>
<p>Let&#8217;s consider the three illustrative trading strategies we&#8217;ve looked at up until now.  The trend-following strategy suffered many little losses and then enjoyed a big win.  Sounds like buying options. The mean-reverting strategy made lots of little profits and then risked getting clobbered with a big loss.  Sounds like someone who&#8217;s writing options.  And the first strategy we <a title="morning range breakout" href="http://puppetmastertrading.com/blog/2007/10/02/anatomy-of-a-knockout/">looked at</a>, the morning range breakout, had a payoff which looked like a long straddle or strangle where the break-evens were near the observed high and lows for the session (where we set our entry stops).</p>
<p><img title="straddle payoff" alt="straddle payoff" src="http://puppetmastertrading.com/blog/images/straddle.gif" /></p>
<p>Now, there&#8217;s obvious differences between the trading strategies&#8217; payoff structures as compared to the similar options strategies.  There&#8217;s no premium, for instance, and that&#8217;s clearly significant.  The morning range breakout seems to exhibit a sort of knockout effect when a position has been entered but then the market reverses and you&#8217;re &#8220;knocked-out&#8221; of your position.  You just take a loss and do not collect even if the market turns back in your direction.  With a straddle you don&#8217;t have this behavior.  There are differences and they are worth keeping in mind.  But the reasons for viewing trading strategies as options portfolios are many and compelling.</p>
<p>The superficial reason, as I mentioned, is that the basic payout structures are potentially similar.  The deep reason is that ultimately the problems are the same &#8211; how to value complex instruments with engineered payouts.  And the pragmatic reason is that many many very smart people have applied their considerable brains and diverse skill-sets to advancing options pricing techniques.  There&#8217;s also a great deal of high quality software available <a target="_blank" title="QuantLib" href="http://www.quantlib.org">out there</a> which can be used to adapt these time-proven techniques to your own algorithmic trading strategy valuations.</p>
<p>The techniques which we&#8217;ve seen up until now, back-testing and parameter optimization, are sort of  weak cousins of a family of techniques long used for options pricing: Monte-Carlo (MC) methods.  MC simulation can clearly be used to assess a trading strategy&#8217;s performance.</p>
<p>In subsequent posts, we&#8217;ll talk about some of the details of each of these techniques and about some of their respective trade-offs.  That should keep my pump primed for a bit, but in the meanwhile I leave you with a parting inquiry: what other options pricing techniques might we apply to our algorithmic trading practices?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.puppetmastertrading.com/blog/2007/10/10/a-trading-strategy-is-an-option/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
