Assignment 03: Sampling and Simulation
Problem 1: Gambling randomly
Someone plays roulette as follows:
- Before each spin, they roll a die.
- They bet on red, as many dollars as the number rolled on the die. (If the die shows 1, they bet $1; if it shows 6, they bet $6.)
- If red comes up, they win back their bet plus the same amount again (so if they bet $3, they win $6). If black (or green) comes up, they lose their bet (so if they bet $3, they lose that $3).
Note that the probability of red is 18/38, black is 18/38, and green is 2/38.
Write code to simulate this game and answer the following questions:
- What is the expected value of a single spin of the roulette wheel? Calculate this by hand and by simulation. Your answers should match. (Answer in terms of dollars.)
- What is the expected value of playing this game for 100 spins? (Answer in terms of dollars.)
- What is the expected number of spins it will take until red comes up? (Answer in terms of spins.)
- What is the probability that the player will be ahead after 100 spins? 1000 spins? (Answer in terms of probability.)
Problem 2: Strategic gambling
I’m trying to develop a gambling strategy for roulette. I know that the expected value of a single spin is negative, so I don’t expect to win in the long run. But hey – gambling can be fun, right? And it’s much more fun if I win more than if I lose.
Let’s stick to the “50-50” bets (which are actually slightly less than 50-50 due to the green slots). These have the simplest odds.
The basic idea is to bet on red, but to double my bet every time I lose. So if I start with a $1 bet and lose, I bet $2 on the next spin. If I lose again, I bet $4. The idea is that when I finally win, I’ll win back all my previous losses plus a profit of $1 (my original bet). So unless I run out of money, I should eventually win. (This is called the Martingale strategy) If I win a bet, I go back to repeating my original bet of $1.
Of course, this strategy has a flaw: at some point you very well might run out of money if you keep losing. And since you keep doubling your bet, the amount you lose can grow very quickly.
Let’s set up some parameters for this strategy:
- Let’s assume you start with a fixed budget of \(B\) dollars. If you lose \(B\) dollars, you’re out of money and you can’t continue, so you end up finishing your night with a loss of \(B\) dollars.
- Let’s say you are happy to walk away with a profit of \(P\) dollars. If you win \(P\) dollars, you stop playing and walk away happy. (Remember that the odds are rigged - if you play long enough, you are destined to lose, so you have to walk away at some point.)
Write code to simulate this strategy (at least 5000 times) and answer the following questions:
- Let’s say you start with \(B = 50\) and \(P = 50\). What is the probability that you will walk away happy? (Answer in terms of probability.)
- What is the expected value of playing this strategy? (Answer in terms of dollars.)
- I told you I like to win more often. If you want to increase your chances of walking away happy, how should you adjust the values of \(B\) and \(P\)? (Answer in terms of a strategy, not specific numbers.) How does this affect the expected value of playing this strategy?
- Let’s say you want to increase your winnings, but your budget is fixed at \(B = 100\). Compute the probability of walking away happy for different values of \(P\) (e.g., \(P = 10\), \(P = 20\), \(P = 50\), \(P = 100\)). What do you notice about the relationship between \(P\) and the probability of walking away happy? Try to make a plot of the probability of walking away happy as a function of \(P\). (Look at the matplotlib documentation or seaborn documentation for examples of how to make plots, or ask AI for help with plotting.)