Monte Carlo in Quantitative Finance

In this post I’m going to give a little introduction to Monte Carlo as a method for integration, and try to get server-side scripting working via WordPress!

Monte Carlo is fundamentally a technique for doing numerical integration. If we’re confronted with an integral that we can’t solve analytically, we have an array of possible techniques available to us. For 1d integrals, probably the easiest thing for well-behaved functions is to use Simpson’s rule and integrate across the part we’re interested in. But to do this in many dimensions can be tricky – for each dimension we probably want the same number of partitions, so the overall number of function evaluations scales exponentially with dimension – very bad news! By contrast, Monte Carlo essentially samples the function at random points and takes an average. The higher value points contribute more to the average than lower value points, and the overall error in the average scales as \inline {1 \over \sqrt{n}}, giving a good approximation relatively quickly for high dimensional problems.

The quintessential example of a Monte Carlo experiment is a simple process to approximate pi. Consider drawing a circle inscribed into a square, just as shown in the following image:

Now, imagine scattering dried cous-cous over the whole area. They will land randomly all over the surface, and first of all we will sweep away any that fall outside of the square.

What next? Well, if we count the number of grains that fell inside the circle, and compare that to the total amount that fell inside the square, what do we expect the ratio to be? As long as they’re not too clustered, the expectation is that it will be \inline {\pi \over 4}, which is of course just the ratio of the areas.

Rather than actually counting grains, we can simulate this process on the computer much more quickly. To represent each grain, we simulate two uniform variables, each on the interval [-0.5,0.5]. We treat these as the grain’s x-coordinate and y-coordinate, and calculate the distance from the origin (0,0) by taking the sum of the squares of these. If the sum is less than the square of the radius of the circle (ie. 0.25) then the grain is ‘inside’ the circle, if it is greater then the grain is ‘outside’.

Here is the simulation run for 1000 grains of cous-cous (refresh for a repeat attempt):

Grains Simulated: 1000
Grains Inside Circle: 790
Our estimate of pi is 3.16

The estimate here is probably fairly close – you may have been lucky (or unlucky!), but we claimed that the estimate will converge to the real value of pi with a progressively larger number of grains [exercise: can you demonstrate this using the central limit theorem?]. Well, below you’ll find another simulation, this time going up to a little over a million grains but making estimates each time the number of grains is doubled, and the error in the estimate is compared to the number of grains so far at each step.

number of steps estimate error
2 4 0.858407
4 3 -0.141593
8 2.5 -0.641593
16 2.75 -0.391593
32 3.125 -0.016593
64 3.1875 0.045907
128 3.15625 0.014657
256 3.140625 -0.000968
512 3.210938 0.069345
1024 3.203125 0.061532
2048 3.152344 0.010751
4096 3.139648 -0.001944
8192 3.136719 -0.004874
16384 3.141602 9.0E-6
32768 3.139771 -0.001822
65536 3.139587 -0.002005
131072 3.139832 -0.001761
262144 3.139969 -0.001624
524288 3.142708 0.001115
1048576 3.142784 0.001191

It should b fairly straight-forward to copy-paste these figures into excel – does the error fall like \inline {1 \over \sqrt{n}} as claimed? In fact, the central limit theorem tells us that the mean of the ratio of grains inside should go to a normal distribution with standard deviation proportional to this quantity, so we should expect it to be outside the bound about 30% of the time (if you have calculated the right constant!).

Of course, in the 2 dimensional circle case, a better idea might be to try and put points evenly over the square and count how many of these fall inside/outside. As mentioned before, the benefits of Monte Carlo are most pronounced when there are many dimensions involved. But, this is something like the procedure involved in quasi-Monte Carlo, a procedure that I’ll talk about some other time that doesn’t use random numbers at all…


Hello world!

Hello and welcome to ‘What Quants Do’! On this blog I am to delve a bit into the wonderful world of mathematical finance, and the things that I do in my day job as a quant. There’ll be a mix of nice results, graphs, reviews of papers and books, and probably several streams of consciousness…

I’m also using this as an attempt to learn to use the WordPress content management system, once I work out how to integrate my own php and javascript, I also hope to include some pricers to illustrate a few of the points that I plan to cover!

Finally, I’m hoping that I’ll get a bit of discussion going, since that’s always the bit I enjoy most about other people’s blogs.

Looking forward to it!