Engineering Randomness

January 6th, 2008


It turns out that one can actually sculpt or engineer randomness. Further, this ability can shed remarkable light on otherwise mysterious phenomena – 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 ‘diffusion’) and expected return (or ‘drift’ or slope). Every five seconds it will generate a new path based on the current settings. path generator Hopefully, this applet provides a little insight into the machinery of a powerful algorithmic trading tool: monte-carlo methods. Just as we can permute a strategy’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’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’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 ‘dark pools’ 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’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’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’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’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 generate sequences of correlated random data, is especially useful as it allows you to generate data for correlated markets – say gold and silver – 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 Dr Andrew Lo’s hypothetical Capital Decimation Partners‘ trading strategy which simply wrote puts on the s&p500 throughout the 90’s to produce spectacular gains in the face of massive risk. It’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’re discussing are one way of analyzing those out-of-sample risks within one’s strategy development process. The practice of engineering markets – writing markets – 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’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 – the applet above uses Dave Gilbert’s excellent open source JFreeChart package. Although the applet uses its own very simple brownian motion implementation, I wouldn’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 QuantLib.

EMS Internals, monte-carlo methods, open-source software, performance analysis

  1. No comments yet.
  1. No trackbacks yet.