Blackjack Simulations and the Central Limit Theorem

In my last post, I discussed how to approximate the expected ROI for different decisions on a blackjack hand using a Monte Carlo approach. The problem was inspired by my brother who sent me the following snapchat:

I wanted to use a numerical approximation approach instead of a combinatorial approach because the former is much quicker and practical. The blackjack hand is the following: if we have a pair of sevens and are facing a 10, what are the expected results for different standing decisions? Should we stand on 14? If we draw an ace, should we stand on 15? What about the decision if we have 17? If you want to read more about this, you can see this link.

In this post, I want to talk about the how close these Monte Carlo approximations are to the true expected values using perhaps the most powerful result in probability theory, the central limit theorem. For the purpose of the discussion, I simplified the problem to having two decisions: either we choose to stand on 14, or we hit.

I wrote a python script that calculated the mean result over a million simulations for both decisions.

1 million trials, hitting on 14, 6 decks

If we hit, on average, we lose .477 units. This means if we bet $10 dollars, over these million trials, the mean result is -$4.77.

1 million trials, standing on 14, 6 decks

If we decide to stand, then we lose $5.33 units on average. So, it seems pretty clear that hitting is the better decision. [Not playing is the best decision!] But, how clear is it? These figures were randomly determined, so they aren’t going to equal the true means. However, the Central Limit Theorem guarantees us a few things. Before developing confidence intervals for both decisions (from the CLT), I want to lay out an understanding for this great theorem.

First, it states that given a large enough sample from a distribution with a finite variance, the means of those samples will be approximately equal to the mean of the population. As the sample size approaches infinity, the mean generated from the sample approaches the true mean of the distribution.

n is the number of samples, Xi is a random draw from the probability distribution, and mu is the true mean of the distribution

In the context of the blackjack hand, since I simulated standing on 7,7 a million times, we can be sure that the sample mean is within a small margin of error of the true mean. -$5.35 is pretty damn close to the true expected result for standing. Theoretically, if I simulated standing an infinite number of times, the sample mean obtained would be equal to the true expected value.

Next, the CLT states that the distribution of sample means will be approximately normal, centered at the true mean of the population, so long as the size of each sample is sufficiently large.

If we take samples of the same size from the distribution, calculate the mean of each sample, and plot the distribution of these sample means, this distribution will approach a normal distribution. As the size of each respective sample approaches infinity, the distribution is exactly normal, centered at the true mean of the original distribution.

The square root of n term has to do with the variance of the distribution of sample means.

Let’s see what this implies for both of our decisions at 14.

When we stand on 14, there are always two possible outcomes- a win or a loss. When we hit, there is a possibility for a push, so that distribution has three possible outcomes. Below, I plotted the results from the Monte Carlo simulations for both distributions. Since the number of trials is sufficiently large, we know that the sample distributions approximate the true distributions, a consequence of Monte Carlo.

100000 trials, standing

Out of 100,000 trials, 76878 were loses and 23122 were wins. For this sample, the average result is -0.53756 units.

100,000 trials, hitting

Above is the distribution when we decide to hit on 14. Out of 100,000 random draws from the probability distribution, 70,764 were losses, 5,813 were ties, and 23,423 were wins. The sample mean is -.47341 units.

Increasing n: Distribution of Sample Means

Next, I examine what happens to the distribution of sample means when we increase the sample size for just the standing decision. I want to show that as a consequence of the CLT, the distribution of sample means should approach a Gaussian distribution as n gets larger and larger.

For n=3, there are only four possible results when we stand: 3 wins, 2 wins 1 loss, 1 win 2 losses, 3 losses. Here is that distribution. Clearly, not Gaussian yet.

Distribution of Sample Means for n=3

The most likely result here is to get three losses, or zero wins. Since there are only two possible outcomes for standing, this is just a simple binomial distribution, where our probability of success is roughly .232 and the number of trials is 3.

When we increase the sample size to 10, we see that the distribution of sample means starts resembling a Gaussian distribution centered close to our predicted mean of -.536. The mean of this distribution is equal to the true mean, which is true for all distributions of sample means, regardless of n.

n=10, 10000 trials

Increasing n to 100 below…

n=100, 10000 trials

Looking more normal at n =5000.

n=5000, 500 trials

Regardless of what the original distribution looks like (as long as it has finite variance), when we sum up independent random variables, the shape tends towards the normal distribution.

Below is the distribution of sample means for the hitting distribution where each sample size is 100. Even though the original distribution for hitting looked different than the standing distribution (there are three possibilities, ties included), the distribution of sample means still looks approximately normal. This is true for any type of distribution with finite variance! The hitting sample distribution is centered at -0.476, which must be somewhat close to the true mean.

Distribution of sample means for hitting where n=100.

Note: It is impossible for the distribution of sample means to be exactly normal for finite n. It is still a discrete distribution of sample means that takes on a finite number of possible values. The central limit theorem says that as we increase n, the distribution of sample means approaches a normal distribution.

Variance of the Distribution of Sample Means

Notice how the spread of the distributions shrinks as we increase n. For a sample size of 5000, almost all of the sample means reside between -.56 and -.52, whereas for n=100 , we see a much wider spread from roughly -.7 to -.35. This is because as we increase n, there is a greater probability that the sample mean is close to the population mean, the first consequence of CLT I discussed. This leads us to the next result of the central limit theorem.

The variance of the distribution of sample means is equal to the variance of the original distribution divided by each sample’s size.

This is an amazing result, and the proof is beyond the scope of this post. You can see why here.

Using properties of the Gaussian distribution, we can build confidence intervals for the true mean! Let me demonstrate how we can use this result by the blackjack example. Let’s look at one sample where we decide to stand on 14, 100,000 times.

Okay, so the sample mean is -.5352. Now, let’s develop a confident interval for the true mean.

First, we need to figure out the variance of the sampling distribution. We can use this to approximate the variance of the true probability distribution. For large n, the sample variance is roughly equal to the true variance, which is given by the formula below:

Sample Variance Formula

I calculated the variance of the initial distribution to be approximately .7136.

Using the CLT, the variance of the distribution of sample means is equal to the sample variance divided by n. We get 7.135*10^-6. Taking the square root of the variance, we see that the standard deviation of the distribution of sample means is 0.00268.

68–95–99.7 Rule

Using the 68–95–99.7 rule from statistics, we can develop some basic confidence intervals. This rule states that if you randomly draw from a normal distribution, there is a 68% probability that the sample lies within one standard deviations of the mean. 95% probability it is within two standard deviations. 99.7% of the time it is within three standard deviations.

For the blackjack hand, there is a 95% chance the sample mean obtained lies within two standard deviations of the true mean. This is equivalent to stating that there is a 95% probability the true mean lies within two standard deviations of the sample mean. The latter statement is what allows us to build a 95% confidence interval.

We are 95% confident that the true mean for standing is in the following interval: [-.5405, -.5298].

There is a 68% probability that the true mean for standing is in the following interval: [-.5379,-.5325].

If we want to build a 99.7% confident interval, we have to go out three standard deviations from the sample mean to obtain the following interval: [-.5432,-.5272].

Conclusion

The Central Limit Theorem allowed us to quantify how close our numeric approximations were to the true expected results for different blackjack decisions. We saw that without any doubt, it is better to hit on 14 than stand on 14. Thus, the chart must have had an error. That error was confirmed by a not-so-choreographed snapchat that my brother sent me.