The Gambler's Ruin

success[p_,i_,c_]:=Module[{r=((1.-p)/p),T=i+c},
If[p==1/2,N[(i/T)],((1-(r^i))/(1-(r^T)))]];
expectedPlaysToRuin[p_,i_,c_]:=Module[{r=((1.-p)/p),T=i+c},
If[p==1/2,i*c,((r+1)/(r-1))(i-T*((1-(r^i))/(1-(r^T))))]];

gambleToRuinSimulation[p_,i_,c_,games_]:=Module[{playerval=i,houseval=c,pts={{0,i}},message="Neither the gambler nor the house was ruined."},
Do[AppendTo[pts,{g,playerval}];If[Random[]<p,playerval++;houseval--,playerval--;houseval++];
If[playerval==c+i  ,message=Row[{"The house was ruined after ",Length[pts]," bets."}];Break[]];
If[playerval==0  ,message=Row[{"The gambler was ruined after ",Length[pts]," bets."}];Break[]],{g,games}];
ListPlot[pts,AxesOrigin->{0,0},AxesLabel->{"number of bets","current stake of the gambler"},PlotLabel->Style[Framed[message],18,RGBColor[.49,0,0]],Joined->True,PlotStyle->RGBColor[.49,0,0],
LabelStyle->{15,Bold},
ImageSize->{600,300},ImagePadding->{{35,115},{20,30}}]];

Manipulate[Column[{Grid[{{Text@Style[Row[{"Probability of gambler's success: ",Chop@N[success[pp,ii,cc]]}],16,Bold]},{Text@Style[Row[{"Expected number of plays until ruin or success: ",NumberForm[expectedPlaysToRuin[pp,ii,cc],8]}],16,Bold]}},Frame->All,ItemSize->43],
gambleToRuinSimulation[pp,ii,cc,gg]}],
{{gg,500,"number of games in simulation"},{50,100,500,1000,5000}},
{{pp,0.50,"player's fixed win probability"},0.40,0.60,.001,Appearance->"Labeled",ControlPlacement->Top},
{{ii,50,"player's initial stake"},10,1000,5,Appearance->"Labeled"},
{{cc,100,"casino's initial stake"},50,10000,10,Appearance->"Labeled"},
SaveDefinitions->True,
TrackedSymbols:> {gg,pp,ii,cc}]

CAPTION

The gambler starts with an i unit stake and the casino or house starts with c units. They repeatedly play a game for which the gambler has a fixed probability p of winning and the winner gets 1 unit from the loser. Play continues until the gambler "succeeds" by acquiring i+c units or is "ruined" by dropping to 0 units. This Demonstration computes the probability that the gambler will succeed by breaking the bank. Subtracting this probability from 1 gives the gambler's ruin probability. The theoretical expected number of plays of the game until success or ruin is also computed and a simulation gives empirical results for the various parameter values. In the example shown in the thumbnail we use p=0.474, the player's probability of winning an "even money" bet in American roulette.

DETAILS

Snapshot 1: a fair game—in such cases the gambler's overall success probability is simply (i/(i+c)), the gambler's proportion of the total stake and the expected number of plays until ruin is i c

Snapshot 2: p=0.53, which is about what an expert card counter in blackjack might achieve; in the simulation, the gambler generates a nice profit, but would require a very long time to break the bank

Snapshot 3: results also apply to two individuals playing "head on"; here the "player" triumphs with the help of a larger bankroll, despite the fact that the odds slightly favor the opponent

Related results: Derivation of the relevant formulas for probability of success and for expected time for success or ruin involves a nice application of recurrence relations. It also provides an interesting example of an absorbing Markov chain. For a more elementary approach, see Chapter 6 of the reference below.

E. Packel, The Mathematics of Games and Gambling, 2nd ed., Washington: The Mathematical Association of America, 2006.

THIS NOTEBOOK IS THE SOURCE CODE FROM

"The Gambler's Ruin" from the Wolfram Demonstrations Project
 http://demonstrations.wolfram.com/TheGamblersRuin/

Contributed by: Ed Packel (Lake Forest College)

A full-function Wolfram Mathematica system (Version 6 or higher) is required to edit this notebook.
GET WOLFRAM MATHEMATICA »

© Wolfram Demonstrations Project & Contributors   |   Terms of Use   |   Make a new version of this Demonstration »