home *** CD-ROM | disk | FTP | other *** search
/ The Hacker's Encyclopedia 1998 / hackers_encyclopedia.iso / etc / scams / riskruin.txt < prev    next >
Encoding:
Text File  |  2003-06-11  |  18.6 KB  |  529 lines

  1.  
  2.                               Risk of Ruin
  3.                             Last Revised 1/15/92
  4.                           Copyright 1991, 1992 Michael Hall
  5.                           Permission to copy for own use
  6.  
  7. This is really seven articles in one:
  8.  
  9. I.   What is the risk of ruin for a given bankroll and given win goal?
  10. II.  How many units of bankroll for a given risk of ruin?
  11. III. How long will it take to go broke or win a goal amount?
  12. IV.  What is the chance of taking a loss after N hands?
  13. V.   George C. on the Ruin Formula
  14. VI.  Mason Malmuth on the Ruin Formula
  15. VII. How about some C code?
  16.  
  17. Although blackjack is frequently used as an example here, the
  18. results can be applied to other gambling games.
  19.  
  20. ==========================================================================
  21. I.   What is the risk of ruin for a given bankroll and given win goal?
  22.  
  23.  
  24. This can be estimated using the standard ruin formula,
  25. with the bankroll adjusted to reflect the standard deviation, as
  26. shown by Griffin in "Theory of Blackjack".  The average squared
  27. win is very nearly the variance (i.e. the standard deviation
  28. squared), more precisely it is the variance plus the square
  29. of the win per hand.  You can approximate the game of blackjack
  30. by betting the square root of the average squared wager 
  31. on a biased coin with P(heads) = 0.5 + wph/2sqrt(asw), where asw is
  32. the average squared wager and wph is the expected win.  So,
  33. here P(heads)= 0.5+.0151/(2sqrt(3.887)) = 0.5038.  The ruin formula is:
  34.  
  35. R = (1 - S^b)/(1 - S^(a+b))
  36.  
  37. where  R    is the probability of ruin from 0 (none) to 1 (always)
  38.        a    is a'/sqrt(asw), the coin toss bankroll
  39.        b    is b'/sqrt(asw), the amount to be won in coin toss units
  40.        S    is P/(1-P), the ratio of a coin winning to losing
  41.        P    is 0.5 + wph/2asw, the bias of the coin
  42.        wph  is the win per hand
  43.        asw  is s^2 + wph^2, the average squared win
  44.  
  45. Suppose we wish to double a bankroll of 300 basic units. The bet size
  46. effectively reduces this to a=b=300/sqrt(3.887)=152.16 units.
  47. S=0.5038/(1-0.5038)= 1.0153.  So R=(1-1.0153^152.16)/(1-1.0153^(152.16*2))
  48. =9.0%.
  49.  
  50. And here's the same formula, fully expanded:
  51.  
  52.           /sqrt(s^2 + wph^2) + wph\(b'/sqrt(s^2 + wph^2))
  53.      1 - | ----------------------- |
  54.           \sqrt(s^2 + wph^2) - wph/
  55. R = -------------------------------
  56.           /sqrt(s^2 + wph^2) + wph\((a'+b')/sqrt(s^2 + wph^2))
  57.      1 - | ----------------------- |
  58.           \sqrt(s^2 + wph^2) - wph/
  59.  
  60. where  R    is the chance of ruin from 0 (none) to 1 (always)
  61.        s^2  is the variance (i.e. square of the standard deviation s)
  62.        wph  is the win per hand in units
  63.        a'   is the blackjack bank size in units
  64.        b'   is the number of blackjack units we want to win (usually = a')
  65.  
  66. If S = 1 (i.e. the game is even), then use this formula instead:
  67.  
  68. R = b / (a + b)
  69.  
  70. where  R    is the chance of ruin from 0 (none) to 1 (always)
  71.        a    is a'/sqrt(asw)
  72.        b    is b'/sqrt(asw)
  73.  
  74.  
  75. Here's some more examples, with the wph and s^2 as above. Here are
  76. the probabilities of ruin before doubling for breaking your bankroll
  77. into various numbers of units:
  78.  
  79.                          CHANCE RUIN BEFORE DOUBLE
  80.             ~1.5% advantage   ~1.0% advantage   ~0.5% advantage
  81. BANKROLL      wph=0.2265        wph=0.151        wph=0.0755
  82. --------    ---------------   --------------    ---------------
  83.  100            23.8                31.5              40.4
  84.  200             8.9                17.5              31.5
  85.  300             2.9                 8.9              23.8
  86.  400             0.9                 4.3              17.5
  87.  500             0.2                 2.0              12.5
  88.  600             0.09                0.9               8.9
  89.  700             0.03                0.4               6.2
  90.  800             0.009               0.1               4.3
  91.  900             0.003               0.09              2.9
  92. 1000             0.0009              0.04              2.0
  93.  
  94. Note: above probabilities do not apply to Frank "Almost Never Lose 40
  95. Units" Irwin ;-)  They also do not apply to Kelly Criterion bettors,
  96. but Kelly Criterion (betting proportional to current bankroll and
  97. advantage) is not practical to apply exactly in practice.
  98.  
  99.  
  100. ==========================================================================
  101. II.  How many units of bankroll for a given risk of ruin?
  102.  
  103. A special case of the ruin formula given before is the following
  104. for when we wish to *double* the bankroll:
  105.  
  106.        1
  107. R = -------
  108.     1 + S^n
  109.  
  110.     where R is the risk of ruin
  111.           S is the ratio of winning to losing
  112.           n is the units of coin toss bankroll
  113.  
  114. We can solve this in terms of n, to answer the above question, and we get:
  115.  
  116.     log((1/R) - 1)
  117. n = --------------
  118.        log(S)
  119.  
  120.  
  121. Expanding this out to head off possible confusion:
  122.  
  123.          log((1/R) - 1)
  124. a'= ----------------------------(sqrt(s^2 + wph^2))
  125.         /sqrt(s^2 + wph^2) + wph\
  126.     log| ---------------------- |
  127.         \sqrt(s^2 + wph^2) - wph/
  128.  
  129. where R is the risk of ruin
  130.       wph is the win per hand
  131.       s^2 is the variance of wph
  132.       a' is the necessary units of blackjack bankroll
  133.  
  134. For example, plugging in R=.09, S^2=3.88681, wph=.0151, then
  135. a'~= 300.  In other words, if you are willing to risk a 9%
  136. risk of ruin and use a 1-4 spread under conditions similar to
  137. my computer simulation, then you should use 300 units of bankroll.
  138.  
  139. I don't believe there is any published blackjack book that accurately
  140. explains the bankroll requirements of blackjack.  In fact, most of them
  141. are just plain wrong when it comes to this.  This is confirmed by
  142. the full double-or-nothing simulations of myself and also independently
  143. on a different simulator by a rec.gambler who is no longer with us.  For
  144. example, a 400 unit bankroll with the above single deck situation has
  145. (only) about a 80% chance of doubling before ruin, according to the
  146. simulations, which is about what we'd expect from using the ruin formula.
  147.  
  148. ==========================================================================
  149. III. How long will it take to go broke or win a goal amount?
  150.  
  151. From Epstein's _Theory of Gambling and Statistical Logic_, page 66:
  152. the expected number of plays before ruin or win limit of a gambler is:
  153.  
  154.               z         a[1-(q/p)^z]
  155.   E(n) = ---------- - ---------------------                 for p<>q
  156.          (q-p)(1-r)   (q-p)(1-r)[1-(q/p)^a]
  157.  
  158.   where E(n) is the expected number of plays before ruin or win limit
  159.         n is the number of plays
  160.         z is the initial capital
  161.         a is the desired final capital (a > z, z-a is the desired win)
  162.         p is the probability of a win
  163.         q is the probability of a loss
  164.         r is the probability of a tie
  165.  
  166. Peter Griffin claims we can approximate blackjack by choosing
  167. p=0.5 + wph/2sqrt(asw), where asw is the average squared wager and wph
  168. is the expected win, with q=1-p and r=0.  With the numbers wph=.0086 and
  169. asw=7.63 (for an 8 deck shoe, AC rules, abandoning counts of -1 or worse)
  170. then p=.5015567. Suppose z=100, and a=200, and so E(n)=9689.  Thus, it
  171. would take 9689 hands on average, around 97 hours, to double or nothing
  172. 100 units on this shoe game.
  173.  
  174. There are other formulas that are sometimes useful.
  175.  
  176. For an even game use:
  177.  
  178.          z(a-z)
  179.   E(n) = ------     for p = q
  180.           1 - r
  181.  
  182. For an infinite win limit "a", use:
  183.  
  184.              z
  185.   E(n) = ----------     for p < q
  186.          (q-p)(1-r)
  187.   
  188.   E(n) = undefined      for p > q
  189.  
  190.   E(n) = infinity       for p = q
  191.  
  192. For intelligent card counters, p > q, and so it doesn't make much
  193. sense to talk about the average time to ruin or winning an infinite
  194. amount.  Although sometimes a card counter will go broke with a
  195. fixed unit size, sometimes a card counter *will* win an infinite
  196. amount if left to play forever.  p < q represents the case of
  197. most gamblers, such as craps players, who are doomed to lose if
  198. they play long enough and so it's only a matter of how long it will
  199. take.
  200.  
  201. ==========================================================================
  202. IV.  What is the chance of taking a loss after N hands?
  203.  
  204. Assuming the risk of ruin is low and the number of hands is
  205. more than 100 or so, the Central Limit Theorem makes the
  206. distribution normal.  The mean and standard deviation of this
  207. normal distribution can be computed from the expected win per
  208. hand and the standard deviation per hand.  z = (x-u)/s*sqrt(N),
  209. where z is the standardized normal variable, x is the point
  210. of interest (zero, if we want to know the chance of taking a
  211. loss), u is the expected win, s is the standard deviation,
  212. and N is the number of hands.
  213.  
  214. Let's say N=40, then z=(-50-(40*.0151))/(sqrt(3.887*40))=-4.0583.  Don't
  215. have my tables handy, but I'm sure that's pretty much off the scale, close
  216. to 0%. That seems reasonable, since it is pretty hard to lose 50 units
  217. in just 40 hands, even if you are spreading 1-4.  I would, however,
  218. expect the "actual" figure to be a bit higher (due to the 4 unit bets
  219. having an extra large influence in the space of only 40 hands.)
  220.  
  221.  
  222. ==========================================================================
  223. V.   George C. on the Ruin Formula
  224.  
  225. From "The Ruin Formula", by George C., Blackjack Forum, September 1988...
  226.  
  227.  
  228. George shows how to compute variance, like so:
  229.  
  230. 6 Decks Strip Rules w/DDAS, 75% Penetration
  231.  
  232. Advantage  Hands/Hour   Bet Squared $  Product $
  233. ---------  ----------   -------------  ---------
  234.   -3.4%       1.0               10000      10000
  235.   -2.9%       2.0               10000      20000
  236.   -2.4%       3.0               10000      30000
  237.   -1.9%       4.0               10000      40000
  238.   -1.4%       8.0               10000      80000
  239.   -0.9%      13.0               10000     130000
  240.   -0.4%      35.5               10000     355000
  241.    0.1%      13.0               40000     520000
  242.    0.6%       8.0              250000    2000000
  243.    1.1%       4.0              562500    2250000
  244.    1.6%       3.0             2250000    6750000
  245.    2.1%       2.0             2250000    4500000
  246.    2.6%       2.0             2250000    4500000
  247.    3.1%       1.0             2250000    2250000
  248.    3.6%       0.5             2250000    1125000
  249.  
  250.   Sum of Products      24560000
  251.   Sq Root of Products      4956
  252.   Times 1.1                5451 = Hourly standard deviation in $
  253.  
  254.   Note: When bet size goes to $1000, it is assumed player will
  255.   play two hands of $500 each, then 2 hands of $1000 each
  256.   [treated above as a bet of .75*2*bet].
  257.  
  258. The above is a reasonable method of computing variance from
  259. frequency distributions.  George C. does his statistics
  260. in "hourly" units, i.e. 100 hands.  Using the above chart, you
  261. can obviously come up with things like the hourly win rate too.
  262.  
  263. Then George comes up with this version of the Ruin Formula:
  264.  
  265.              h
  266.     /1 + w/v\
  267.    | ------- |  -  1
  268.     \1 - w/v/
  269. R = --------------------
  270.              s+h
  271.     /1 + w/v\
  272.    | ------- |  -  1
  273.     \1 - w/v/
  274.  
  275. where R is the probability of ruin
  276.       w is the hourly expected win (in units)
  277.       v is the hourly variance
  278.       h is the hours of play
  279.       s is the stake (or size of bank)
  280.   
  281. He wants to figure out what his chance of halving his bank of
  282. $150,000 before doubling it is...
  283.  
  284. George C.:
  285.  "Since I should average $392/hour, it will take me 383
  286.   hours to double my bank of $150,000 (i.e., divide the bank size,
  287.   $150k, by the hourly expectation, $392, to get 383 hours.) I want
  288.   to know what my chances are of halving my bank so I divide
  289.   $75,000 (half of my bank) by $500 to obtain how many units of
  290.   bank I have.  That equals 150 units."  [George calls $500
  291.   his unit size, even though he goes down to $100 bets in bad
  292.   counts, but that's okay, so long as we know what he means.]
  293.  
  294. George substitutes the values w=.783,v=119,h=383,s=150 to
  295. get .14, or a 14% chance of halving his bank of 300 $500 units
  296. before doubling it. Nrrrrr.... but thanks for playing George C.,
  297. and we have some nice consolation gifts for you as well as
  298. Chambliss and Rogenski.  You just can't use whatever units
  299. you feel like in the ruin formula.
  300.  
  301. My computations show a 11.2% chance of losing *half* the bankroll
  302. before doubling the whole bankroll.
  303.  
  304. Note: general_ruin(1500.0, 1500.0, 27.016, .0392) = .013, and
  305.       general_ruin( 750.0, 1500.0, 27.016, .0392) = .112,
  306.       using the C code in another part of this article with
  307.       $100 units. 27.016 is the variance in $100 units per hand (squared).
  308.  
  309. George C.:
  310.  "The answer you should get is .14 or about a 1 in 7
  311.   chance of losing half of your bank.  Most high stake pros
  312.   that I know play double the bet size I recommend here,
  313.   considering the size of my bankroll..."
  314.  
  315. I'm a bit puzzled by the "s+h" term in George's formula, and
  316. I tend to think it's totally bogus. s is the initial bankroll,
  317. while h is the hours. Whoh, ERROR type conflict.
  318.  
  319. We can see the problem in George's approach by switching to
  320. a different unit size for the time, which shouldn't change the
  321. risk of ruin. Let's say instead of hours (i.e. 100 hands),
  322. how about 100 hours (i.e. 10,000 hands)?  This divides
  323. the necessary units of time by 100, and multiples the variance
  324. and win by 100.  Georges formula then spits out 2.463%, whereas
  325. with hourly units the answer was 14%.  Clearly something wrong
  326. here.  Could be me, but I think it's George.
  327.  
  328. George's formula will work if you enter the data in terms of
  329. hands and bet units.  Instead of hours, for "h" use the number of
  330. units you wish to win.
  331.  
  332.  
  333. ==========================================================================
  334. VI.  Mason Malmuth on the Ruin Formula
  335.  
  336. From a letter to the editor, by Mason Malmuth, Blackjack Forum,
  337. December 1988...
  338.  
  339. Mason Malmuth:
  340.  "George C's article on `The Ruin Formula' (BJ VIII #3) was
  341.   very well done, [NOT!] but if you use the method give in my
  342.   book, `Gambling Theory and Other Topics', you can extend
  343.   these ideas even further and produce what I think are
  344.   even more interesting numbers.  Specifically, consider
  345.   the following equation:
  346.  
  347.   LL = (WR)(N)-(3)(SD)sqrt(N)
  348.   where LL is your lower limit,
  349.   WR is your win rate per hour,
  350.   N is the number of hours you play, and
  351.   SD is the standard deviation.
  352.  
  353.   For all practical purposes, this is the equation that gives
  354.   the lower limit (at three standard deviations) for how you
  355.   would do for some period of time.  That is, for practical
  356.   purposes, this equation is your worst possible result."
  357.  
  358. Okay, let's apply Mason's equation to George's problem, so
  359. WR=392, N=383, SD=5451, producing LL=-169898.00.  Actually,
  360. come to think of it this doesn't really give you much of
  361. an indication as to your risk of ruin during those 383
  362. hours - it is just the worst result you would expect after
  363. 383 hours IF YOU HAD AN INFINITE BANKROLL. 
  364.  
  365. But Mason Malmuth continues:
  366.  "Going one step further, if we take the above equation and
  367.   take the first derivative with respect to N, set it to zero,
  368.   and solve for N, we find the number of hours where our bankroll
  369.   can by minimized
  370.  
  371.   0 = WR - (3)(1/2)(SD)/(sqrt(N))
  372.  
  373.                   2
  374.        / (3)(SD) \
  375.   N = | --------  |
  376.        \ (2)(WR) /
  377.  
  378.   Now by substituting this value back into the original lower
  379.   limit equation, we produce practical bankroll requirements.
  380.   In George C's example WR=.783, and SD=10.9.  Thus N=436,
  381.  
  382.                       2
  383.          / (3)(10.9) \
  384.   436 = |  ---------  |
  385.          \ (2)(.783) /
  386.  
  387.   and the required bankroll is 341 units.
  388.  
  389.   -341 = (.783)(436)-(3)(10.9)sqrt(436)"
  390.  
  391. First, note that 341 units is 341 of George C's $500 units,
  392. which is really 1705 $100 units, or $170,500.  Using my version
  393. of the ruin formula, I calculate a 0.7% chance of ruin before
  394. doubling 1705 $100 units, under George C's conditions.
  395.  
  396. Mason's technique seems to work okay, but I'd trust the ruin
  397. formula more.  Part II of this article gave a means of
  398. determining bankroll size for a given risk of ruin.
  399.  
  400.  
  401. ==========================================================================
  402. VII. How about some C code?
  403.  
  404. And finally, here's some C code to do the ruin formula above...
  405.  
  406. Compile by doing something like:
  407.  
  408. cc -c ruin.c
  409. cc -o ruin ruin.o /usr/lib/libm.a
  410.  
  411. /*
  412.   Gambling ruin formulas. Version 1.1.
  413.  
  414.   Copyright 1991, Michael Hall
  415.   Permission to use pretty much however you want, but at your own
  416.   risk of ruin :-)
  417.   */
  418.  
  419. #include <math.h>
  420.  
  421. #define sqr(X) (X * X)
  422.  
  423. /*
  424.   Just a test.  Should print following (approximately):
  425.   0.088595
  426.   300.0
  427. */
  428. main()
  429. {
  430.   double general_ruin(), bankroll();
  431.  
  432.   printf("%f\n", general_ruin(300.0, 300.0, 3.886851, 0.0151));
  433.   printf("%f\n", bankroll(0.088595, 3.886851, 0.0151));
  434. }
  435.  
  436.  
  437. /*
  438.   Probability of ruin when trying to win "bb" units starting with "aa"
  439.   units of bankroll on a gambling game where the expected win (or
  440.   loss) per trial is "wph" and the variance is "s2".  Note that "aa" and
  441.   "bb" are doubles, just like the other parameters.
  442.   */
  443. double general_ruin (aa, bb, s2, wph)
  444.      double aa, bb, s2, wph;
  445. {
  446.   double coin_units, a, b, S, asw, compute_asw(), coin_bet_size(), big_S(),
  447.          coin_ruin();
  448.  
  449.   asw = compute_asw(s2, wph);
  450.   coin_units = coin_bet_size(asw);
  451.   a = aa / coin_units;
  452.   b = bb / coin_units;
  453.   S = big_S(s2, wph);
  454.   return(coin_ruin(a, b, S));
  455. }
  456.  
  457.  
  458. /*
  459.   Generates proper bankroll size for doubling given a desired risk of
  460.   ruin and the other information as above.
  461. */
  462. double bankroll (R, s2, wph)
  463.      double R, s2, wph;
  464. {
  465.   double S, coin_size, coin_bet_size(), coin_bankroll();
  466.   
  467.   S = big_S(s2, wph);
  468.   coin_size = coin_bet_size(s2, wph);
  469.   return(coin_bankroll(R, S) * coin_size);
  470. }
  471.  
  472. double coin_bankroll(R, S)
  473.      double R, S;
  474. {
  475.   double log();
  476.  
  477.   return(log((1.0 / R) - 1)/log(S));
  478. }
  479.  
  480. /*
  481.   asw is the average squared win, which is a simple function
  482.   of s2 and wph.
  483.   */
  484. double compute_asw(s2, wph)
  485.      double s2, wph;
  486. {
  487.   return(s2 + sqr(wph));
  488. }
  489.  
  490.  
  491. /*
  492.   Number of units to bet on a coin tossing game, to get
  493.   the same mean and variance as the more general game
  494.   with asw average squared wager.
  495.   */
  496. double coin_bet_size(asw)
  497.      double asw;
  498. {
  499.   double sqrt();
  500.  
  501.   return(sqrt(asw));
  502. }
  503.  
  504.  
  505. /*
  506.   The big S in the coin ruin formula.
  507. */
  508. double big_S(asw, wph)
  509.      double asw, wph;
  510. {
  511.   double sqrt();
  512.   return((sqrt(asw) + wph) / (sqrt(asw) - wph));
  513. }
  514.  
  515.  
  516. /*
  517.   Probability of ruin when trying to win "b" units starting with "a"
  518.   units of bankroll on a biased coin tossing game where "S" is the
  519.   ratio of the probability of winning to the probability of losing
  520.   (i.e. P/(1-P) where P is the probability of winning.
  521.   */
  522. double coin_ruin (a, b, S)
  523.      double a, b, S;
  524. {
  525.   double pow();
  526.  
  527.   return((1.0 - pow(S,b)) / (1.0 - pow(S,a + b)));
  528. }
  529.