A study on the applicability of martingale using simulations of the coin game

 

The task is to analyse the applicability, usefulness (or to understand its absence) of the martingale method - it is understood as differently increasing bets in cases of defeat, and returning to the initial one in case of winning.

With the help of simulations of the game can clearly, from a practical point of view, find out the mathematical expectation, ie profit (and other properties) without any complicated formulas, etc.

Also, it makes you wonder that in gambling games gambling establishments allow you to increase your bet a certain number of times. The question is, why? So it works somehow, and you can use it to gain an advantage?

The aim is to make sense of it all. I feel most comfortable writing in Java, I will lay out the code, but it is not complicated, and it should not be too hard to understand. Also, of course, I will post a description of the simulation, and the results.

public class CheckupCoinGame {
        private static final Random RANDOM = new Random();
        private static final int REPETITION = 10;
        private static final int ITERATIONS = 10_000_000;
        private Map<Integer, Integer> series;
        private Map<Integer, Float> bets;
        private float initialBet;
        private static final float MARTIN_KOEFF = 2.0 f;
        private float profit;
        private float currentBet;
        private static final float COMMISSION = 0.0 f;
        private int losingInRow;
        
        public CheckupCoinGame(float initialBet) {
                this.initialBet = initialBet;
                series = new HashMap<>();
                bets = new HashMap<>();
                init();
        }
        public void init() {
                series.clear();
                bets.clear();
                profit = 0.0 f;
                losingInRow = 0;
                currentBet = initialBet;
        }
        public void printSeries() {
                System.out.println("profit: "+profit);
                System.out.println(series.toString());
                System.out.println(bets.toString());
                System.out.println();
        }
        public void play() {
                profit -= currentBet;
                if(RANDOM.nextBoolean()) {
                        float prize = currentBet*2.0 f;
                        float commission = prize*COMMISSION;
                        
                        if(series.get(losingInRow)==null) series.put(losingInRow, 1);
                        else series.put(losingInRow, series.get(losingInRow)+1);
                        
                        currentBet = initialBet;
                        losingInRow = 0;
                        profit += prize-commission;
                }
                else {
                        currentBet = currentBet * MARTIN_KOEFF;
                        losingInRow++;
                        if(bets.get(losingInRow)==null) bets.put(losingInRow, currentBet);
                }
        }
        
        public static void main(String[] args) {
                CheckupCoinGame coinGame = new CheckupCoinGame(1.0 f);
                
                for(int i=0; i<REPETITION; i++) {
                        coinGame.init();
                        for(int j=0; j<ITERATIONS; j++) {
                                coinGame.play();
                        }
                        coinGame.printSeries();
                }
        }
        
}

Explanation - for a clearer estimation of variance/mat expectation we use separately the number of iterations per number of repetitions, with the results of each repetition displayed separately.

 

To start, classic, increase by 2 (constant MARTIN_KOEFF), 10 approaches of 10 million times, start with $1, no commissions.

Results:

profit: 4999409.0

{0=2497719, 1=1252139, 2=624519, 3=312714, 4=156440, 5=77924, 6=38942, 7=19544, 8=9567, 9=4929, 10=2482, 11=1292, 12=597, 13=321, 14=151, 15=60, 16=43, 17=16, 18=3, 19=3, 20=3, 21=1}

{1=2.0, 2=4.0, 3=8.0, 4=16.0, 5=32.0, 6=64.0, 7=128.0, 8=256.0, 9=512.0, 10=1024.0, 11=2048.0, 12=4096.0, 13=8192.0, 14=16384.0, 15=32768.0, 16=65536.0, 17=131072.0, 18=262144.0, 19=524288.0, 20=1048576.0, 21=2097152.0}



profit: 4997075.0

{0=2496961, 1=1249799, 2=624290, 3=312746, 4=156362, 5=78465, 6=39278, 7=19735, 8=9794, 9=4837, 10=2430, 11=1194, 12=613, 13=283, 14=130, 15=79, 16=37, 17=20, 18=5, 19=7, 20=6, 22=4}

{1=2.0, 2=4.0, 3=8.0, 4=16.0, 5=32.0, 6=64.0, 7=128.0, 8=256.0, 9=512.0, 10=1024.0, 11=2048.0, 12=4096.0, 13=8192.0, 14=16384.0, 15=32768.0, 16=65536.0, 17=131072.0, 18=262144.0, 19=524288.0, 20=1048576.0, 21=2097152.0, 22=4194304.0}



profit: 5002676.0

{0=2502897, 1=1250625, 2=625055, 3=311884, 4=156157, 5=78165, 6=38854, 7=19620, 8=9662, 9=4882, 10=2377, 11=1247, 12=603, 13=329, 14=163, 15=76, 16=39, 17=19, 18=10, 19=8, 20=2, 22=1, 23=1}

{1=2.0, 2=4.0, 3=8.0, 4=16.0, 5=32.0, 6=64.0, 7=128.0, 8=256.0, 9=512.0, 10=1024.0, 11=2048.0, 12=4096.0, 13=8192.0, 14=16384.0, 15=32768.0, 16=65536.0, 17=131072.0, 18=262144.0, 19=524288.0, 20=1048576.0, 21=2097152.0, 22=4194304.0, 23=8388608.0}



profit: 4998547.0

{0=2498479, 1=1249915, 2=625338, 3=311953, 4=156321, 5=78343, 6=38774, 7=19557, 8=9885, 9=5109, 10=2480, 11=1252, 12=590, 13=268, 14=152, 15=68, 16=37, 17=15, 18=8, 19=3, 20=1, 21=1, 22=1}

{1=2.0, 2=4.0, 3=8.0, 4=16.0, 5=32.0, 6=64.0, 7=128.0, 8=256.0, 9=512.0, 10=1024.0, 11=2048.0, 12=4096.0, 13=8192.0, 14=16384.0, 15=32768.0, 16=65536.0, 17=131072.0, 18=262144.0, 19=524288.0, 20=1048576.0, 21=2097152.0, 22=4194304.0}



profit: 5002649.0

{0=2503490, 1=1249853, 2=625523, 3=311324, 4=156306, 5=77963, 6=39152, 7=19575, 8=9674, 9=4840, 10=2433, 11=1259, 12=618, 13=311, 14=164, 15=78, 16=46, 17=19, 18=13, 19=5, 20=3}

{1=2.0, 2=4.0, 3=8.0, 4=16.0, 5=32.0, 6=64.0, 7=128.0, 8=256.0, 9=512.0, 10=1024.0, 11=2048.0, 12=4096.0, 13=8192.0, 14=16384.0, 15=32768.0, 16=65536.0, 17=131072.0, 18=262144.0, 19=524288.0, 20=1048576.0}



profit: 4998962.0

{0=2499594, 1=1249230, 2=624651, 3=312343, 4=156629, 5=78249, 6=39344, 7=19297, 8=9833, 9=4911, 10=2401, 11=1251, 12=615, 13=321, 14=139, 15=82, 16=39, 17=16, 18=10, 19=6, 20=1}

{1=2.0, 2=4.0, 3=8.0, 4=16.0, 5=32.0, 6=64.0, 7=128.0, 8=256.0, 9=512.0, 10=1024.0, 11=2048.0, 12=4096.0, 13=8192.0, 14=16384.0, 15=32768.0, 16=65536.0, 17=131072.0, 18=262144.0, 19=524288.0, 20=1048576.0}



profit: 4997062.0

{0=2495979, 1=1250440, 2=625280, 3=313136, 4=155618, 5=78028, 6=39168, 7=19844, 8=9854, 9=4902, 10=2389, 11=1182, 12=630, 13=309, 14=153, 15=72, 16=35, 17=21, 18=10, 19=5, 20=4, 21=1, 22=3}

{1=2.0, 2=4.0, 3=8.0, 4=16.0, 5=32.0, 6=64.0, 7=128.0, 8=256.0, 9=512.0, 10=1024.0, 11=2048.0, 12=4096.0, 13=8192.0, 14=16384.0, 15=32768.0, 16=65536.0, 17=131072.0, 18=262144.0, 19=524288.0, 20=1048576.0, 21=2097152.0, 22=4194304.0}



profit: 5000395.0

{0=2501438, 1=1248339, 2=625719, 3=312474, 4=155812, 5=78371, 6=39136, 7=19610, 8=9827, 9=4801, 10=2470, 11=1191, 12=621, 13=315, 14=141, 15=66, 16=32, 17=17, 18=8, 19=5, 20=2}

{1=2.0, 2=4.0, 3=8.0, 4=16.0, 5=32.0, 6=64.0, 7=128.0, 8=256.0, 9=512.0, 10=1024.0, 11=2048.0, 12=4096.0, 13=8192.0, 14=16384.0, 15=32768.0, 16=65536.0, 17=131072.0, 18=262144.0, 19=524288.0, 20=1048576.0}



profit: 4998447.0

{0=2497878, 1=1249173, 2=625992, 3=312876, 4=156572, 5=78194, 6=38913, 7=19401, 8=9608, 9=4951, 10=2433, 11=1241, 12=601, 13=303, 14=152, 15=78, 16=36, 17=26, 18=13, 19=3, 20=2, 23=1}

{1=2.0, 2=4.0, 3=8.0, 4=16.0, 5=32.0, 6=64.0, 7=128.0, 8=256.0, 9=512.0, 10=1024.0, 11=2048.0, 12=4096.0, 13=8192.0, 14=16384.0, 15=32768.0, 16=65536.0, 17=131072.0, 18=262144.0, 19=524288.0, 20=1048576.0, 21=2097152.0, 22=4194304.0, 23=8388608.0}



profit: 5000776.0

{0=2500120, 1=1250168, 2=625457, 3=312776, 4=156621, 5=78111, 6=38744, 7=19331, 8=9685, 9=4911, 10=2420, 11=1204, 12=657, 13=282, 14=141, 15=83, 16=28, 17=22, 18=9, 19=3, 20=2, 21=1}

{1=2.0, 2=4.0, 3=8.0, 4=16.0, 5=32.0, 6=64.0, 7=128.0, 8=256.0, 9=512.0, 10=1024.0, 11=2048.0, 12=4096.0, 13=8192.0, 14=16384.0, 15=32768.0, 16=65536.0, 17=131072.0, 18=262144.0, 19=524288.0, 20=1048576.0, 21=2097152.0}

Explanation - the first line is a profit, how many times was the number of increases, below the size of the rate for this increase

From the results we can see, that in this case we have a clear plus mathematical expectation. It remains only to estimate the variance, it is clear to earn one dollar you have to bet more than 8 million 300 thousand dollars!!! Plus, for ten million simulations the losing streak easily comes to 23! If you test more, the series will be even longer.

To be continued....

 
Stanislav Aksenov:

To start, classic, increase by 2 (constant MARTIN_KOEFF), 10 approaches of 10 million times, start with $1, no commissions.

Results:

Explanation - the first line is a profit, how many times was the number of increases, below the size of the rate for this increase

From the results we can see, that in this case we have a clear plus mathematical expectation. It remains only to estimate the variance, it is clear to earn one dollar you have to bet more than 8 million 300 thousand dollars!!! Plus, for ten million simulations the losing streak easily comes to 23! If you test more, the series will be even longer.

To be continued....

Martingale is bound to end badly. But to feel it, to realise it, such experiments are useful.

 

Actually, what is the mathematical expectation? What is it equal to? Obviously the profit is 5 million per 10 million simulations. So for one bet of one dollar we earn 5million/10million=0.5 dollars. But what conclusions can we draw? Is it positive in the case of an infinite bankroll?

And how long a losing streak may last at all? To find out, let's simulate 4 approaches of 100 million. It is hard to imagine that one person can make so many bets in his life.

Further we will simulate a 0.1 dollar stake, because otherwise we will get uncomfortably large figures with an exponent.

profit: 2097151.9
{0=25002899, 1=12495987, 2=6251387, 3=3124908, 4=1562498, 5=780283, 6=390904, 7=195707, 8=97661, 9=48678, 10=24679, 11=12335, 12=6064, 13=3107, 14=1547, 15=721, 16=366, 17=169, 18=96, 19=47, 20=24, 21=10, 22=2, 23=2, 25=1}
{1=0.2, 2=0.4, 3=0.8, 4=1.6, 5=3.2, 6=6.4, 7=12.8, 8=25.6, 9=51.2, 10=102.4, 11=204.8, 12=409.6, 13=819.2, 14=1638.4, 15=3276.8, 16=6553.6, 17=13107.2, 18=26214.4, 19=52428.8, 20=104857.6, 21=209715.2, 22=419430.4, 23=838860.8, 24=1677721.6, 25=3355443.2}
profit: 2097151.9
{0=24999620, 1=12499424, 2=6248760, 3=3126441, 4=1562514, 5=781553, 6=390278, 7=195487, 8=97888, 9=48528, 10=24541, 11=12169, 12=6114, 13=3116, 14=1423, 15=705, 16=381, 17=191, 18=104, 19=59, 20=13, 21=10, 22=5, 23=4}
{1=0.2, 2=0.4, 3=0.8, 4=1.6, 5=3.2, 6=6.4, 7=12.8, 8=25.6, 9=51.2, 10=102.4, 11=204.8, 12=409.6, 13=819.2, 14=1638.4, 15=3276.8, 16=6553.6, 17=13107.2, 18=26214.4, 19=52428.8, 20=104857.6, 21=209715.2, 22=419430.4, 23=838860.8}
profit: 2097151.9
{0=25005180, 1=12500626, 2=6250523, 3=3123585, 4=1562576, 5=780612, 6=390732, 7=195639, 8=97763, 9=48409, 10=24007, 11=12349, 12=6205, 13=3143, 14=1564, 15=772, 16=372, 17=219, 18=92, 19=51, 20=24, 21=17, 22=3, 23=1, 24=2, 25=1, 26=1, 27=1, 32=1}
{1=0.2, 2=0.4, 3=0.8, 4=1.6, 5=3.2, 6=6.4, 7=12.8, 8=25.6, 9=51.2, 10=102.4, 11=204.8, 12=409.6, 13=819.2, 14=1638.4, 15=3276.8, 16=6553.6, 17=13107.2, 18=26214.4, 19=52428.8, 20=104857.6, 21=209715.2, 22=419430.4, 23=838860.8, 24=1677721.6, 25=3355443.2, 26=6710886.5, 27=1.3421773 E7, 28=2.6843546 E7, 29=5.3687092 E7, 30=1.07374184 E8, 31=2.14748368 E8, 32=4.29496736 E8}
profit: 2097049.6
{0=24997605, 1=12498426, 2=6243581, 3=3125971, 4=1564980, 5=781406, 6=391431, 7=195220, 8=97786, 9=48769, 10=24671, 11=12074, 12=6120, 13=3036, 14=1593, 15=792, 16=366, 17=189, 18=96, 19=41, 20=17, 21=10, 22=7, 23=4, 26=1}
{1=0.2, 2=0.4, 3=0.8, 4=1.6, 5=3.2, 6=6.4, 7=12.8, 8=25.6, 9=51.2, 10=102.4, 11=204.8, 12=409.6, 13=819.2, 14=1638.4, 15=3276.8, 16=6553.6, 17=13107.2, 18=26214.4, 19=52428.8, 20=104857.6, 21=209715.2, 22=419430.4, 23=838860.8, 24=1677721.6, 25=3355443.2, 26=6710886.5}

We find that we earn 2,097,150 for 100 million games. For each bet of $0.1 we earn 0.0209715. Which is strange, because we got a completely different mathematical expectation! That makes 20 cents on the dollar, hmm... It turns out that the size of the bet and the number of imitations affect the result. I don't get it!

At least we determined what series of failures is possible, I think we can safely expect that more than 32 times will not be.

 
Stanislav Aksenov:

Actually, what is the mathematical expectation? What is it equal to? Obviously the profit is 5 million per 10 million simulations. So for one bet of one dollar we earn 5million/10million=0.5 dollars. But what conclusions can we draw? Is it positive in the case of an infinite bankroll?

And how long a losing streak may last at all? To find out, let's simulate 4 approaches of 100 million. It is hard to imagine that one person can make so many bets in his life.

Further we will simulate a 0.1 dollar stake, because otherwise we will get uncomfortably large figures with an exponent.

We find that we earn 2,097,150 for 100 million games. For each bet of $0.1 we earn 0.0209715. Which is strange, because we got a completely different mathematical expectation! That makes 20 cents on the dollar, hmm... It turns out that the size of the bet and the number of imitations affect the result. I don't get it!

We've got a winning streak, I think we can count on no more than 32 times.


I don't remember how it ended with me that time, but if you interrupt the series 3-4-5 times (I forget where the norm is) you get quite good results

 
Stanislav Aksenov:

Actually, what is the mathematical expectation? What is it equal to? Obviously the profit is 5 million per 10 million simulations. So for one bet of one dollar we earn 5million/10million=0.5 dollars. But what conclusions can we draw? Is it positive in the case of an infinite bankroll?

And how long a losing streak may last at all? To find out, let's simulate 4 approaches of 100 million. It is hard to imagine that one person can make so many bets in his life.

Further we will simulate a 0.1 dollar stake, because otherwise we will get uncomfortably large figures with an exponent.

We find that we earn 2,097,150 for 100 million games. For each bet of $0.1 we earn 0.0209715. Which is strange, because we got a completely different mathematical expectation! That makes 20 cents on the dollar, hmm... It turns out that the size of the bet and the number of imitations affect the result. I don't get it!

At least we determined what succession of failures is possible, I think we can safely expect that more than 32 times will not be.


I don't understand the mathematics of TC either.

 
Stanislav Aksenov:

The task is to analyse the applicability, usefulness (or understand its absence) of the martingale method - by which we mean differently increasing bets in cases of defeat, and returning to the initial one in case of winning.

With the help of simulations of the game can clearly, from a practical point of view, find out the mathematical expectation, ie profit (and other properties) without any complicated formulas, etc.

Also, it makes you wonder that in gambling games gambling establishments allow you to increase your bet a certain number of times. The question is, why? So it works somehow, and you can use it to gain an advantage?

The aim is to make sense of it all. I feel most comfortable writing in Java, I will lay out the code, but it is not complicated, and it should not be too hard to understand. Also, of course, I will post a description of the simulation, and the results.

Explanation - for clearer estimation of dispersion/maturity we'll use iterations count per count of repetitions, with output of results of each repetition separately.


Add spread or commission and you're happy...

 

Thanks, worth a read of course, but my focus here is mainly on martingale, the game can be anything at all, it doesn't matter

Alexey Volchanskiy:

Also don't understand anything about the mathematics of the TS


Mat expectation in my mind is how much real money we make on each bet.


WARNING A bug in the code has been detected. Very strange, but if float is replaced with double it works correctly

Those 4 approaches of 100 million simulations

profit: 4999152.974493183
{0=24988724, 1=12502775, 2=6246814, 3=3127371, 4=1562420, 5=782105, 6=390497, 7=195020, 8=98007, 9=49153, 10=24187, 11=12328, 12=6111, 13=3006, 14=1481, 15=751, 16=384, 17=211, 18=94, 19=38, 20=27, 21=13, 22=7, 23=4, 24=1, 25=3}
{1=0.20000000298023224, 2=0.4000000059604645, 3=0.800000011920929, 4=1.600000023841858, 5=3.200000047683716, 6=6.400000095367432, 7=12.800000190734863, 8=25.600000381469727, 9=51.20000076293945, 10=102.4000015258789, 11=204.8000030517578, 12=409.6000061035156, 13=819.2000122070312, 14=1638.4000244140625, 15=3276.800048828125, 16=6553.60009765625, 17=13107.2001953125, 18=26214.400390625, 19=52428.80078125, 20=104857.6015625, 21=209715.203125, 22=419430.40625, 23=838860.8125, 24=1677721.625, 25=3355443.25}
profit: 5000240.774509393
{0=24998905, 1=12503432, 2=6250123, 3=3125373, 4=1563581, 5=780742, 6=390844, 7=194830, 8=97278, 9=48710, 10=24346, 11=12041, 12=6215, 13=2955, 14=1533, 15=786, 16=346, 17=190, 18=94, 19=45, 20=15, 21=15, 22=2, 23=3, 24=1, 25=1, 26=1}
{1=0.20000000298023224, 2=0.4000000059604645, 3=0.800000011920929, 4=1.600000023841858, 5=3.200000047683716, 6=6.400000095367432, 7=12.800000190734863, 8=25.600000381469727, 9=51.20000076293945, 10=102.4000015258789, 11=204.8000030517578, 12=409.6000061035156, 13=819.2000122070312, 14=1638.4000244140625, 15=3276.800048828125, 16=6553.60009765625, 17=13107.2001953125, 18=26214.400390625, 19=52428.80078125, 20=104857.6015625, 21=209715.203125, 22=419430.40625, 23=838860.8125, 24=1677721.625, 25=3355443.25, 26=6710886.5}
profit: 5000755.774517067
{0=25005148, 1=12506239, 2=6249727, 3=3122417, 4=1561735, 5=783244, 6=388461, 7=195067, 8=97401, 9=49402, 10=24283, 11=12270, 12=6053, 13=3044, 14=1481, 15=798, 16=383, 17=196, 18=100, 19=63, 20=23, 21=13, 22=8, 23=4, 24=2, 25=2}
{1=0.20000000298023224, 2=0.4000000059604645, 3=0.800000011920929, 4=1.600000023841858, 5=3.200000047683716, 6=6.400000095367432, 7=12.800000190734863, 8=25.600000381469727, 9=51.20000076293945, 10=102.4000015258789, 11=204.8000030517578, 12=409.6000061035156, 13=819.2000122070312, 14=1638.4000244140625, 15=3276.800048828125, 16=6553.60009765625, 17=13107.2001953125, 18=26214.400390625, 19=52428.80078125, 20=104857.6015625, 21=209715.203125, 22=419430.40625, 23=838860.8125, 24=1677721.625, 25=3355443.25}
profit: 5000612.874514937
{0=25006362, 1=12501058, 2=6250003, 3=3125038, 4=1562464, 5=780830, 6=389979, 7=194878, 8=97783, 9=48958, 10=24207, 11=12315, 12=6128, 13=3078, 14=1521, 15=762, 16=409, 17=168, 18=94, 19=35, 20=28, 21=16, 22=6, 23=6, 24=1, 26=1}
{1=0.20000000298023224, 2=0.4000000059604645, 3=0.800000011920929, 4=1.600000023841858, 5=3.200000047683716, 6=6.400000095367432, 7=12.800000190734863, 8=25.600000381469727, 9=51.20000076293945, 10=102.4000015258789, 11=204.8000030517578, 12=409.6000061035156, 13=819.2000122070312, 14=1638.4000244140625, 15=3276.800048828125, 16=6553.60009765625, 17=13107.2001953125, 18=26214.400390625, 19=52428.80078125, 20=104857.6015625, 21=209715.203125, 22=419430.40625, 23=838860.8125, 24=1677721.625, 25=3355443.25, 26=6710886.5}

Mat expectation of each bet (we have $0.1) is 5 million / 100 million = 0.05 cents. That is, for each bet we earn 5 cents. Now converges with the previous 50 cents for each $1 bet

 
Good experiment. Shows how bad martingale is. ) There's no way to get away with it. It is only a matter of time. According to probability theory a long series of losses is sure to occur. Doubling the lot increases the exponent of losses. The account will be killed rather quickly. ))) I use martingale on the real. )
 
Grigoriy Chaunin:
Good experiment. It shows what a punk martingale is. ) We will not fail with it. It is only a matter of time. According to probability theory a long series of losses is sure to occur. Doubling the lot increases the exponent of losses. The account will be killed rather quickly...

Congratulations, you have just lit the Grail.

Now everyone can "inevitably", "just a matter of time", "necessarily" and "quickly enough" raise the grandmas in the "volume of the martingale bullshit" (minus the spread) simply by opening to the opposite side of the coin signal and changing the MM to "inverse"