Saturday, 9 February 2019

Liverpool v Bournemouth Today: Analytics and Form Heatmaps

I have been running some analysis on today's games. Here are some numbers for one of the crucial ones - Liverpool v Bournemouth. I've developed a "heatmap" to show the form of both teams!

Here is a heatmap for Livepool. Attcking from increases left to right, while defensive form increases up the page. Believe me, this shows phenomenal form!


Compare this with Bournemouth. They are clearly less good!!

So, here is my odds estimate!

    x:0  x:1  x:2  x:3  x:4  x:5  x:6  x:7  x:8  x:9
0:y  57/1 90/1 367/1 1723/1 8332/1 49999/1 --- --- --- --- 
1:y  15/1 28/1 90/1 426/1 2272/1 16666/1 49999/1 --- --- --- 
2:y  9/1 16/1 58/1 234/1 1999/1 49999/1 --- --- --- --- 
3:y  8/1 13/1 45/1 229/1 1922/1 16666/1 49999/1 --- --- --- 
4:y  9/1 15/1 58/1 242/1 2499/1 16666/1 --- --- --- --- 
5:y  13/1 22/1 78/1 367/1 2173/1 16666/1 --- --- --- --- 
6:y  22/1 39/1 123/1 609/1 4999/1 24999/1 --- --- --- --- 
7:y  47/1 75/1 235/1 1281/1 8332/1 --- --- --- --- --- 
8:y  105/1 179/1 514/1 7142/1 24999/1 --- --- --- --- --- 
9:y  164/1 275/1 745/1 4999/1 49999/1 49999/1 --- --- --- --- 

summary:  Home win, 1/8; Away win, 29/1; Score draw 17/1; No score draw, 57/1.

Looks like the most likely result (by a whisker) is 3 - nil to Liverpool.


A reminder, this is a new method and still needs to be validated, so use with caution.

Wednesday, 6 February 2019

Everton v Man City Tonight!

So, here is my first odds forecast, for tonight's prem game...

Here is a grid of the odds for all score combinations up to 9 apiece...

       x:0     x:1  x:2   x:3  x:4  x:5  x:6  x:7  x:8  x:9 
0:y  19/1   8/1  10/1 13/1 32/1 74/1 207/1 768/1 2499/1 9999/1  
1:y  17/1   9/1  9/1 15/1 28/1 70/1 226/1 832/1 1999/1 9999/1  
2:y  42/1   19/1 19/1 31/1 68/1 146/1 285/1 1666/1 - 9999/1  
3:y  151/1 59/1 61/1 92/1 166/1 369/1 1110/1 - 9999/1 -  
4:y  344/1 262/1 178/1 434/1 999/1 1999/1 3332/1 4999/1 - -  
5:y  2499/1 1110/1 908/1 1666/1 3332/1 4999/1 - - - -  
6:y  4999/1 4999/1 - 9999/1 - - - - - -  
7:y  9999/1 - - - - - - - - -  
8:y  - - - - - - - - - -  
9:y  - - - - - - - - - -  


And here are some summary odds: 
Home win: '44/10', 
Away win: '1/2', 
Score draw: '5/1', 
No score draw '19/1'

These are based on 10,000 modeled games and 5000 particles per team. Interested to know if there are other odds people would be interested in.

I compared with Bet365 odds, which are generally fairly similar. My numbers seem to like the idea of a home win slightly more than Bet365. 1 nil to Everton looks like a value bet (although odds are long).

Health warning: I am still validating this model, although I believe the approach is generally solid!

*** Update*** the game finished 0-2 (win for Man City). It stood at 0-1 until injury time, which would have tallied with my most likely result

Sunday, 3 February 2019

Back to Bayes-ics

As explained last post, to do our football analytics, what we need are some input parameters about how "good" the two teams facing each other in a match are likely to be, on the day. There are two alternative approaches to doing this. One is based on classical statistics. To follow this approach you look back over a load of matches and work out an average scoring rate and an average rate of conceding. You can also estimate, on average, how much better the team performs at home. This approach has some weaknesses though. A team can get better or worse over the season; Its no good at telling how good the team will be today. It also requires quite a lot of data (a lot of matches) and assumes all the teams form are stable over time. In other words, it makes some assumptions that are not true. Which is never good.
A much better approach is to use Bayesian statistics. Thomas Bayes was a statistician with a keen interest in games of chance. Hence his work is very relevant to all sorts of gambling! The formulas he gave us are all about inferring the underlying truth from a series of observations. Each observation modifies our belief in a given hypothesis. To cut a long story short, bayesian inference crops up everywhere, in modern analytics.
The particular method I am deploying for football match analysis is the Particle Filter - a modern development, based entirely on Bayesian inference. You can find a pretty good intro to particle filters in this slide deck. Note the reference to football results analysis on slide 24... Using a PF for football analysis is s a nice party trick that often crops up in tutorial material, although I do it in a slightly more sophisticated way to the standard approach.
Applying a particle filter to the English Premier League works like this:

Each team is represented by a large number of "particles", each of which is a guess at the "model" - i.e. the qualities of the team (its attacking strength, defensive strength etc.)
  • Between fixtures, we "advance" these models, saying in effect. Last week the team was like this, so this week, how might the team have moved on
  • After a fixture, we "filter" the particles, preferentially keeping those that best explain the result. Incidentally, this is where Bayes comes in. His theorem says that instead of asking the hard question, "how good is my particle (model), given the result", we can ask "how likely is my result, given my model". This turns out to be an easier question and one we can answer. Importantly we consider not just the result but the capabilities of the teams involved. Hence all the analysis is interconnected.
  • Now, when two teams face off, we have a set of guesses about the teams capabilities at the present time that is based on all previous results, especially the last result. We can model the game considering the full range of guesses and get the best possible odds prediction, given the evidence.
In a nutshell, that's it. My plan now is to publish some predictions before the weekend fixtures and try to ascertain if we can beat the bookies!. That's my goal. Bookies are there to be beaten after all.

Saturday, 2 February 2019

Monte Carlo Football Analytics - Project Monaco

I'm going to christen this effort Project Monaco. It's about Monte Carlo and Football, so it's a no brainer, right?

I'll explain the basics of the analysis...

Consider two football teams, facing each other. The result is based on a few things. How good is the home team at attacking? Conversely, how good is the away team at defending? These two things will help determine an average rate of goal scoring for the home team. There is another factor in there - the home team advantage. Some teams perform better at home than away. Others do not, and some teams even do a little better away from home (home fans can be off-putting if they're not getting behind the team). On the flip side, how good is the away side at attacking, and how well can the home team defend.
In my method, I put these numbers into a pot, and work out an average expected rate of goal scoring for each team, in the context of them playing each other. I then create a computer model of the fixture, and run about ten thousand trial games, recording the result of each. What I get is a comprehensive odds forecast, covering every score permutation.
The computer model uses a classic statistical method to model the results of each trial game. The binomial distribution. Its hard to argue with the basics of this. The one hard part we are left with is establishing the input data for the match, regarding the strengths and weakenesses of each team. The truth is, we can't be certain about them, and that leads to some complications. What we need to do is consider a range of possibilities regarding this input data, which makes things a little mroe complicated. I will explain how we work out these inputs based on the league results in the next post!

Context Switch - Monte Carlo Football Analytics

It's been a year since m,y last post on Monte Carlo modelling of horse races. The reason for the gap is that I realised, through quite a bit of experimentation, that my methods for predicting the "true odds" of a horse race really weren't fit for purpose. A lot of the time, my odds predictions were quite similar to those from the bookies. But the cases where I predicted a horse should have much shorter odds (i.e. the "value bets" did not win as often as I expected. Essentially there was very little profit to be had. None, in fact, beyond random outbreaks of good luck.
I concluded that, for horse racing, there was a lot of information out there that helps understand how well a horse is likely to perform. Maybe a lot of it is on "back channels" known only to the inner racing community.  But, I concluded, at a minimum, you really needed to look back at a horse's history and see how it fared against each horse it raced, and to know how good each of these other horses were. That, I concluded, was too much like hard work (at least for now). Too much bespoke web scraping to be written for one thing, and life is too short. What I did do, is dream up an analysis method that could genuinely work. Its based on established methods, although it has elements that I don't believe have been tried before. But I decided it would be much easier to operate this on a more restricted field of runners. Like a football league, where a small set of clubs face each other in a very well defined, exhaustive set of fixtures. The Premier League, will be my case study!
The good news is, having tried this, I KNOW I have a method that is at least pretty cool. As I planned to do with the horse racing, I will provide more details about the method, and some of my odds predictions for upcoming games. More posts to follow!

Tuesday, 20 February 2018

Monte Carlo or bust?


Looking around a bit shows I am not unique in using Monte Carlo simulation to estimate the  true odds, in horse racing. For examole, see this monte carlo example. The author has a nice idea of using standard horse ratings, namely Official Rating (OR) and the Racing Post Rating (RPR) as the input to the model. My method is to use the past performance of each horse as the input - which I believe has some neat benefits - but the basic approach is the same.

Basically the first we have to do is define a probability density function (PDF) for the speed we think each horse might run in the race. It might look like this:

It represents the probability the horse will run at any given speed. The peak of the PDF represents the most likely speed for the horse. It may run faster or slower, but each are less likely. The PDF tails off at the edges to show this. The extreme edges are getting pretty unlikely. The shape of the PDF is important. The typical thing to do is to use a Normal or in other words Gaussian form for the PDF. This is not a bad choice, because Gaussian PDFs crop up all over the place in nature, so the likely running speed for a horse probably follows one.

When we execute the Monte Carlo race model we run a lot of imaginary races (maybe 1000 or more) and simply count the times each horse wins. To simulate each race, we draw, at random, example speeds for each horse from the PDF- such that the most likely race speed for each horse is in the middle of its distribution, with the frequency falling off towards the edge of the distribution We then rank the horses based on speed and work out the winner. Here the choice of the Gaussian PDF is handy because computer languages often have a ready made function for generating random samples from a nor distribution. I'm using Python, and it does the job nicely.

So, we have the results of a thousand or so simulated races, so now we can calculate the "true" odds for the horses easily enough. We made a few assumptions along the way, but if these are true, our odds should be good. Just to state those assumptions again:

  • We assume the past performance of the horse provides a good measure of its quality
  • We assume the horse's speed PDF is a Gaussian distribution positioned in proportion to the horse's quality score. 
  • We have to "invent" a width for this Gaussian, (called the standard deviation). This is a bit of a weakness, in that we have to make this up to make the odds look right. Still, it should probably be fairly constant for all races.
So, that's the basis of the approach. I'm working on some improvements that are quite subtle, and I'll introduce in future posts. Now lets see how well it works!

Thursday, 15 February 2018

Horse Race Analytics Explained

As discussed in the previous post, the aim of my horse race analytics is to estimate the "true odds" for each horse in a race, so that we can compare them with what bookmakers are offering, to identify "good value". I put the term "true odds" in quotes (I did it again!) for a reason. It is quite hard to say what the true odds of anything is - let alone a one-off thing like a race. To measure the true odds accurately we would need to run the same race, with the same horses,  the same health, in the same weather and track conditions, a very large number of times and count the outcomes. But the weather is actually an uncertain factor so maybe we'd need to use a few different seasonally appropriate weather conditions. Anyway, clearly this is completely unfeasible, and the true odds are therefore really quite an abstract concept. Its doubtful that a precise number value for the true odds can even be defined in fact. One thing we can do is work out our way of calculating true odds and test it over a large number of real races. Our three to one (3/1) horses should on average win once for every three losses, our 2/1 should win once for every two losses etc. Incidentally if you are not familiar already, it turns out odds are a little different to probabilities. They are quoted as the number of losses vs. the number of wins. The win probability on the other hand will be a number between 0 and 1 defining the likelihood of a win in each race.

My approach to calculating the true odds has two stages. First, we estimate a "quality score" for each horse. The better the horse, the higher the quality score. We need to decide a standard way of doing this - for example we could look at the six previous races and assign a score of 5 for a win, 4 for second etc. I have a more sophisticated approach that I'll describe in a future post, but for now, you get the general ideas. 

Having calculated a quality score for each horse, we then use this to estimate the odds. In simple, made up cases, this might be easy. If three horses race, for example, and they are all exactly equal in terms of quality score then the true odds are 2/1 for each horse, because, on average, in each 3 races, each horse will win one and loose twice. For any significantly complicated example, it gets a lot more difficult. In fact, it rapidly becomes quite impossible to calculate analytically (i.e. using a formula). The way to do it is to do the kind of thing  merchant banks do a lot when analysing trades - Monte Carlo modelling. More about how this works in the next post.