Programming for Sports Betting

There are many areas in which programming can assist the sports trader. Automation of your trading allows you to remove emotion from your trades. An emotional trade can often be a losing trade. If your trading algorithms are profitable then they will succeed without human intervention.

Programming also permits you to trade markets in parallel thus allowing for a scaling up of your trading. Why trade only one market at a time when you can be trading and profiting from many markets simultaneously?

Listed here are areas in which programming can automate and assist the trader.

  • Manual trading
  • Automated trading
  • Web Scraping for data
  • Quantitative Analysis

Manual Trading

There is much third party software to assist the manual trader as listed in the Trading Software section of this website. However, you may want to progam your own software if you have security worries about third party software or wish to prevent your proprietary algorithms from reaching the public domain.

You can read more about programming your own software in Write Your Own Betfair Software

Automated Trading

As your skill as a trader improves you will want to scale up your trading through automation. A manual trader can only effectively trade one market at a time. By automating your trading, a bot can perform simple and/or repetitive tasks allowing the trader to free up time to trade on multiple markets with the possibility of increased return on investment.

Areas of automation include the following

  • Machine access to betting markets using price gathering and trading bots. 
  • Gathering of sports data from web sites by way of web scraping. 
  • Charting of time series data.
  • Pricing algorithms for determining fair odds. (See also Sports betting arbitrage)
  • Trading algorithms for routing trades to the exchange/bookmaker with the best price. Algorithmic Trading

Web Scraping

Although prices can easily be obtained through the betting exchange or bookmaker's website there maybe additional data that you require and for which there is no API to assist you. In horse racing there are many online publications where you can download race data for previous races. The Racing Post is one such site. Through use of RegEx or serialization it is possible to download a page from an online source and parse it into a database. (More on this to follow)

Quantitative Analysis

When you have collected your data you will want to analyse it to generate trading rules. Software for analysis could simply be a spreadsheet, to more mathematical software such as R. Programming in VBA can enhance the capabilities of Excel. The quant can also develop software such as a Monte Carlo simulator for simulating sports event prior to them taking place or develop software utilising machine learning techniques to discover trading rules. (More on this to follow)

Further Reading

I recommend the following texts


A guide to creating sports trading applications with API-NG. This book teaches you how to build sports trading applications, from gathering prices to placing bets into Betfair's exchange. The reader is also taught how to build a database of prices and volume for offline analysis, automating Betfair charts and a brief look at advanced techniques; trading indicators, volume weighted average price, arbitrage, machine learning, Monte Carlo methods and more.



A complete telling of one man's modelling of the sport of Jai Alai and his profitable automated betting on the sport. Full Review

14 comments:

  1. Would be interested to read more on web scraping in current RP format. A few years ago I was just using web queries in excel. Would use a tool to pull up all the URLs for the days racing then dump them into excel and run the vba to pull in the web query table for each link. Then automate the data clean up and formatting. Cannot do this now..

    ReplyDelete
    Replies
    1. My next book will have a little on web scraping. Due to copyright, I have to be careful not to make explicit mention of any website.

      Hopefully, people will know what "Chasing Toast" refers to.

      Delete
  2. Is web scraping legal James?

    ReplyDelete
    Replies
    1. There might be copyright issues depending on what you do with the scraped data but not the actual scraping itself.

      Plenty of books teaching you how to scrape. No publishers being dragged through the courts.

      Delete
  3. Hello,

    I bought the Programming for Betfair and at page 19, at the Betfair Visualisers section, the given link does not work.

    Can you please provide updated link?

    ReplyDelete
    Replies
    1. Obviously, you are reading the book too fast and have not found the support URL.

      Start again. Slowly.

      Delete
  4. Hi James,

    Is there any way we can reach you via a personal message ? I.e an email address please?

    ReplyDelete
    Replies
    1. Leave your email address in a comment.

      I don't publish comments with email addresses.

      I will contact you when I get your email address.

      Delete
  5. Hi James is there anyway a stoploss can be programmed for trading the football markets on betfair ,I have tried everything but when the market suspends my stoploss disappears.Rgards Billy

    ReplyDelete
    Replies
    1. Look through the literature for 'persistence'.

      Delete
  6. Hi James,

    Working through your book and doing well so far, i have an issue though regarding the end result on P40. Hoping my email shows i can explain in more detail the issue.

    ReplyDelete
    Replies
    1. Look at the earliest pages of the book for the support web page. From there you will find errata and other help.

      Delete
  7. Hi James,

    I'm just getting into trading. Luckily I found your website before shelling out for any dodgy scalping courses.

    I have been looking around the website but I'm unsure where to begin. I am pretty good when it comes to mathematics but have no knowledge of writing software.

    The thing I've quickly noticed myself is what you've identified - people working off feeling. Talking about a strategy and then having a "feeling" that the market is going to change, yeah it did, no it didn't, oh actually it did....wasn't that lucky I've made a profit. I knew I would...kind of thing.

    So this is the first proper place I've come across that debunks all that nonsense. My question is: where do I start. I'm willing to put in the time and effort to learn how to automate things, what strategies actually work, focus on the psychological side of things but I just don't know where to begin. Could you point me in the right direction please?

    Thank you.

    ReplyDelete
    Replies
    1. Thank you for your message. Naturally, I am going to point you in the direction of my two books. Buy them but use them as a reference for the time being. Something to build up to.

      To start with, pick a sport you know something about. From there you will determine what moves prices. You must build databases of price changes, pre-market and in-play. You will also be looking for mis-prices that will either correct or provide edge when the event is over.

      Betting/trading all boils down to edge. Whatever triggers a bet or trade must pay back more than it pays out.

      With algo-trading there is no need to worry about psychology. The only psychology in algo-trading is the ability to work long and hard and trust only your algorithms and trading programs. If it's a profitable algo you leave it, if not you switch it off.

      You can start with filter rules; statistical analysis of events and their prices. Do they return more than they pay out? Then move on to more sophisticated systems that play on the psychological defects of punters.

      It's all about two things; data and looking for edge in that data.

      Remember also to look at all aspects of your life. What is the edge and am I paying out too much? Not spending money is as good as making money. Most billionaires are misers!

      Good luck!

      Delete