Gambler’s Ruin Problem [pdf]
columbia.edu
columbia.edu
You have 52 playing cards (26 red, 26 black). You draw cards one by one. A red card pays you a dollar. A black one fines you a dollar. You can stop any time you want. Cards are not returned to the deck after being drawn. What is the optimal stopping rule in terms of maximizing expected payoff?
1. Draw 26 cards.
2a. Equal to or greater than $26? Stop.
2b. Less than $26? Draw 13 more cards.
3a. Equal to or greater than $1? Stop.
3b. Equal to or less than $0? Keep drawing until equal to $0, then stop.
I'm assuming I want to always stop at a non-negative value, else I'd pay the house on the way out. If ending with a negative value has no consequences beyond the game itself, then just stop at 2b after drawing.
You are correct though that you'd never want to stop on a negative number, as you always can execute 3b
Anyway, my logic is if I am at or higher than the median after I have drawn half the deck, then that means there are more black cards than reds in the remaining deck and I have a greater chance each draw of losing a buck than gaining.
So it is in my best interest to pull out at that point, than to try my luck against ever worsening odds.
That calculation is presumably the tricky part… integrating over Pascal’s Triangle or something. But it must be positive to start: If the first card is red we have already gained, and if it’s black we’re at worst back where we started.
#awesome feature from Python 3.9!
from functools import cache
@cache
def ev(score, cards_left):
if cards_left == 0: return 0
up_cards_no = (cards_left - score) / 2
p_up = up_cards_no / cards_left
p_down = 1 - p_up
return max(score, p_up * ev(score + 1, cards_left - 1) + p_down * ev(score - 1, cards_left - 1))
>>> ev(0,52)
2.6244755489939253
Of course we should continue if the current score is lower than ev. Here is the script to find exact thresholds at which we should stop drawing more cards: def find_thresholds():
print(f"EV of tha game: {ev(0,52)}") # fill the cache up
for i in range (0,10):
thres = 52 - i
while ev(i, thres) > i:
thres -= 2
print(f"At score {i} you should stop drawing with {thres} cards left")
>>> find_thresholds()
EV of tha game: 2.6244755489939253
At score 0 you should stop drawing with 0 cards left
At score 1 you should stop drawing with 3 cards left
At score 2 you should stop drawing with 8 cards left
At score 3 you should stop drawing with 17 cards left
At score 4 you should stop drawing with 28 cards left
At score 5 you should stop drawing with 41 cards left
At score 6 you should stop drawing with 46 cards left
...
Being up 6 or more we should always stop. The last interesting number is being up 5.It's actually quite simple. In a fair game you expect to leave with as much money as you started with. initial money = expected final money = p * all money
Also, it's not quite clear to me why in this case initial money = expected final money. For the related game where you go double-or-nothing on each bet, it's evident this holds since the expected value of your next turn is the same as your current (I believe it's called martingale property), but that doesn't hold for the game in the article where you win +1 or -1 unit each bet, since if you e.g. have 4 units and the win state is 5 units, you're more likely to win than lose.
Edit: nevermind, I think it is a martingale since if you're at 4 units the expected value of the next state is 0.5*5 + 0.5*3 = 4. I guess my confusion stemmed from the fact that even though the long-term expected value is unchanged, you can still have good odds of winning (which is balanced by a small chance of a catastrophic loss), e.g. 4 = 0 * 1/5 + 5 * 4/5.
Start with a dollar, after several tosses you have `r^(head-tail difference)' dollars. The game ends if head-tail difference is `N - i' (with probability `x') or if head-tail difference is `-i' (probability is `1 - x'). The expected value is still a dollar:
1 = x r^(N - i) + (1 - x) (1/r)^i
Solve this equation for x.
So after winning a trade(s) you increase the amount you are risking and after loosing you decrease the amount you are risking.