Project: The martingale

Unlike the nightingale and the martin, the martingale is not a bird, but a betting system that some gamblers use when playing roulette. It's a simple idea: Whenever you lose, double your bet on the next round, so that when you win you recover everything you've lost and get a little more besides. Since you seldom lose more than two or three times in a row, and since you're bound to win eventually if you keep playing, the system seems to guarantee a profit. The simplicity and elegance of the idea have made this system the most widely used of all betting systems.

Despite its popularity, however, it is worthless. The flaw is that although it is true that a long sequence of losses is a rare event, it is also an extremely expensive one. At some point, you will find that you don't have enough money to double your bet again. Even before that, you will discover that the casino places an upper limit on the amount you can bet on any one turn of the wheel. When you reach this limit, you will not be allowed to double your bet any more. Consequently, when you finally win, you will not recover all of your losses; indeed, you'll probably lose everything you've won so far, and more.

The Scheme program that we'll be looking at today demonstrates this point by simulating the martingale's performance over a long period of time -- experience that it would take you weeks or years (and thousands of dollars) to acquire by direct observation at glittering European casinos. Presumably the savings in time and expense compensate somewhat for the less exhilarating atmosphere of the lab.


Step 1

The Scheme program containing the procedures that carry out this simulation can be found at /home/stone/courses/scheme/html/martingale-project.ss. Copy this file into your home directory by opening a dtterm window and giving the shell command

cp /home/stone/courses/scheme/html/martingale-project.ss ~/martingale-project.ss

Step 2

Start XEmacs and load the file ~/martingale-project.ss. It's a long file, but most of it consists of comments. The first page or so gives a summary description of the game of roulette, which you can skip if you've watched a James Bond movie or visited Las Vegas. Read through the next hundred lines or so. (There's a comment that begins with the distinctive mark ;;; ===== to tell you where you can stop reading on this first pass over the program.)


Step 3

Start Chez Scheme and load the program file into it, either (in dtterm) by adding the name of the file to the command line, or (under XEmacs) by invoking the load procedure. Give yourself a bankroll of, say, ten thousand dollars and try out the system for a few simulated hours (two hundred spins of the wheel, perhaps -- or choose whatever arguments you like). How much did you wind up with? Does the martingale seem like a promising and attractive system?

Now try it instead over a long season of play -- two hundred spins a day for a couple of months, about twelve thousand spins altogether. How long did it take before the casino had all your money?


Step 4

You may not like the betting limits that the simulated casino imposes on players (minimum bet, $20; maximum bet, $3000). Players of the martingale system often complain about the upper limit in particular. Raise the upper limit and try your bets again.

(In the real world, casinos very seldom agree to raise the maximum bet unless the minimum bet is raised proportionately, to keep a ratio of 150 : 1 or 100 : 1 between the two. They will get all of the system player's money anyway, but they will get it more quickly if he can double his bet only six or seven times before hitting the upper limit.)


Step 5

The ``great martingale'' is a variation of the martingale in which, after each loss, the player not only doubles her bet, but also adds the amount of the original bet to the result. The idea is to compensate for the delay and disappointment occasioned by the loss.

I've replaced part of the code for the great-martingale simulation with a call to a non-existent procedure, *-REPLACE-THIS-WITH-THE-CORRECT-EXPRESSION-*. Find the place in the code at which this identifier occurs and delete it; instead, put in the arithmetic expression that describes how to compute the size of the next bet after the player loses on one spin of the wheel. Test your code by invoking the great-martingale procedure with appropriate arguments.


Step 6

The last half of the program describes a third variation of the martingale, this one called the ``cancellation'' system. Although I've provided most of the code that implements a simulator for this system, I've left out the bodies of three procedure definitions -- the procedures descending-multiples-kernel, last, and all-but-last -- for you to supply.

Read through the description of the cancellation system, write the missing bodies of the three procedure definitions, and test the completed simulation.


created February 5, 1998
last revised February 9, 1998

John David Stone (stone@math.grin.edu)