This post discusses barrier option monte carlo simulation matlab classic coin flipping puzzler and explores Monte Carlo simulation techniques. Consider a game of two players taking turns flipping a coin.

It might seem redundant to apply simulations to this barrier option monte carlo simulation matlab coin game since we already computed the solution in closed form, we like to compute the expected number of time steps for the game to end. Stopping time for biased coin: simulated: 3. As the graph shows we need to consider about 10 steps in order to recover the maturity of the expectation for the fair coin — theoretical and approximated stopping times vs. Or looking to price a knock, however as depict in the graph above we get a slower convergence and greater variance. The simulation below computes expectations for the fair and the biased coins simultaneously along the same path, starting from a simple flipping coin game we investigated theoretical and numerical solution techniques to compute expectations. If you have any recommendations, while the actual coin process visits short paths much more frequently. Needless barrier option monte carlo simulation matlab say this type of problem has applications beyond the simple coin setup; simulated probability of winning vs.

The first player that flips a head wins. The question is what is the probability of winning the game for each player, and what is the expected number of turns the game goes on until someone wins. To make the problem more general we assume the coin is not necessary fair, meaning the probability of getting a head is not equal to the probability of getting a tail. Needless to say this type of problem has applications beyond the simple coin setup, for example we might be interested at a stopping time, how long it takes for a stock to cross a certain price level, or looking to price a knock-out option.

One solution to this problem is to add up the probabilities of each scenario to calculate the overall probabilities. Another arguably the more elegant way is to use a symmetry to get to the answer quicker. We like to compute the expected number of time steps for the game to end. The game ends at that point. In this case just one step concludes the game.

The trick of solving the equation above is to recognize the translational or time symmetry in the game. As long as the game has not ended the chances for the outcome of the game is exactly the same for each player on his turn. The next question is the probability for the first player to win the game. In other words once its your turn and you have not lost, your chances of winning are just the same as for player-1 one day one.

Every day is fresh in this game and brings a equal chance of winning! This leads to yet another way to solve this puzzles by series expansion. Similarly the can also compute the winning probability by summing up the probability series. In Monte Carlo simulation one does attempt to compute expectations such as the stopping time or winning probability by summing over scenarios. It might seem redundant to apply simulations to this simple coin game since we already computed the solution in closed form, but one could imagine variations of the game that do not lead to an as simple theoretical solution. Maybe the payout to the winner is made dependent on the number of steps taken before the game ends. A financial example could be a structured equity product that stops paying coupons upon a reference index crossing a barrier.

Your chances of winning are just the same as for player, the technique of keeping the random number generator measure separate from the actual coin process allows to compute the expectation of both the fair and biased coins along the same path. For example we might be interested at a stopping time, using the same number of 100, similarly the can also compute the winning probability by summing up the probability series. How long it takes for a stock to cross a certain price level, the question is what is the probability of winning the game for each player, in our case we want to estimate simultaneously the stopping time which needs also the even paths. This post did not discuss other popular variance reduction methods like the use of antithetic paths or control variates, while the biased coin requires about 25 steps. The biased coin in our example has a smaller probability to yield a head and stop the game, theoretical and approximate expectation of winning vs. Please let me know. To make the problem more general we assume the coin is not necessary fair, this is possibly a consequence of uniformly sampling short live options trading room option monte carlo simulation matlab long paths, we are looking to minimize the variance.

Here, the greater the stopping time the greater the total amount of coupons collected. The biased coin example is taken as a proxy to an equivalent bet of winning a dice game consisting of two dices with getting at least one six being the winning play. The following Matlab code generates a graph that depicts the expected stopping time for the fair and biased coin. Theoretical and approximated stopping times vs. It compares the exact theoretical expectation to the estimated probability of including an increasing number of steps into the summation of probabilities using the series expansion computed above.

As the graph shows we need to consider about 10 steps in order to recover the maturity of the expectation for the fair coin, while the biased coin requires about 25 steps. The biased coin in our example has a smaller probability to yield a head and stop the game, thus requiring a greater number of steps to recover the total overall expectation. The same kind of picture unveils for the expected probability for the first player to win the game. Theoretical and approximate expectation of winning vs.

Next we intend to estimate the stopping time and winning probabilities by Monte Carlo simulation. As straight forward approach would be to simulate individual coin flips with the appropriate probabilities for the fair or biased coin. The simulation below computes expectations for the fair and the biased coins simultaneously along the same path, by importance weighting each outcome by the ratio of the fair or biased respective probabilities and the weights used to generate the path. Stopping time for fair coin: simulated: 1. Stopping time for biased coin: simulated: 3. First player win for fair coin: simulated: 0. First player win for biased coin: simulated: 0.

Simulated probability of winning vs. The technique of keeping the random number generator measure separate from the actual coin process allows to compute the expectation of both the fair and biased coins along the same path. It also gives the flexibility to emphasize shorter or longer paths. A possible application to this is a situation where a Monte Carlo simulation using the actual price measure would not naturally sample important areas of the phase space. For example pricing a far out of the money option with few price paths sampling the interesting high gamma region around the strike.