Q#16: Pricing a coin flip

Suppose a casino has created a new game, determined via coin toss. If the coin is tails, the individual is paid $1, and if the coin is heads it’s tossed again. On the 2nd toss (assuming heads on first toss), the individual will be paid $2 if tails, otherwise if it’s heads we continue, doubling each time to $4, $8, $16 etc for each tails. Using a Monte Carlo simulation what price should the casino charge to play this game, assuming you only want to break even?

-Credit: erik@interviewqs.com

TRY IT YOURSELF!

ANSWER:

This question requires a refresher on what a Monte Carlo based simulation is and also an understanding of statistics and probability.

Simply put a Monte Carlo Simulation is a just a technique to measure a random variable, in this case our payout, based on repetitive sampling. From statistics, recall the law of large numbers says that we can expect the expected returns to approach the true returns given a large number of sampling.

To construct repetitive sampling of the situation we need to use loops. Also, we can be clever on how to construct the situation, since the event stops whenever when we get a tails. Therefore, the reward we recieve is equal to 2^(# of heads before a tails) which can be coded as below:

import numpy as np
i = 0
game = []
while i < 20:
game.append(round(np.random.uniform()))
if game[-1] == 0:
i+=100
else:
i+=1
cnt = 0
for j in g:
if j == 1:
cnt+=1
else:
pass
2**cnt

In this code we assume a 1 is heads and a 0 is tails, the while loop is constructing a single game that truncates as soon as a tails is reached. Next, we just have to loop over the above code for many trials to get the final answer.

import numpy as npu = 0
ans = []
while u < 1000000:
i = 0
game = []
while i < 20:
game.append(round(np.random.uniform()))
if game[-1] == 0:
i+=100
else:
i+=1
cnt = 0
for j in g:
if j == 1:
cnt+=1
else:
pass
ans.append(2**cnt)
u+=1
np.mean(ans)

--

--