<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Aritra on Medium]]></title>
        <description><![CDATA[Stories by Aritra on Medium]]></description>
        <link>https://medium.com/@arit.pom?source=rss-99bd1f158d77------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*GELVnaFUKKi3wmnD.jpg</url>
            <title>Stories by Aritra on Medium</title>
            <link>https://medium.com/@arit.pom?source=rss-99bd1f158d77------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 22 Nov 2026 10:40:25 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@arit.pom/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Football Odds data analysis using MonteCarlo simulation in Python — Part 2]]></title>
            <link>https://medium.com/@arit.pom/football-odds-data-analysis-using-montecarlo-simulation-in-python-part-2-43f5e951c1fc?source=rss-99bd1f158d77------2</link>
            <guid isPermaLink="false">https://medium.com/p/43f5e951c1fc</guid>
            <category><![CDATA[football]]></category>
            <category><![CDATA[odds-and-betting]]></category>
            <category><![CDATA[football-betting]]></category>
            <category><![CDATA[monte-carlo-simulation]]></category>
            <category><![CDATA[football-analytics]]></category>
            <dc:creator><![CDATA[Aritra]]></dc:creator>
            <pubDate>Tue, 21 Mar 2023 16:12:56 GMT</pubDate>
            <atom:updated>2023-03-21T16:12:56.871Z</atom:updated>
            <content:encoded><![CDATA[<h3>Football Odds data analysis using MonteCarlo simulation in Python — Part 2</h3><h3>Introduction</h3><p>A few days back I did a course on “data camp” about “Monte Carlo simulations in Python”. Since then I am thinking about how to apply those skills in real-life data to simulate something. Then in my last <a href="https://themachineball.com/blog-details/13">post</a>, I used Poisson distribution to estimate the chances (i.e., probability) of a home team and an away team winning along with a draw and from that calculated true odds to compare the results with the bookmaker’s implied odds. This article is based upon some of intutions we build in our last article. Please read the <a href="https://themachineball.com/blog-details/13">part — 1</a> for a better understanding of this one.</p><h3>What is Monte carlo simulation?</h3><p>First simulations are done to mimic reality, basically experiments that attempt to imitate reality. Monte-carlo simulations are used to predict the probability of different outcomes impacted by the presence of random variables. In Monte-carlo simulations experiments rely on repeated sampling to obtain numerical results.</p><p>Last summer me with some of my Romanian friends were doing Bar-b-que in the garden. We suddenly found dice in the garden and one of my friends asked me to play a game, where we both will roll the dice and whoever gets the highest number will win. We played 10 times.</p><p>Now, what we actually did? I rolled the dice, got one number and he did once and got one number. We compared and who got the higher number won. Let’s put this into code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mum8mW09gabiAUk2bwLeSw.png" /></figure><p>I called the above function anf got the result <strong>“Player A wins and the number 4 &gt; 3”</strong> for the first time, again I called the function and got the result<strong> “Player B wins and the number 6 &gt; 5”</strong>. I told you we played the game for 10 times. Now if I call this function for 10 times</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-6kFTLpg3hFrm_rwOa9fsA.png" /></figure><p>the result will be something like this -</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/610/0*lqa22DRpFEQi-_mt.png" /></figure><p>I called again and the results look like below -</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/610/0*-Rgpf2b-fZMwIjnm.png" /></figure><p>Just look at the results which are different and random totally. That is why results from monte-carlo simulations are stochastic in nature because the experiments rely on random sampling. Now remember I was playing the game with my friend, I lost 7 times. It could be vice versa. But I lost. From the above two pictures, we can see once A won more and once B won more. I was unlucky. Before moving on to our football score simulation, let’s take another look at the above game one more time. Let’s calculate what would happen if we would play the game 100 times.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uu3iltTLLdqFeCG79KteMg.png" /></figure><p>The results of playing 10 times -</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/790/0*ZLxlOi1hJtSpHdXA.png" /></figure><p>The results of playing 100 times -</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*PuF7tUFRI3nqIbKH.png" /></figure><p>The results of playing 1000 times -</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*YxxqEy5AgPKrxkX4.png" /></figure><p>What did you notice? The more we play the chances of both the players winning colliding with the same percentage. This is called the “Law of large numbers”. The dice here is unbiased, and the numbers generated are identically distributed.</p><h3>Monte carlo simulation to football data</h3><p>Now, I said at the start that you have to go through the first <a href="https://themachineball.com/blog-details/13">article</a> to get the football odds data. Please go through once.</p><p>In the last article, we analysed the Aston Villa (Home) vs Bournemouth (Away) match from the premier league. We calculated two values — Home team goal expectance and Away team goal expectance. We will calculate here again and the values may be different because of the stochastic nature but will be around the previous values. This time -</p><p>Home team goal expectance = 2.76<br>Away team goal expectance = 1.03</p><p>From these values, we have to calculate goals for each of the home team and away team. Last time we used Poisson distribution and this time we will use Monte Carlo simulation. <br>Now, think of the above expectances as xG per match for the home and away team. We will assume that every match is played for 95 minutes. So, the chances each team will score one goal per minute are like below -</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*zZSVC1yQvRao-kIw.png" /></figure><p>Now we will simulate the home and away teams for 95 minutes and store the number of goals.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tlMwTQPjFbDzMxavkKz4OA.png" /></figure><p>These simple lines of code will generate goals for us. The rest of the calculations are the same as in the previous article. This is the Monte Carlo simulation. <br>Last time we generated a number of goals from Poisson distribution which look like below -</p><pre>home_team_poission = random.poisson(lam=home_team_goal, size=100000)<br>away_team_poission = random.poisson(lam=away_team_goal, size=100000)</pre><p>This is the difference.If you now follow the steps like the previous article and play the match for 10000 times (in other words simulate the match for 10000 times), you will end up something like below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/780/0*9hjh9Ut1Z68s-ryx.png" /></figure><p>From here you can calculate the true winning chances and odds. Code for this article is <a href="https://github.com/kaii55/Odds_calculation/blob/main/Odds_calculation%20with%20Monte%20Carlo%20simulation.ipynb">here</a>.</p><h3>Conclusions</h3><p>Now we know how to use Poisson distribution and Monte Carlo simulation to generate the number of goals. We used two powerful concepts with very simple data. Later someday, probably very soon, we will use complex data and parameters like an expected goal (xG), shots on target and many more altogether to analyse scoring chances, and chance winning more precisely. If you want to generate your own xG model, you can take a look into my earlier post: <a href="https://themachineball.com/blog-details/8">An expected goal model</a></p><p>Link to my website: <a href="https://themachineball.com/">https://themachineball.com</a><br>Link to my twitter: <a href="https://twitter.com/themachineball">https://twitter.com/themachineball</a></p><h3>An important note:</h3><p>The below code will say if the match is played between Aston Villa and Bournemouth 10000 times, what would happen?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4Kb2szmog-gBFv1ub29qMQ.png" /></figure><p>The result looks like below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*p0zZvfG4HCpW7kp3.png" /></figure><p>Here you see that the chances of the Home and Away team win did not collide because here the matches are biased on the basis of chance of scoring. In the dice game, the dice was unbiased.</p><h3>References:</h3><p><a href="https://themachineball.com/blog-details/13">Part -1 of this article</a></p><p><a href="https://app.datacamp.com/learn/courses/monte-carlo-simulations-in-python">Monte Carlo simulation — DataCamp</a></p><p><a href="https://themachineball.com/blog-details/8">An expected goal model</a></p><p><a href="https://github.com/kaii55/Odds_calculation/blob/main/Odds_calculation%20with%20Monte%20Carlo%20simulation.ipynb">Code for this article</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=43f5e951c1fc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Football Odds data analysis using Poisson distribution in Python — Part 1]]></title>
            <link>https://medium.com/@arit.pom/football-odds-data-analysis-using-poisson-distribution-in-python-part-1-bba64852108f?source=rss-99bd1f158d77------2</link>
            <guid isPermaLink="false">https://medium.com/p/bba64852108f</guid>
            <category><![CDATA[poisson-distribution]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[football-betting]]></category>
            <category><![CDATA[football-analytics]]></category>
            <category><![CDATA[footbal-odds]]></category>
            <dc:creator><![CDATA[Aritra]]></dc:creator>
            <pubDate>Mon, 20 Mar 2023 16:01:53 GMT</pubDate>
            <atom:updated>2023-03-21T13:07:02.759Z</atom:updated>
            <content:encoded><![CDATA[<h3>Football Odds data analysis using Poisson distribution in Python — Part 1</h3><h3>Introduction</h3><p>For the past couple of days, I was studying a little bit about statistics, statistical distributions and a lot about football odds data. I do not promote gambling, just interested in the mathematics behind it. Read a lot about how bookmakers set the price on each team according to their winning chances. Came across many good articles, and particularly in this <a href="https://www.newbettingsites.co/articles/true-odds-vs-implied-odds/">article</a>, they say “In betting, the trick is to find markets in which the bookmaker’s odds are bigger than the true odds, for that is where the value lies. (quoted from the article itself)”.</p><p>Now the question is how do you predict chances? If someone involves in gambling, they would notice that there is a price for every single event such as team winning, team total shots, team shots on target, Over and under a certain number of goals, correct score, player scoring or assisting and there are many more events. That means bookmakers have information on each of the things they set the price on. As a result, we need to start at some point to predict chances by ourselves if we want to bet on something (Please bet if you do it for fun or see the accuracy of your prediction and obviously if you have enough pool of money otherwise please don’t).</p><h3>Bookmaker’s odds</h3><p>At very first before indulging ourselves in mathematical calculations and simulations or predicting chances let’s take a look at bookmaker’s calculations. On the 18th of March, 2023, there was a match between Aston Villa (Home) vs Bournemouth (Away) where the odds offered by a certain bookmaker look like below -</p><p>Aston Villa (Home): 1.73<br>Draw: 3.75<br>Bournemouth (Away): 4.75</p><p>That means if you stake 1 pound on each of them, if the Home team wins you will get 1.73 pounds, if the draw happens, you will get 3.75 pounds, and if the Away team wins, you will get 4.75 pounds, meaning that having a profit of 0.73, 2.75 and 3.75 pounds respectively.</p><p>Now, there is a formula for calculating probability from odds, which is - <br>odds = 1/ probability</p><p>So, now if we calculate the probability of winning chances of each team we get the below:</p><p>Home team winning probability = 1/ Home team odds = 1/ 1.73 = 0.578 = 57.8%<br>Draw probability = 1/ Home team odds = 1/ 3.75 = 0.2666 = 26.67%<br>Away team winning probability = 1/ Home team odds = 1/ 4.75 = 0.2105 = 21.0%<br>Total probability set by the Bookmaker is: 0.578 + 0.2667 + 0.2105 = 1.05547<br>Total winning chances set by the Bookmaker is: 57.8% + 26.67% + 21.0% = 105.47%</p><p>But, we know the probability of an event can never be greater than 1, because the number of trials in which the event can happen cannot be greater than the total number of trials. That means the sum of the above should never be greater than 1 or 100%. Then what is the meaning of an extra 105.47% - 100% = 5.47%? This 5.47% is bookmakers&#39; margin (also called overround) to balance their books. Different bookmakers have different margins. Now the probabilities calculated above are then simply called implied probability from implied odds.</p><h3>Data collection and calculating necessary team statistics</h3><p>Now, the question is how we calculate the true odds and probability of winning each of the above-mentioned events. Our calculation begins now, where we will use mathematical concepts and predictions. First, we need data. Everything is over there on the internet, trust me. <a href="https://www.football-data.co.uk/">Football-data-co-uk</a> provides match results of home and away along with odds offered by different bookmakers. We need access to that data, below the simple line of code will do the needful -</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*dicpw6g8bSNpRE8-.png" /></figure><p>The result will look like below -</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*fguAq5AxOCAeVSIp.png" /></figure><p>We will keep our process as simple as we can so that we can build our intuition on top of that. We do not need these many columns. We need the home team name, away team name, home team goals and away team goals. That’s it for now. so our final working data set will look like this -</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/724/0*6GSXGPgGtJIdg10U.png" /></figure><p>Remember our sole purpose is to find true probabilities for ourselves, that means finding the true winning chances. First select the home team (i.e., Aston Villa) and away team (Bournemouth).</p><p>Task 1. Calculate the average total home goals scored.</p><p>Task 2: Calculate the average total away goals scored.</p><p>Task 3. Calculate average Home team goals scored at home.</p><p>Task 4. Calculate average Home team goals conceded at home.</p><p>Task 5. Calculate average Away team goals scored away.</p><p>Task 6. Calculate average Away team goals conceded away.</p><p>Task 7. Calculate the Home team attacking strength. (i.e., average Home team goals scored at home/ average Home goals scored in the league)</p><p>Task 8. Calculate the Home team’s defensive strength. (i.e., average Home team goals conceded at home/ average Away goals scored in the league)</p><p>Task 9. Calculate the Away team attacking strength. (i.e., average Away team goals scored at Away/ average Away goals scored in the league)</p><p>Task 10. Calculate the Away team’s defensive strength. (i.e., average Away team goals conceded at Away/ average Home goals scored in the league)</p><p>Task 11. Calculate Home team score expectance (home_team_att_strength * away_team_def_strength * total_home_goals_mean)</p><p>Task 12. Calculate Away team score expectance (away_team_att_strength * home_team_def_strength * total_away_goals_mean)</p><p>The concept has been borrowed from <a href="https://www.youtube.com/watch?v=ZZW2b84T0cw">here</a>. In my <a href="https://github.com/kaii55/Odds_calculation/blob/main/Odds%20calculation%20(Part%20-%201)%20Aston%20Villa%20vs%20Bournemouth.ipynb">GitHub</a>, one can take a look at the coding I used to calculate the above-mentioned parameters.</p><p>The results of the above tasks look like below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/964/0*cbEdl9-uNRmoKnYw.png" /></figure><p>Now we have to ask ourselves a simple question. Can a team score 2.61 or 1.22 goals? Simply NO. That is where Poisson distribution comes to play. If you want to have an essence of Poisson distribution and monte-carlo simulation and how they are implemented in football data please take a look at these posts — <a href="https://www.sonofacorner.com/an-introduction-to-monte-carlo/">monte carlo simulation</a>, <a href="https://www.sonofacorner.com/intro-bayesian-modelling-football-1/">poission distribution</a>, and <a href="https://soccermatics.readthedocs.io/en/latest/gallery/lesson5/plot_simulatematch.html">randomness</a>.</p><p>Now a single line of code will generate the number of goals for us from the above-mentioned goal expectance with 100000 different values (i.e., samples).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*81M78OoVjLQEiTK1.png" /></figure><p>Next lines of code will generate number of chances of the goals to happen for home and away teams.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/802/0*AaCK8hDgBXoUeudu.png" /></figure><p>If we put them in a dataframe it will look like below — (In the left hand side which is basically the index, also represents the number of goals).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*psIbU4EKjCEWmKcn.png" /></figure><p>Okay then we have come this far to calculate the chances of scoring 0, 1, 2, 3 , 4, 5 number of goals for the home and away teams. we now know the home and away teams’ scoring of exactly 0, 1, 2, 3, 4, 5 goals in the match.</p><p>It is now getting long. I think we should take a coffee break and think of what we have done so far and grasp the relevant calculations (What we did so far). <br>I took a break. Did you? Lets start again! Remember what was our main goal? Calculating true odds. We are close. I promise you.</p><p>So far, we know that each of the home and away team’s scoring chances of 0, 1, 2, 3, 4, 5 goals. Now we have to calculate the chances of home team and away teams draw (0–0, 1–1, 2–2 etc.) and win chances for each of them (like home team’s and aways team’s score 1–0, 2–1, 3–1, 3–2 etc.) We will simply take a dot product of the chances and it will look like below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/760/0*wk_XNS3KpXdLm-CL.png" /></figure><p>Now, think of this as a matrix. The summation upper triangular matrix is the chances of away team’s winning in total, the summation of the diagonal axis is the total chances of draw and the lower triangual matrix is the chances of home team’s winning in total.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/578/0*dIqytS5edQ5q3LI3.png" /></figure><p>For better understanding, I have highlighted the matrix. The green parts is away team’s total chances of winning, the black part is the total chances of draw and the red part is the home teams’s total chances of winning. Close close very close.</p><p>Time to sum up.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/874/0*PJ3cdgNEaPV8MGpH.png" /></figure><p>We did it. Machineball is my website’s name. I am acting like a bookmaker now. 😉💁 . We found out the chances of home match and away match scoring performances. True chances (according to our analysis).</p><p>Time to calculate true odds. Remember odds = (1/ probability). I calculated.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/692/0*I2apsHABfqGN_cJv.png" /></figure><h3>Implied odds vs True odds</h3><p>Machineball home team win odds: 1.61<br>Bookmaker home team win odds: 1.73</p><p>Machineball draw odds: 5.88<br>Bookmaker draw odds: 3.75</p><p>Machineball away team win odds: 6.29<br>Bookmaker home team win odds: 4.75</p><p>They say “In betting, the trick is to find markets in which the bookmaker’s odds are bigger than the true odds, for that is where the value lies.” Did we find anything? Yes, 1.73 &gt; 1.61.</p><h3>Some question and answers 😉</h3><p>Question 1. Shall we bet?<br>Answer: If you can calculate the true odds correctly, and find the above-mentioned situations, you should. Cause long term you win. Mathematics says that. Expert betters say that.</p><p>Question 2. The calculated true odds are true odds?<br>Answer: Our model is very simple. Bookmakers use lots of data, match sentiment, lineups, and complex machine learning algorithms to calculate odds. If you think you are more powerful than them. Go on.</p><h3>Conclusions</h3><p>The above was a general analogy to look at true odds. How the bookmakers set their own odds and how you can calculate your odds. This was one way of thinking and one way of calculation. Make your own assumptions and go. Atleast give it a try. Mathematics is beautiful.</p><p>Last but not the least, the final score of the game was Aston Villa 3–0 Bournemouth.</p><h3>An important note:</h3><p>I want to discuss an important point regarding the true odds calculation. On the 20th of March, 2023 there was a match between Barcelona (The home team) and Real Madrid (the Away team).</p><p>First, try the above calculation for this match by yourself. You know what to do, you have to select all the La Liga matches between those teams before the above-mentioned date and then run the calculation. You will think that this calculation is flawed. Your calculated odds for Barcelona will be something like 1.58, for the draw 3.42 and Real Madrid will be 13.89. No chance the bookmaker will offer you something like 13.89 for Real Madrid. What happened?</p><p>Before looking at my answer try to think by yourself what happened. Maybe, go back to each calculation you made and try to analyse.</p><p>I am telling you what happened. Barcelona at Home scored 27 and conceded only 2 goals. Our calculation includes “average home team goals conceded at home” and this one plays a role in “Home team defensive strength”. Now you know why the calculated odds are so high for Real Madrid. I have done again the analysis with a bias term added to the away team goal expectance and used it as a lambda function of Poisson distribution. The bias is of your choice. Think of the bias as, bias = choice /100, I thought Real Madrid has at least a 50% chance of scoring in this game. So, I added 50/ 100 = 0.5 to away team goal expectance and re-calculated. The re-calculated odds are for Barcelona 2.05, for a draw 3.45 and for Real Madrid 4.55. You can take a look at the analysis <a href="https://github.com/kaii55/Odds_calculation/blob/main/Odds%20calculation%20(Part%20-%202)%20Barcelona%20vs%20Real%20Madrid.ipynb">here</a>.</p><p>In this match, the bookmaker offered Barcelona 2.20, for a draw 3.40 for Real Madrid 3.20. Technically, did we again get some value to place a bet? 😎 Look at the match result 😉</p><p>Link to the post in my website: <a href="https://themachineball.com/blog-details/13">https://themachineball.com/blog-details/13</a><br>Link to the Github for the code: <a href="https://github.com/kaii55/Odds_calculation">https://github.com/kaii55/Odds_calculation</a><br>Link to my website: <a href="https://themachineball.com/">https://themachineball.com</a><br>Link to my twitter: <a href="https://twitter.com/themachineball">https://twitter.com/themachineball</a></p><h3>References:</h3><p>1. <a href="https://www.sonofacorner.com/an-introduction-to-monte-carlo/">Tutorial — 1</a></p><p>2. <a href="https://www.sonofacorner.com/intro-bayesian-modelling-football-1/">Tutorial — 2</a></p><p>3. <a href="https://soccermatics.readthedocs.io/en/latest/gallery/lesson5/plot_simulatematch.html">Soccermatics</a></p><p>4. <a href="https://www.newbettingsites.co/articles/true-odds-vs-implied-odds/">Implied odds vs True odds</a></p><p>5. <a href="https://caanberry.com/maths-behind-betting-odds/">How to think about odds</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bba64852108f" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>