Pages

Thursday, 27 August 2015

Gambling and Expected Value: NHL Lotto (OLG)

In this post on Gambling and Expected Value, we look at the "NHL Lotto" lottery offered by the OLG.
Click here to find similar posts on other lotteries and games of chance.

NHL Lotto (OLG)

NHL Lotto a lottery offered by the Ontario Lottery and Gaming Corporation (OLG). 

How the Game Works

To play NHL Lotto, the player selects a combination of 5 numbers chosen from 1 to 30, and an NHL team (of which there are also 30 options). Numbers cannot be repeated and the order is not important. The player also has the option of having the computer generate a random selection instead (known as "Quick Pick" in lottery vernacular). The game involves two portions, the "Instant Win" and the "Nightly Draw". In the Instant Win portion, you watch a computer-generated animation of a hockey player take three shots at a net with targets and hope that you've been randomly selected to be a winner. The system has been programmed to randomly mete out prizes based on OLGs predetermined odds of winning. In the Nightly Draw, prizes are awarded based on correctly matching the winning numbers and NHL team. It costs $2 to play NHL Lotto. 

Probabilities and Prizes

There are 13 different ways to win a prize in the Instant Win portion of NHL Lotto, ranging from $15,000 down to $2. The prize awarded corresponds to the targets hit by your computer generated hockey player, but it's not clear how exactly that translates into calculable probabilities. I'll have to assume the odds reported by the OLG are the exact probabilities programmed into their computers. But here's the summary of the Instant Win prizes and probabilities for NHL Lotto:

Summary of prizes and their probabilities in the Instant Win portion of NHL Lotto

There are 142,506 unique combinations of five numbers that can be chosen from the numbers 1 to 30. The number of combinations of items you can choose from a set without repetition is calculated using the following formula:

 \binom nk = \frac{n!}{k!(n-k)!},

where k is the number of items chosen, n is the total number of item to choose from, and ! denotes the factorial function. In this case, n = 30 and k = 5. But you also choose one hockey team out of 30 possible choices. You could repeat the above calculation for n = 30 and k = 1, but it should be intuitively obvious that there are 30 possible ways to pick one hockey team out of the 30. So in total there are 30 times 142,506 = 4,275,180 unique combinations of one NHL team plus 5 numbers chosen from the numbers 1 to 30.

The probability of matching some number of the winning 5 can be calculated from the hypergeometric distribution. The formula looks like this:

Equation 1 (general lottery prize probability formula)

where p is the probability of winning, n is the size of the set of numbers the winners are drawn from, k is the size of a combination, and r is the number of matching numbers required to win the prize. For example, to calculate the probability of matching four numbers in NHL Lotto, r = 4, k = 5, and n = 30. Plugging in the numbers gives the probability of approximately 0.088%, or about 1 in 1,140 (note this probability reflects the combined probability of winning either the 3rd or 4th prizes).

We can treat the NHL team matching as a bonus number drawn from a separate pool of numbers. The formula to calculate the probability of matching r out of k winning numbers plus a bonus number that is drawn from a separate pool of m numbers is a slight modification of Equation 1:

Equation 2 (general lottery with separate bonus number prize probability formula) 

Here is a table summarizing the payouts of the Nightly Draw portion of NHL Lotto and their probabilities:

Summary of prizes and their probabilities for the Nightly Draw portion of NHL Lotto.

Since for some of the prizes matching x out of 5 numbers has two different prizes depending on whether or not you match the NHL team, the probability has to be adjusted for overcounting. The probability of matching with the bonus is calculated from Equation 2 (m = 30). The probability of matching without the bonus is calculated from Equation 1 minus Equation 2.

So there's roughly 66.7% chance you lose on the Instant Win game and 94.5% you lose on the Nightly Draw. The combined probability of losing both games is calculated by multiplying the two probabilities together, which works out to a 63.1% probability that an NHL Lotto player has just thrown his money away.

Expected Value

Expected value here is pretty straightforward to calculate, just multiply each of the possible prizes by its respective probability, sum all the products, and then subtract the cost of the ticket. For example, the $100,000 prize in the Nightly Draw multiplied by the 1/4,275,180 probability of winning contributes an expected value of $100,000/4,275,180 (about 2.34 cents) to the overall expected value of an NHL Lotto ticket.


Summary of expected values of the prizes in the Instant Win portion of NHL Lotto

Summary of expected values of the prizes in the Nightly Draw portion of NHL Lotto
with overall expected value and house edge of NHL Lotto

From the tables, you can see there's a house edge of about 41.3%, meaning an average of 41.3 cents from every dollar spent on NHL Lotto goes straight to the OLG.

It's interesting to compare the two games. The total expected value of the Instant Win prizes is more than 4 times the expected value of Nightly Draw prizes. Similarly, the probability of getting a payout in the Instant Win portion is about 6 times the probability of getting a payout in the Nightly Draw. The OLG cleverly use a little computer animation, which is probably slightly entertaining to watch, and the fact that you get a payout about a third of the time, to hook people on the game. Most people appreciate that the chance of winning exists only if they buy a ticket, but don't really appreciate how minuscule that chance might be. The Nightly Draw is there to give players hope. The thinking is that if you lose the Instant Win game, well at least you've got another shot at free money. Too bad your chance of winning anything in the Nightly Draw is much lower than in the Instant Win. The Nightly Draw is even assigned a bigger top prize, because when the payout gets bigger, people tend to be more willing to make bad decisions (like buying another ticket).

From our analysis we can draw the following conclusions:

  1. NHL Lotto has a house edge of about 41.3%, which is a little better than a 50/50 draw. In other words, on average, OLG keeps 41.3 cents of every dollar spent playing NHL Lotto. Better than a lot of lotteries, but worse than casino games.
  2. The Instant Win portion of the game is significantly better than the Nightly Draw portion, both in terms of the expected prize value (about 4 times that of the Nightly Draw), and the odds of winning a payout (about 6 times higher chance of winning than in the Nightly Draw).
  3. The combination of flashy animation, small and relatively frequent payouts, and a second chance game that has a bigger top prize (but rarely pays out to anyone) is purposefully crafted to attract and hook gamblers on NHL Lotto. 

Monday, 24 August 2015

Gambling and Expected Value: Ontario 49 (OLG)

In this post on Gambling and Expected Value, we look at the "Ontario 49" lottery offered by the OLG.
Click here to find similar posts on other lotteries and games of chance.

Ontario 49 (OLG)

Ontario 49 is a lottery offered by the Ontario Lottery and Gaming Corporation (OLG). 

How the Game Works

To play Ontario 49, the player selects a combination of 6 numbers chosen from 1 to 49. Numbers cannot be repeated and the order is not important. The player also has the option of having the computer generate a random selection instead (known as "Quick Pick" in lottery vernacular). The six winning numbers are drawn at random, along with a seventh "bonus number". The bonus number is only important for the second or sixth prizes. Second prize is awarded to tickets matching 5 out of 6 numbers plus the bonus number. Sixth prize is awarded to tickets matching 2 out of 6 numbers plus the bonus number. Winnings are determined by how many of the numbers are matched. The minimum wager in Ontario 49 is $1 and additional plays are bought in $1 increments. A $1 wager buys 1 play. 

Probabilities and Prizes

There are 7 different ways to win a prize playing Ontario 49, ranging from a free ticket in a future draw to $2,000,000. The first and second prizes are capped to a total of $2,000,000 and $50,000 respectively, meaning that if there are multiple winners, the prize gets split between them.

There are 13,983,816 unique combinations of six numbers that can be chosen from the numbers 1 to 49. That number of combinations of items you can choose from a set without repetition is calculated using the following formula:

 \binom nk = \frac{n!}{k!(n-k)!},

where k is the number of items chosen, n is the total number of item to choose from, and ! denotes the factorial function. In this case, n = 49 and k = 6.

The probability of matching some number of the winning 6 can be calculated from the hypergeometric distribution. The formula looks like this:

Equation 1 (general lottery prize probability formula)

where p is the probability of winning, n is the size of the set of numbers the winners are drawn from, k is the size of a combination, and r is the number of matching numbers required to win the prize. For example, to calculate the probability of matching three numbers in Ontario 49, r = 3, k = 6, and n = 49. Plugging in the numbers gives the probability of approximately 1.765%, or about 1 in 56.7.

The second prize adds a complication because of the bonus number. The formula to calculate the probability of matching r out of k winning numbers plus a bonus number (also drawn from the pool of n numbers) is a slight modification of Equation 1:

Equation 2 (general lottery with bonus number prize probability formula)

Here is a table summarizing Ontario 49's payouts and their probabilities:


Since matching 5 out of 6 numbers has two different prizes depending on whether or not you match the bonus, the probability has to be adjusted for overcounting. The probability of matching 6 of 6, 4 of 6, or 3 of 6 numbers is calculated from Equation 1. The probability of matching 5 of 6 plus the bonus or 2 out of 6 plus the bonus is calculated from Equation 2. The remaining prizes, matching 5 of 6 but not the bonus, or 2 out of 6 but not the bonus, is calculated from Equation 1 minus Equation 2.

The last thing we need is the probability that your wager is just money thrown away. That's 100% minus the total of probabilities of winning the prizes in the table above, which works out to exactly 70,662,652,981/83,230,673,988 (about 84.9%). This means that an Ontario 49 number combination has about 15.1% chance of not losing. However, keep in mind most of those "winners" are just getting a free play in a future draw, which as you'll see in the expected value section, is almost worthless.

Expected Value

The precise expected value is a little tricky because the payout on the top two prizes depends on how many winners there were, and the value of a free play is actually significantly less than the cost of the play. Let's first start by calculating the contribution to the expected value coming from the guaranteed prize amounts. Each contribution is simply the net gain (prize minus wager) multiplied by the probability.


Next, lets calculate how much the losing tickets contribute to the expected value. Again, it's the net gain multiplied by the probability, or (-$1) * (70,662,652,981/83,230,673,988). That's about -$0.849. At this point, the expected value of a ticket, ignoring the top two prizes and the free tickets, is about -$0.609.

Next we have to figure out how much the top two prizes contribute to expected value. That depends on how many winners there are. We don't know how many winners there are, but if we know how many combinations are played, we can estimate how likely there are to be 0, 1, 2, etc. winners. This is calculated using the binomial distribution. If the probability of winning the prize is p, the probability of not winning the prize is (1-p), and N combinations are played, then probability of there being s winners of the shared pot is:


What do we need this for? Well, because the prize depends on the number of winners and the number of winners is a probabilistic function of the number of tickets sold. Therefore, we need to estimate an expected value of the prize. I've estimated that the number of combinations played in each Ontario 49 draw is on the order of 750,000. Accordingly, I've estimated the expected top prize based on there being up to 7 winners (more than 7 winners is too unlikely to be worth consideration). I've also checked N = 250,000 and N = 2,500,000 to show that the final result is not that sensitive to the accuracy of my estimate of N.

Probability of s winners of the top prize in a draw where N random combinations are played.
Expected prize amount based on
N combinations played.

The expected value of the top prize is $1,998,603.85 if 750,000 combinations are played in each draw. So for the top prize, the effect of prize sharing is pretty small, assuming my estimate of 750,000 combinations played per draw is reasonable. As you can see from the table, even if I was off by a factor of more than three and 2,500,000 combinations are played, the expected prize is still within 0.8% of the single-winner prize amount.

Working through the same process for the second prize, this time considering up to 10 winners because the likelihood of multiple second prize winners is higher, we get the following table:

Probability of s winners of the second prize in a draw where N random combinations are played.
Expected prize amount estimated based on 
N combinations played.

You can see from the difference between N = 750,000 and N = 2,500,000 that the expected payout for the second prize is little more sensitive to the accuracy of my estimate of N. But it is not excessively sensitive, so our estimate is probably still pretty close to correct.

Finally, we need to estimate the value of a free ticket. Start by taking the expected value of free ticket. It's the sum of the products of each prize and the likelihood of winning. Let's consider only the monetary prizes first.

Expected value of a free ticket, ignoring the value of additional free tickets.

Summing up the expected values of the prizes on a free ticket works out to a little under 43.5 cents. But a free ticket has roughly 12% probability of win another free ticket, and that ticket could win a monetary prize, or it could win yet another free ticket, and so on. What we have here is an infinite series that can be expressed by the equation below

The infinite summation to calculate the equivalent prize value of a free Ontario 49 ticket.
We could sum the first few terms until it converges, but it this case we have a very simple closed-form solution, shown below:

Solution to the sum of an infinite power series.
Therefore,
So winning a free ticket is equivalent to receiving a cash prize of about 49.4 cents.

We can also use a similar infinite sum to calculate the probability of getting any money back on an Ontario 49 ticket. The value of a becomes the sum of the probabilities of winning the monetary prizes and r is the probability of winning a free ticket.



Thus, after accounting for the possibility of winning money on a free ticket, the chance of winning money on an Ontario 49 play is still only about 3.52% (i.e. about 1 in 28.4).

Putting everything together now, the expected value of a single Ontario 49 play is


This means that, on average, for every dollar you spend playing Ontario 49, the OLG keeps about 50.6 cents for themselves.

From our analysis we can draw the following conclusions:

  1. Ontario 49 has a house edge of about 50.6%, which is slightly worse than a 50/50 draw. In other words, on average, OLG keeps 50.6 cents of every dollar spent playing Ontario 49.
  2. The OLG website is misleading in stating that your odds of winning are 1 in 6.6. There's only 3.52%, or 1 in 28.4, chance that you're going to win any money. 

Sunday, 16 August 2015

Beer Bongs, Volume, and Fluid Mechanics

A beer bong is a very simple device, composed of a funnel and a tube, designed to quickly get beer into the user. While you could go out and buy one, it'd be a pretty big waste of money considering how cheaply and easily you could build your own. Of course, if you do build your own, you're going to want to know a few specs so you can answer all your friends' questions, like "how much beer does it hold?" and "how fast does the beer come out?"

Though store-bought beer bongs ensure there are two scantily clad ladies for every man in attendance...

Let's start with the volume. For calculation purposes, we'll split the beer bong into three parts: the hose, the conical part of the funnel, and the cylindrical top of the funnel (if you have one). To simplify things, we'll assume that the little exit tube at the bottom of the funnel is just part of the hose. The volumes of beer in the hose and the cylindrical portion of the funnel are calculated using the cylindrical volume formula:


where D and L are the diameter and length of the cylinder, respectively. The conical part of the funnel is a cone with the tip cut off, known as a conical frustum. The volume of a conical frustum is: 


where L is the height of the frustum and D1 and D2 are the two end diameters. So, defining our beer bong geometry as in the figure below

Notation for beer bong geometry.
the volume of beer in the beer bong is calculated as


where the D's and L's are in centimetres and V is in millilitres. If your funnel doesn't have a "hopper" portion, Lfh = 0. Divide V by 341 mL/bottle if you want to know how many bottles the full beer bong is equivalent to.

If you prefer US Customary units, use this formula instead:


where the D's and L's are in inches and V is in US fluid ounces. 

So that's the answer to "how much beer does it hold?" Now for some fluid mechanics to calculate the beer velocity. We're just going to calculate the initial velocity, which is when the beer flows fastest. As the beer drains, the flow rate slows down. We start with the energy equation for fluid flow, which is


where the subscripts 1 and 2 represent two points along the flow path, u is the flow velocity (we already used V for volume), g is the acceleration due to gravity (= 9.807 m/s² = 32.18 ft/s²), z is the height above some arbitrary reference point, p is the static fluid pressure, ɣ is the fluid's specific weight, α is the kinetic energy correction factor, and hL1-2 is the loss of hydraulic head from from point 1 to point 2.

For the beer bong, we're interested in the exit velocity, so we'll make the end of the hose point 2. We'll make the surface of the beer in the funnel point 1. Both point 1 and point 2 are exposed to atmosphere, so we can take p1 and p2 to be equal and they cancel out of the equation. Because the reference point for z is arbitrary, we can choose the exit from the beer bong to be the reference point, making z2 equal to zero.


Now the energy equation looks like this


According to the law of conservation of mass for incompressible fluids, the flow rate (unit volume per unit time) of the beer must be constant. We can use this to relate u1 to u2.


We can measure z1, it's just how high the surface of the beer is above the end of the hose. If the hose is fully straightened, z1 is maximized, equal to Lfh + Lfc + Lh. Now if you want to use an easy approximation, you can assume that the head losses are negligible and the energy correction factors are both equal to 1.0. With these assumptions we can solve for the exit velocity directly


where u2 is in m/s if z is in metres and g is 9.807 m/s². You can use any units you want for D as long as you use the same units for both (e.g. you can't put one in inches and the other in millimetres). For velocity in cm/s, z is in cm and g = 980.7 cm/s². For velocity in ft/s, z is in ft and g = 32.18 ft/s².

If you want volumetric flow rate, just add the following calculation step:


If you use centimetres for Dh and cm/s for u2 (1 m = 100 cm), the flow rate will work out in mL/s. If you stick with metres for everything you'll get a pretty small number for Q because the units will be in m³/s (1 m³ = 1000 L).

We can make this approximation even easier by assuming the funnel diameter is much larger than the hose diameter (which is probably true), making the denominator of the above velocity expression very nearly 1.0, and the exit velocity is simply


As you'll see later in an example, ignoring energy losses isn't going to give you a very accurate answer, and your friends aren't going to accept some lousy ballpark estimate. So the math's going to get more intense, but I paid good money for my fluid mechanics course in university and I'll be damned if I don't find a way to put that knowledge to use.

It's safe to assume turbulent flow in the hose, and although the beer is moving much more slowly in the funnel, it's probably also in the turbulent flow regime. The kinetic energy correction factor varies depending on fluid velocity, viscosity, and pipe roughness, but a typical number is about 1.05. I'm going to assume α1α2 = 1.05.


I'm going to assume hydraulic head losses come from two sources, friction inside the hose, and the flow contraction at the funnel cone. I'm ignoring the effect of the bend in the hose, which should be okay if the bend radius is much larger than the hose diameter, but if you put a tight bend in the hose you are introducing additional losses. For the flow contraction,


Where u is the flow velocity leaving the contraction and k is an empirical factor that depends on the shape of the contraction. For typical funnel geometry, k should be around 0.07 to 0.08. I'll use 0.08. We can define a third point on the flow path, the exit of the funnel/entrance to the hose, but we won't need to do much with it. Since we've already assumed the funnel exit has the same diameter as the hose, the velocity at point 3 must be equal to the velocity at point 2 in order to satisfy the mass conservation law. Therefore, the head loss from point 1 to point 3 is


The friction loss in the hose is calculated using the Darcy-Weisbach equation


where f is the Darcy friction factor, L is the pipe length, D is the pipe diameter, and u is the flow velocity in the pipe. For our beer bong, the head loss from point 3 to point 2 is


Now things start to get more complicated. The friction factor is an empirical value that's a function of the pipe roughness, diameter, flow velocity, and fluid viscosity. But your beer bong's probably going to be made with smooth plastic or rubber hose, so we can assume a perfectly smooth pipe (i.e. ignore pipe roughness). If you're doing something crazy like using cast iron or bamboo or hollowed out whalebone, you might want to consider the pipe roughness.

The Colebrook equation is typically cited for calculating the friction factor, but it's an implicit equation, meaning you can't solve the friction factor directly, you need to solve using an iterative process. For a perfectly smooth pipe, the Colebrook equation is


where Re is the Reynolds number, which for the beer bong hose is equal to


 where η is the kinematic viscosity of the beer, typically about 1.8×10⁻⁶ m²/s, or 0.018 cm²/s. Thus,


Since we still don't know what u2 is yet, we have iterations upon iterations on our hands here. Good thing Excel can do all that for you. But if you want to solve it by hand you could cut down on your iterations by using Haaland's approximation of the Colebrook equation.


You could also use the approximate value of u2 to calculate the friction factor. It should get you a friction factor that's fairly close to the "exact" solution, so we can create a beastly-looking equation for u2 that will get pretty close to the same answer as the iterative solution from Excel.


Substituting values of 980.7 cm/s² for g and 0.018 cm²/s for η,


where L, z, and the D's are in centimetres so that u2 comes out in cm/s.

Let's do an example based on a hypothetical beer bong with some clever name like The Brain Cell Slayer, depicted in the figure below.

The Brain Cell Slayer

Volume


Initial velocity and flow rate (approximate solution)


Initial velocity and flow rate (more accurate solution)


Even though it's a smooth hose, friction has a pretty significant effect in this example, reducing the initial velocity of the beer by almost 40%. And just so you can see that our beastly-looking equation really does get you close to the "exact" iterative solution, here's what I get from Excel using the Colebrook equation for the friction factor:


References
Potter, M.C. and Wiggert, D.C. (2002). Mechanics of Fluids, 3rd Edition. Brooks/Cole, Pacific Grove, CA.