Statistics
Gambler's Ruin Probability: Fair (p = 0.5) & Biased Random Walk
Calculate the probability of reaching zero before a fixed upper target in an independent unit-step random walk, including fair odds, deterministic endpoints and numerically stable near-fair evaluation.
Specify the random walk, not a trading forecast
Start at integer capital A and stop at either0 or A+B. Each independent step adds one unit with fixed probability p or subtracts one with probability1−p. The model assumes equal-size gains and losses, constant probabilities and no time limit.
These assumptions do not describe arbitrary investments, casino products or variable-stake strategies. At p=0.48 the expected change per unit stake is2p−1=−0.04, not a2% expected loss. No historical or named-game attribution is needed for this hypothetical example.
Check boundaries and fair odds
A and B must be nonnegative whole units with a positive total. This exercise caps A+B at one billion units to keep inputs within a simple numeric working range. Require0<=p<=1.
A=0 means already ruined; B=0 means the upper target has already been reached. For positive A and B, p=0 gives certain ruin and p=1 gives certain success. At p=0.5, ruin is B/(A+B). Initial A=20,B=30 gives0.6 at fair odds.
=IF(COUNT(B2:B4)<>3,"Enter numeric A,B,p",IF(OR(B2<0,B3<0,B2<>INT(B2),B3<>INT(B3),B2+B3<=0,B2+B3>1000000000,B4<0,B4>1),"Require whole A,B>=0; 0<A+B<=1e9; p in [0,1]","OK"))Avoid overflowing powers and near-fair cancellation
The usual biased formula uses powers of r=(1−p)/p. Large capitals can overflow those powers; near p=0.5 it also subtracts nearly equal numbers. The helper cells use t=abs(ln(1−p)−ln(p)) and only nonpositive exponential arguments.
Define g(x)=(1−exp(−x))/x with g(0)=1. For x<0.0001 the helpers evaluate1−x/2+x²/6−x³/24+x⁴/120. The first omitted term has magnitude at most x^5/720 in this range.
Ruin is [B/(A+B)]×g(Bt)/g((A+B)t), multiplied by exp(−At) when p>0.5. This also reaches the fair limit without dividing0/0. E8 returns the unrounded result.
=IF(E2<>"OK",E2,IF(B2=0,1,IF(B3=0,0,IF(B4=0,1,IF(B4=1,0,B3/(B2+B3)*E6/E7*IF(B4>0.5,EXP(-B2*E3),1))))))Calculate success directly too
E9 evaluates the symmetric expression [A/(A+B)]×g(At)/g((A+B)t), multiplied by exp(−Bt) when p<0.5. Computing both probabilities directly preserves a small probability better than subtracting a value near one.
At A=20,B=30,p=0.48, ruin rounds to0.9263. At p=0.55 it rounds to0.0180. The two outputs sum to one within floating-point precision. Extremely small probabilities can still underflow to zero; these are numerical model results, not arbitrary-precision guarantees.
=IF(E2<>"OK",E2,IF(B2=0,0,IF(B3=0,1,IF(B4=0,0,IF(B4=1,1,B2/(B2+B3)*E11/E7*IF(B4<0.5,EXP(-B3*E3),1))))))Try fair, biased and boundary cases
Change p to0.5,0,1 and values just above or below0.5. Then try large A and B; the helpers avoid the positive exponential overflow of the naive formula.
Keeping the upper target finite is essential. This page does not calculate expected duration or the different problem of playing indefinitely with no upper stopping target.
Try the example
Use the original values or change them to test your understanding.