Screen Shot 2020-06-05 at 10.14.13 PM

Martingale II and Currency Trading

We can use computer coding to explore game strategies and also to help understand the underlying probability distribution functions.   Let’s start with a simple game where we toss a coin 4 times, stake 1 counter each toss and always call heads.  This would give us a binomial distribution with 4 trials and the probability of success fixed as 1/2.

Tossing a coin 4 time [simple strategy]

Screen Shot 2020-06-05 at 9.27.47 PM

For example the only way of losing 4 counters is a 4 coin streak of T,T,T,T.  The probability of this happening is 1/16.  We can see from this distribution that the most likely outcome is 0 (i.e no profit and no loss).  If we work out the expected value, E(X) by multiplying profit/loss by frequencies and summing the result we get E(X) = 0.  Therefore this is a fair game (we expect to neither make a profit nor a loss).

Tossing a coin 4 time [Martingale strategy]

Screen Shot 2020-06-05 at 9.34.19 PM

This is a more complicated strategy which goes as follows:

1) You stake 1 counter on heads.
b) if you lose you stake 2 counters on heads
c) if you lose you stake 4 counters on heads
d) if you lose you stake 8 counters on heads.

If you win, the your next stake is always to go back to staking 1 counter.

For example for the sequence: H,H,T,T 

First you bet 1 counter on heads.  You win 1 counter
Next you bet 1 counter on heads.  You win 1 counter
Next you bet 1 counters on heads.  You lose 1 counter
Next you bet 2 counters on heads.  You lose 2 counters

[overall loss is 1 counter]

For example for the sequence: T,T,T,H 

First you bet 1 counter on heads.  You lose 1 counter
Next you bet 2 counter on heads.  You lose 2 counters
Next you bet 4 counters on heads.  You lose 4 counter
Next you bet 8 counters on heads.  You win 8 counters

[overall profit is 1 counter]

This leads to the following probabilities:

Once again we will have E(X) = 0, but a very different distribution to the simple 4 coin toss.  We can see we have an 11/16 chance of making a profit after 4 coins – but the small chance of catastrophic loss (15 counters) means that the overall expectation is still zero.

Iterated Martingale:

Here we can do a computer simulation.  This is the scenario this time:

Screen Shot 2020-06-05 at 10.01.23 PM

We start with 100 counters, we toss a coin for a maximum of 3 times. We then define a completed round as when we get to a shaded box.  We then repeat this process through 999 rounds, and model what happens. Here I used a Python program to simulate a player using this strategy.

Screen Shot 2020-06-05 at 10.06.15 PM

We can see that we have periods of linear growth followed by steep falls – which is a very familiar pattern across many investment types.  We can see that the initial starting 100 counters was built up to around 120 at the peak, but was closer to just 40 when we finished the simulation.

Let’s do another simulation to see what happens this time:

Screen Shot 2020-06-05 at 10.14.13 PM

Here we can see that the 2nd player was actually performing significantly worse after around 600 rounds, but this time ended up with a finishing total of around 130 counters.

Changing the multiplier

We can also see what happens when rather than doubling stakes on losses we follow some other multiple.  For example we might choose to multiply our stake by 5.  This leads to much greater volatility as we can see below:

Multiplier x5

Screen Shot 2020-06-06 at 6.18.05 AM

Here we have 2 very different outcomes for 2 players using the same model.  Player 1 (in blue) may believe they have found a sure-fire method of making huge profits, but player 2 (green) went bankrupt after around 600 rounds.

Multiplier x1.11

Screen Shot 2020-06-06 at 6.28.07 AM

Here we can see that if the multiplier is close to 1 we have much less volatility (as you would expect because your maximum losses per round are much smaller).

Screen Shot 2020-06-06 at 5.20.07 PM

We can run the simulation across 5000 rounds – and here we can see that we have big winning and losing streaks, but that over the long run the account value oscillates around the starting value of 100 counters.

Forex charts

We can see similar graphs when we look at forex (currency exchange) charts.  For example:

Screen Shot 2020-06-06 at 6.42.53 AM

In this graph (from here) we plot the exchange between US dollar and Thai Baht.  We can see the same sort of graph movements – with run of gains and losses leading to a similar jagged shape.  This is not surprising as forex trades can also be thought of in terms of 2 binary outcomes like tossing a coin, and indeed huge amounts of forex trading is done through computer programs, some of which do use the Martingale system as a basis.

The effect of commission on the model

Screen Shot 2020-06-06 at 7.16.35 PM

So, to finish off we can modify our system slightly so that we try to replicate forex trading.  We will follow the same model as before, but this time we have to pay a very small commission for every trade we make.  This now gives us:

E(X) = -0.000175. (0.0001 counters commission per trade)

E(X) = -0.00035. (0.0002 counters commission per trade)

Even though E(X) is very slightly negative, it means that in the long run we would expect to lose money.    With the 0.0002 counters commission we would expect to lose around 20 counters over 50,000 rounds.  The simulation graph above was run with 0.0002 counters commission –  and in this case it led to bankruptcy before 3000 rounds.

Computer code

Screen Shot 2020-06-06 at 6.53.33 AM

The Python code above can be used to generate data which can then be copied into Desmos.  The above code simulates 1 player playing 999 rounds, starting with 100 counters, with a multiplier of 5.   If you know a little bit about coding you can try and play with this yourselves!

Screen Shot 2020-09-12 at 1.36.32 PM

I’ve also just added a version of this code onto repl.  You can run this code – and also generate the graph direct (click on the graph png after running).  It creates some beautiful images like that shown above.

Essential resources for IB students:

1) Revision Village

Screen Shot 2021-05-19 at 9.55.51 AM

Revision Village has been put together to help IB students with topic revision both for during the course and for the end of Year 12 school exams and Year 13 final exams.  I would strongly recommend students use this as a resource during the course (not just for final revision in Y13!) There are specific resources for HL and SL students for both Analysis and Applications.

Screen Shot 2018-03-19 at 4.42.05 PM.png

There is a comprehensive Questionbank takes you to a breakdown of each main subject area (e.g. Algebra, Calculus etc) and then provides a large bank of graded questions.  What I like about this is that you are given a difficulty rating, as well as a mark scheme and also a worked video tutorial.  Really useful!

Screen Shot 2021-05-19 at 10.05.18 AM

The Practice Exams section takes you to a large number of ready made quizzes, exams and predicted papers.   These all have worked solutions and allow you to focus on specific topics or start general revision.  This also has some excellent challenging questions for those students aiming for 6s and 7s.

Each course also has a dedicated video tutorial section which provides 5-15 minute tutorial videos on every single syllabus part – handily sorted into topic categories.

2) Exploration Guides and Paper 3 Resources

Screen Shot 2021-05-19 at 6.32.13 PM

I’ve put together four comprehensive pdf guides to help students prepare for their exploration coursework and Paper 3 investigations. The exploration guides talk through the marking criteria, common student mistakes, excellent ideas for explorations, technology advice, modeling methods and a variety of statistical techniques with detailed explanations. I’ve also made 17 full investigation questions which are also excellent starting points for explorations.  The Exploration Guides can be downloaded here and the Paper 3 Questions can be downloaded here.