Showing posts with label Monte Carlo methods. Show all posts
Showing posts with label Monte Carlo methods. Show all posts

The Perfect Bet

I have just finished reading The Perfect Bet by Adam Kucharski, a history of betting in the past, present and future. The book starts with the familiar early days of probability theory, driven by Blaise Pascal and Pierre de Fermat. The theory of probability owes much to the world of gambling. Next, the book shows how brute force methods have been used by syndicates to win lotteries and that not all scratchcards are equal.

After the Second World War Monte Carlo methods were developed as a way in which to model how neutrons would behave in a hydrogen bomb. Such methods were then used to simulate millions of games of blackjack in order to find the optimal winning strategy.

The financial world is now rife with "rocket scientists" using physics to crack open the markets. One such scientist is Doyne Farmer who intially applied his knowledge to creating an edge in the casino game of roulette. Farmer then went on to use his skills to set up a fund in the financial markets.

William Benter gets a mention for his modelling of Hong Kong horse racing and making millions of dollars from his betting. Dixon and Coles and their initial work on modelling soccer games is detailed.

For those interested in bot trading there is a lot to digest. Mostly financial trading and poker playing bots are covered but there is a lot to be read between the lines. Whilst doing so I have thought of a few new approaches that I will apply to my bots. There is a lot you can learn from financial algo-trading. Much of it has nothing to do with the underlying financial instrument being traded.

Although only 200 pages long the book is very interesting and I highly recommend it.

Amazon - The Perfect Bet

Recent Work

Programming for Betfair, a book I wrote to show traders how easy it is to write their own bot, continues to sell. All abilities have bought the book; from beginner programmers, to beginner algo-traders, to experienced traders who want to build something better than existing third-party software.

Beginner programmers have followed the instructions in the book without difficulty. Many beginners have vowed to learn how to program so that they can extend their bot to do exactly what they require from it.

Using Microsoft's Visual Studio makes learning how to program very easy. Beginner algo-traders find the book useful as I explain the nuts and bolts of building an algo-trading application. Experienced traders too are using the book to quickly get their ideas down in code.  Coding your own trading software means that you don't have to pay a monthly subscription fee to a vendor.

Algo-trading is all about finding your own niche and exploiting it before others do so. Above all, people are using the book to build applications that are tailored to their needs without having to give away their ideas to third-party developers. Discussing strategies with others will always result in your strategy failing as others will arbitrage away any edge there might have been.

Initially, there were a few teething problems with Betfair's API-NG, which have now been rectified both by Betfair on their servers and by myself in the book through an online addendum. Betfair received a copy of the book and now Betfair endorses Programming fro Betfair as an ideal way for people to learn how to code API-NG applications.

As promised I have been helping beginner coders solve any problems they have been having with understanding the book. There has only been one negative review of the book and that was by a person who had no real problem with the book's content. They just didn't understand the philosophy of not being tied to third-party software and the advatanges that gives you when searching for a trading edge.

Third-party software forces the user to trade in a particular way. With thousands of users of software such as that produced by BetAngel or AGT there are a lot of people trading in a similar fashion, which reduces their edge. When you code your own trading software anything is possible. You are limited only by your imagination.

I have made a start on my next book, which will introduce computational methods for strategy and money management optimisation. As with the first book, I am writing programs that I feel epitomise my trading philosphy and then I will base the book around the program code that I will give to the reader.

To guarantee that the programs I am writing are suited to the task, I am currently developing a new trading strategy for technical trading pre-race horse betting markets. Utilising evolutionary computation and Monte Carlo simulation I will build and demonstrate tools that every algo-trader should have with which to find an edge.

RiskSimulator 2


I am currently working on an improved risk simulator. The simulator will visually depict simulations of betting, trading and staking. The picture above displays the Staking simulator tab, which I am currently working on.

You will notice Martingale and Fibonacci staking options. I am not advocating them as viable staking plans. If the release program has them then it will be to demonstrate that they don't work. However, I expect most of my readership to intelligent enough to have discounted them already so I might remove them as options.

RiskSimulator


I have written a simple RiskSimulator for level stakes betting. The application permits up to 100,000 bets to be simulated with graphical outputs. The user enters fair and bookmaker/exchange odds, a Monte Carlo simulation handles the rest. When the simulation is complete the yield, risk of no profit and risk of ruin are output. Also, two charts are output; a time series progression for the bankroll and a histogram of variance.

Although using standard statistical methods such as the binomial distribution will provide more accurate results, the simulator provides a more easy to understand visual representation. Also, a binomial distribution is based on an infinite number of trials. As nobody bets an infinite number of times a Monte Carlo simulation can show the user the wide variation between what is expected mathematically and what may happen in reality.

Above, we see that the distribution of results in the histogram is not a smooth curve (as one would expect from a binomial distribution) even for 100,000 trials. Future work will include a StakingSimulator for users to investigate the worth of various staking systems, including level stakes, proportional stakes, Kelly Criterion and guaranteed losers such as Martingale and Fibonacci.

Calculated Bets: Computers, Gambling, and Mathematical Modeling to Win

Steven Skiena of Stony Brook University has a lifelong passion for the sport of Jai Alai, a ball game from the Basque region of Spain. Akin to squash, the game is played with baskets attached to the hand rather than with racquets held by the hand. The book details Steven's building of a model for the game of Jai Alai with which he used for betting. The book explains the rules of Jai Alai and how betting is incorporated into the game. It is important to understand how betting and a sport's rules are related, which can reveal quirks that can be utilised for arbitrage.

In the following chapters Steven builds a Monte Carlo simulation of Jai Alai so that he can test his theories about the likelihood of any one particular player in a matchup winning the event. With 8 players vying to be the best there is an advantage in being one of the first two paired players to play. Steven's simulation proves this hypothesis. Using available player ratings Steven builds a model for each player and for the payoffs for various kinds of Pari-Mutuel bets. He then goes on to build an automated betting system, which was rather sophisticated for its time. Finally, Steven discusses how to approach other sports and gambling games using his methodology.

All-in-all this book is a fascinating read. Some find it hard going but I can appreciate all the hard work that Steven has put into mastering modelling a sport and betting on it. If you want to know what it takes to model a sport and build a bot to place bets then you need this book at hand. You won't learn how to program specifically for your requirements and this book was written before Betfair took off. However, you will learn what it takes to dedicate yourself to a related task.

Amazon - Calculated Bets: Computers, Gambling, and Mathematical Modeling to Win

Introduction to Monte Carlo Methods

Monte Carlo methods involve the use of computers to make millions of guesses to the solution of a problem. As with the Wisdom of the Crowd the more guesses that are made the closer to the correct solution you get. A common example, when explaining Monte Carlo Methods, is the estimation of a value for Pi. And because Monte Carlo Methods use random numbers we also use in this example the random process of throwing darts blindfolded at a circular dartboard placed on a square backboard.

If we imagine a hypothetical dartboard of radius 1 unit (diameter is 2 units) then we can place this dartboard onto a square backboard of 2 units by 2 units. (see following image)


We know that the area of a square is Height * Width and in this case the area will equal 4 units. The area of a circle is Pi * radius^2 but because we know the radius to be 1 and 1^2 is 1 then the area of our circle is therefore Pi. If we can calculate the area of the circle then we will know the value of Pi. Because the circle touches the four sides of the square then it is seen that we can subtract the area of the square not covered by the circle from the area of the square to leave us with the area of the circle and thence a value for Pi. So how do we determine the area of the square not touched by the circle?

This is where the dartboard analogy is used. If we randomly throw darts in the direction of the backboard and dartboard then darts will hit the dartboard with a frequency of area of circle/area of square. In reality we know that Pi is approximately 3.14... so we would expect darts to hit the dartboard in the approximate ratio of 3.14/4 or about 0.785 times the number of darts thrown. If we multiply our experimentally determined ratio by 4 (the unit area of the square) then we will have a value for Pi.

All we now need to do is throw lots of darts randomly in the general direction of the backboard and work out the ratio of hits to the dartboard to the total number of darts thrown and multiply this answer by 4. We can either do this by buying a dartboard and a backboard (wouldn't that be a fun experiment for young school children!) or we can work it out using Excel (less fun for young school children).

In the next image (click to enlarge) we can see a spreadsheet to calculate Pi by Monte Carlo Methods. Column A is just a count of the number of trials, column B is the X co-ordinate of our dart given by =1-(2*RAND()) and column C is the Y co-ordinate of our dart also determined randomly by =1-(2*RAND()). We use that particular random number generator to give us a range of numbers from -1 to +1, our unit dimensions.


We can now drag these three columns down for as many iterations as we require. In this example I have done 10,000 iterations. (For a greater number we can always run the simulation multiple times by pressing F9 on your keyboard and noting each estimation.)

Next, we want to know if a dart has entered the dartboard rather than the backboard so Columns D and E determine if the co-ordinates in B and C are within the circle. We do this with the formula =IF(B3^2+C3^2<1,B3,0) (see end note) in column D and =IF(B3^2+C3^2<1,C3,0) in column E. Drag these down as far as you have gone in columns B and C. You will notice that sometimes the values in columns D and E are zero. This is because the dart has missed the dartboard.

We can also see scatter plots of the random numbers generated. The square is created by a scatter plot of the numbers in columns B and C and the circle by the numbers generated in columns D and E. These charts show that the numbers are correctly defining our square and our circle.

Columns F and G count the number of darts in the dartboard and the number of darts thrown. There are a variety of ways to do this but checking for X or Y not equal to 0 will count the number of darts in the dartboard for column F. Column G is superfluous as it always counts a dart thrown. In cell F2 we have a count of all darts in the dartboard and cell G2 is just a count of all darts thrown.

Finally, cell I2 is the ratio of darts in the dartboard to darts thrown and cell I3 is that ratio multiplied by 4. As you can see, even for many thousands of trials you will get wildly differing results. Of course, we will never get close to the value of Pi because it is of infinite length but the longer the trial continues the closer we get, within the limits of 32 or 64-bit computing.

The drawback of using Monte Carlo Methods for calculating Pi is that it is a computationally wasteful method. Mathematicians have come up with simple algorithms that calculate Pi to an adequate number of decimal places with just a few iterations. When we use Monte Carlo Methods we must be sure that there is not a simple method for performing our calculations first before we use something like Monte Carlo. For other problems, Monte Carlo Methods may be the only way and my next article will take us towards such problems.



For a book on sports specific Monte Carlo methods there is the excellent Calculated Bets: Computers, Gambling, and Mathematical Modeling to Win by Professor Steven Skiena. Steven constructed a simulation of the game of Jai Alai using Monte Carlo methods for an automated betting system. In chapter three of his book the professor simulated one million games of Jai Alai and was able to construct a model for win, place and show betting. He has also given a video seminar on his work too.



End note

This formula is derived from Pythagoras. Any line (radius) from the centre of this circle to its edge is of length 1. This line is also the side opposite the right-angled triangle formed by the centre of the circle and the X & Y co-ordinates thus, if the sum of the two squares of the co-ordinates is less than 1 then the dart lies along a radius and is therefore on the dartboard.

Calculated Bets: Computers, Gambling and Mathematical Modeling to Win

Here is a series of videos from a seminar given by Steven Skiena, author of Calculated Bets: Computers, Gambling, and Mathematical Modeling to Win. I recommend Steven's book. The book scores lowly on Amazon but that is due to readers expecting a get-rich-quick treatise rather than a scholarly work that prompts the reader to do further research.

In the book Steven detailed his methods for modelling and betting on Jai Alai games. Although, the market for Jai Alai gambling is very small the methods Steven used can be applied to any sport.

Steven used statistical methods to build a model for Jai Alai play and then used Monte Carlo methods to model millions of games with which to judge his betting rules.

Part 1

Part 2

Part 3

Part 4