Time to Trade Tennis

Tennis is my favourite television sport, after cycle racing. The sport is also my favourite sport to play now that I am getting on in years and am no longer able to cycle at the level I once did. I have never considered trading tennis before because horse racing was sufficiently challenging but with my book out of the way I have time to consider new projects.

The sport of tennis is relatively simple to model as the sport is a head to head between a pair of players or a pair of partners in doubles. Unlike football there is always a winner in tennis so the draw is not a consideration. With the exception of Davis/Federation Cup games there is no concept of home and away. The days of home nations dominating Grand Slam tournaments are probably over. 

The scoring system in tennis favours the player who wins the most points (an obvious statement to make but stay with me). This can be seen in an interesting simulation using Monte Carlo methods created by Michael Maboussin author of The Success Equation. If you click on the following link then you will see the simulation in action.

Tennis Simulation

With players of equal ability the probability of either player winning the game is 0.50 but you only have to play around with the simulation to see that a player who is only marginally better than another player has by far the greater chance of winning a match. Indeed with a 57.7% chance of winning you guarantee victory with a 1.0 probability of winning the match. I can vouch for that personally. Being rather middle-aged and decrepid I tend not to play singles games as I am guaranteed to lose. I am better suited to the slightly more static role of net poaching in doubles.

In reality not all games go the way a simulation might have you believe. The top seeded players lose games for a variety of reasons. Their abilities might be waning but it takes time for them to drop down through the rankings. A player might treat a tournament as a training exercise and withdraw after a couple of rounds or their mind might be on a more prestigious future tournament and they make too many mistakes and lose a match to a lowly ranked player.

Data for tennis matches is very easy to come by and is usually free. There are also websites where you can match up a pair of players to see how they faired against each other in the past. Once such site is MatchStat and can be found at the following link.

MatchStat

Just enter the names of the two players in a singles match and you will be shown their previous matches against each other. However, it is not just a simple matter of creating a probability from the number of times a player has beaten another. As you will see in MatchStat, games are played on different surfaces with some players preferring one surface to another. The players at the top of the ATP rankings will be mindful of their ranking points and build their season around the bigger tournaments such as the four Grand Slams and the ATP Tour Masters 1000 tournaments. The lucrative ATP World Tour final at the end of the year is also borne in mind too.

Currently, I am working on my own Monte Carlo methods simulator, which will allow the user to model some of the aspects mentioned above and permit "What if?" scenarios to determine how various factors alter the probability of winning a tennis match. With probabilities you can derive odds and use them as a basis for trading with.

See Also

Tennis Citations - Some academic work on tennis trading

The Hidden Mathematics of Sport - Contains useful mathematical facts on tennis and other sports

Back to Work

Completing the book was a long six months, full of doubts and rewrites. I am glad that the book is finished so that I can contemplate new projects.  But just because I have put all my code into a book doesn't mean that I have nothing left to write on this blog. My observations of bot trading on Betfair will continue and decrying some of the nonsense you read elsewhere.

There is more code to write, which will probably find its way into another book in the years to come. Then there are my investments to catch up with. I am very much a believer of "getting rich slowly". Not everyone can be an Elon Musk or Richard Branson, creating a string of successful money making products. In fact, very few of us can. It's all part of the normal distribution. There is little space at the top of the distribution peak for many people. Every winner needs a loser and every big winner needs a lot of losers. 

Be happy with what you have and make the most of it. By all means try to improve your lot but don't gamble for it. Invest wisely with your time to increase your knowledge and invest wisely with your capital to increase your wealth. There are many who win big only to lose big later. You can make a lot of money quickly and lose it just as quickly. It's all about risk and reward. The more risk you take the bigger the reward but also the bigger the potential loss. 

I am sure you have seen plenty of blogs where people run up large wins at the beginning and then the blog ends abruptly. Blogs where people proudly boast their winnings but withhold their losses, even manipulating the figures or starting over so as to hide their failings. Sports trading is only a small part of what I do. I am in no hurry to make large sums of money. Approaching my fiftieth year means that the money I have gained from working for others is all the money I will ever have from that route and so I have to invest wisely. Today I only earn what I can scrape off the Internet. I have money in Peer 2 Peer investment sites, I write about trading, I code trading strategies, I do the odd consultancy job, gathering money here and there. My life is varied and its my own. No nine to five and no manager. Time for a holiday.

Programming for Betfair

Programming for Betfair, a guide to creating sports trading applications, is now available on Amazon. You do not need any previous programming experience to follow the book, just a logical mind. Both beginner and expert programmers have completed the book. Programming for Betfair teaches you all you need to know about programming your own trading applications.

Why Would I Want This Book?

Yes, there is plenty of third-party software out there but a lot of this software is geared to manual trading and even then, trading in a certain style. You may have your own trading strategies, which cannot be implemented with third-party software. Algorithmic trading is best done with software that you have crafted yourself. Also, you may not want third-party software to be able to implement your ideas otherwise other traders will happen upon your strategies.

In the long-term there is a great cost-saving to be had from producing your own trading software. Betfair does charge a £299 one-off access fee for receiving live data through API-NG. However, you can receive free delayed data (with a one to sixty seconds delay) whilst you develop your own software and strategies. Betting functions are always in realtime whether you use live data or not. Also, with the delayed key you will still have access to the lastMatchTime so you will know at which time the lastPriceMatched was struck.

Most third-party trading software has a subscription fee that has to be paid every month and eventually you will pay a lot more than Betfair's API-NG live access charge. You can always work through this book, test some ideas and then decide if you want live access to the data at a later date.

What will the book teach me?

Using the freely available Visual Studio programming environment I show the reader how to build an application that gets prices from and places bets automatically into Betfair's exchange.

Also, the reader can build databases from Betfair data for offline analysis. Data can be saved whilst the trading application is running and then converted into a CSV format for a spreadsheet where it can be manipulated, charted and analysed for the creation of trading rules.

After working through the book the reader should have all the tools needed to start building their own trading bots.

There is also a chapter on improving access to the charts on Betfair's website. Charts can be grouped together for comparison and updated automatically to keep the trader up to date with the latest trends in the market place. The final chapter touches on some advanced techniques such as the creation of trading indicators, volume analysis (specifically VWAP - volume weighted average price), low-latency optimisation, arbitrage, machine learning, Monte Carlo methods and more.

With this book you will be able to create trading bots using your own trading systems. You won't have to give away any of your trading secrets through asking a third-party to include the exact functionality that you require in their software.

Some Screen Captures from the Book

Betfair's visualisers are used to demonstrate how JSON is used to communicate between the reader's computer and Betfair's servers. The reader is then gently led through the creation of JSON request strings and the processing of JSON response strings into raw data for use by the application.


The price engine with a bet placement control for experimenting with various bet types. The user is then shown a non-graphical way of inserting bets into the exchange for automated trigger betting with bots.


A ChartBot can easily be created for multiple views of Betfair charts, side by side. They can also be set to auto-update.


The applications created in the book can build databases of data for offline analysis in a spreadsheet so that the user can analyse the data and build trading rules.


Contents

Preface
Introduction

Chapter 1 - A BASIC Approach
Join the Revolution
Microsoft Visual Basic
Google Chrome

Chapter 2 - Logging into Betfair
Session Tokens and Application Keys
The ToolBox
Changing a Control's Properties
Adding Another Form
The WebBrowser Control
The Betfair Visualisers

Chapter 3 - Understanding JSON
JavaScript Object Notation
JSON Parser
ListMarketCatalogue
Serialization and Deserialization
NewtonSoft.Json.dll

Chapter 4 - Off to Market
Sending a Request
Serializing a Visual Basic Object into JSON
Referencing Newtonsoft.Json.dll
Building a Visual Basic Request Object
Deserializing JSON into a Visual Basic Object
Running The Application

Chapter 5 - A GUI Feeling
Displaying the Contents of a JSON Response
The DataGridView Control
Building a Standalone Application
Further Work

Chapter 6 - Gathering Prices
Using the listMarketBook Method
Processing ListMarketBook Responses
The Timer Control
Further Work

Chapter 7 - Place Your Bets
Types of Trader
Placing a Bet Through the Visualiser
Sub £2 Bets
Greening Up (Hedging)
Betting Experiments
Monitoring Bets
Automated Trading
Further Work

Chapter 8 - Saving Data for Offline Analysis
Saving Data to Your Hard Drive
Processing Data for Offline Analysis
Data Visualisation with a Spreadsheet

Chapter 9 - Automating Betfair Charts
ChartBot
Creating a Form Programmatically
Using ChartBot
Further Work

Chapter 10 - Making The Most of It
Quantitative Analysis
Creating You Own Indicators
Volume Analysis
Trend Following
Fundamental Analysis
Arbitrage
Money Management
Optimising for Speed (Low Latency)
Machine Learning
Monte Carlo Methods
Concluding Remarks

Recommended Reading

Complete Listings

Is there an eBook? There will not be an eBook. I am a self-publisher with no facilities for creating eBooks. My book is printed on demand with no advance royalties from a publisher therefore I am dependent on all future sales. As I started coding in the early 1980s I am used to entering code from magazines and books. I feel that I learned more from that than today's generation who cut and paste their knowledge. There is a lot to be said for doing things slowly.

Need help with the book?

If you are looking for help on this page then you have not read the book properly. Start again from the very first page, read carefully and you will find the URL for the book's support page, where I provide updates and help beginners to find their typos.

With over 1000 satisfied readers, the code in this book (as of February 2017) still permits a trader to create their own applications for algo-trading and historic data capture.