Simulation is easy, probability is hard…
There are many interesting things that can be learned about probabilistic modelling from the world of trading and finance, where, perhaps due to the direct connection to very large sums of money, attitudes to problems are generally very different to those of the typical statistician or ML practitioner. Two books I have enjoyed recently in the area are The Education of a Speculator by Victor Niederhoffer and Fooled by Randomness by Nassim Nicholas Taleb. The books are similar in many ways, both contain plenty of interesting insights into thinking probabilistically, as well as a number of cautionary tales of modelling gone wrong1. In Fooled by Randomness, Taleb talks a lot about the power of simulation for probabilistic models, and how modern computers, using what he calls his “Monte Carlo Engine”, allow us to get answers from complex models that previously would have been impossible, or at least very time consuming, to solve analytically. This was fresh in my mind when I read the following passage from chapter 8 of The Education of a Speculator about the well known gambler’s ruin problem:
A speculator with initial capital
plays a game with a casino: he wins each play with probability or loses with probability , the speculator stays in the game until his capital reaches or depreciates to . It can be shown that in such a game, the speculators probability of ruin is,
This is a very good example a problem which can be solved easily with the “Monte Carlo Engine”, or simulation in plainer language, but is actually quite difficult to solve analytically. In this post we’re going to derive the formula for the probability of ruin above analytically, and calculate the probability using simulation and hopefully along the way we’ll get a feel for the advantages and disadvantages of both methods2.
Simulation⌗
The idea behind simulation is really simple, to work out the probability that our gambler will be ruined, all we need to do is run a bunch of games in our imaginary casino, and work out the proportion of games in which the gambler loses, this then becomes our answer for the probability of ruin. We can think of each of these games as a sort of parallel universe, each is possible and distinct from the next, and taken as a whole they represent every possible situation our gambler could go through. Now you might be thinking, hang on, are there not an extremely large number (an infinite number even) of possible games? Could the gambler not keep on playing indefinitely if the correct combination of wins and losses arise such that the balance never goes higher than
So how do we actually do the simulating? We just need to have some code that can produce randomly 1 (representing the gambler winning a play) with probability
Note the Bernoulli function here just produces a 1 with probability
Analytical Solution⌗
(This section is going to be a bit more maths heavy, so if that’s not your thing then feel free to skim/skip.)
Like a lot of problems in probability, at first glance it doesn’t look too bad. Unfortunately it’s kind of hard to know where to start because of the limitless number of different games that are possible. To get going we need to use a bit of a trick3. Let’s say the probability of winning the game when we start with capital
- The gambler wins the first play with probability
and ends up with capital , the probability of going on to win the game from this position is then . - The gambler loses the first play with probability
, and ends up with capital , the probability of going on to win the game from this position is then .
We can then write
We also know that
Next write equation 2 as,
for
because for example the
using the standard result for a finite sum of a geometric series, we get
as long as
so,
which means
In the case
in cases
Comparison⌗
OK so now we have methods to calculate the probability of ruin both using simulation and analytically, let’s see how they compare. Below are plots of the probability of winning the game against the probability of winning a play

We can get a better idea about the error introduced by using the simulated method from the following plot of error against number of simulated games, with error bars computed from 5 repeats. The gradient of the graph is about 0.5 and since the axis are log scale this corresponds to the relationship

Conclusions⌗
I think the most important thing to consider when comparing the two solutions before we even think about errors, computation time etc, is simplicity. The code for the simulations took me less than 5 minutes to write. I spent about an hour trying to come up with an analytical solution with no luck, I then looked up the solution, and it took me quite a while longer to get my head round it. Even simple problems in probability can end up being analytically intractable, meaning no closed form solution can ever be found, let alone by me. For this reason Taleb is right to emphasize the power of the Monte Carlo engine, I hope this post has gone some way to illustrates it practical application.
Thanks for reading!
-
Both also contain a variety of strongly held opinions about how life should be lived, which I probably could have done without, maybe this is common in trading books? ↩︎
-
This trade-off arises all the time in ML when we are deciding how we want to do inference for a particular model, should we use stochastic sampling methods like MCMC, or something like variational inference, which requires more analytical calculations. ↩︎
-
We can approach the problem in a more rigorous way using Markov chains, see for example these handy lecture notes ↩︎