Category Archives: Finances

What are the odds of …. ?

My mind is kind of blown right now. Need to put this into words and write it down. Perhaps others have some input to validate or contradict what I am saying.

I was studying probabilities and going through a topic of binomial distributions. I finished the lectures and went online to see how this information could be useful in the real world. Textbook examples are all about coin flips and I had a hard time relating the information to the real world scenarios. How often do you need to know the probability of tails coming up twice in three flips? Why does this binomial distribution topic matter?

A cursory search brought more coin examples. The real stuff was starting to show through here and there, starting with this article. Yet nothing that I could relate to or apply directly. Until it hit me: binomial distribution could help explain some of the NBA betting behavior I have been seeing! Let me backtrack to how I got there.

Background

I’ve been running an experiment to see if it would be possible to come out cash positive when betting on NBA games using wagering lines provided online. A short answer to that is a “no”: gambling institutions are sophisticated money-making operations that have no interest in losing money to a common man. Yet, the temptation to find an edge is strong, if you combine that with machine learning and stats analysis, one can’t help but try.

For three months now I simulate NBA bets against the real lines and record what happens. The first two months resulted in a negative balance. Last month+ has been positive. My initial approach that was losing money was strictly using a machine learning model I built and I made bets using moneyline odds. It was a good experience in that I learned that favorites in NBA lose much more often than a casual fan realizes. I also learned a ton on how simple ML models won’t cut it against skewed odds that oddsmakers setup against you, simple stab won’t work.

Bad results did not discourage me from experimenting, and I decided to see what would happen if I used the model only as one of the signals, and then relied on my own intuition as I watch the games and keep up with the teams. I no longer did “moneylines” and instead picked “the spread” bets that have payoff anywhere from -115 to -105. I also decided to only bet up to three games per day regardless of the number of matchups in the day. The three game choice was random, but I figured it was a number that forced me to think about the choices harder and pick the games I had the most confidence. With the spread odds, picking two out of three correctly guaranteed a positive night if you bet equal amounts on each game. 66% target rate did not sound too intimidating.

The new strategy has been in place for most of December and all of January. During this time I am winning ~62% of bets and slowly making up for the losses encountered during the first two months. 62% is close to 66% I was hoping to achieve. I track each bet, and the average odds come out to be ~-114. Basically for $10, you win $8.77 ($10 * 1000 / 114). Expected Value with params like this is positive: 0.62 * 8.77 – 0.38 * 10 = 5.43 – 3.8 = 1.63. All of this is assuring. I still can’t explain the winning rate with formula since intuition is a big part of it. This is concerning since I could be just hitting a lucky streak but for now, I am continuing with the approach.

During all of the time that the strategy has been running, I’ve had two questions in the back of my mind. My most common outcome when betting three games has been two wins and one loss. Kind of makes sense since in aggregate I am hitting about 62% win rate. But I wondered “what are the odds of hitting all three correctly? what about two, and one, and zero?”. And also wondered if I should continue to make three bets a day or increase it. I did not spend too much time trying to answer those questions and instead focused on getting better data, etc.

Aha! moment

With all the background info out of the way, here is the big realization of the day: betting on games is exactly where the field of binomial distribution can be applied. The outcome is binary: you either win or lose the bet (I consider push a win). A historical probability of winning is known from your past results, 0.62 in my case. If you expect to maintain this rate, you can calculate the probability of hitting all three, two, one, and zero bets when you make three picks using the binomial distribution formula! Like it or not, you are rolling a weighted dice three times!

Here is the formula for calculating the probability of each specific outcome. Let “n” be the number of bets, “k” be the number of wins, probability of success be Ps then the probability of “k” wins out of “n” bets can be calculated using this formula:

n! / ((n-k)! k!) * (Ps) ^ k * (1-Ps) ^ (n-k)

For my example of 3 picks and 0.62% of success rate:

3! / ((3-k)! k!) * (0.62) ^ k * (0.32) ^ (3-k)

And here are the results:

# of winsprobability
3 wins23.8%
2 wins43.8%
1 win26.8%
0 wins5.5%

Two win outcome is the most probably, no wonder I am seeing it the most! I have hit zero win days, but those are rare, and that fits in line with a 5% according to the probabilities above. I should be seeing three-win days more frequently than I am but I am extremely excited at the moment to know what is expected.

I was happily going through binomial distributions topic for two days, searching for real world examples, and only after a repeated push to find one did I realize that I am living this binomial distribution outcome almost every day for the last three months!

I can now only answer the question if I should stick to three-game bets or increase this further. Let’s set the n=4, what do we get? Here is the new table:

# of winsprobability
4 wins14.7%
3 wins36.2%
2 wins33.3%
1 win13.6%
0 wins2%

In aggregate, I will end up positive for the day only if I win three or four times out of the four picks. Combined probability of that is 50.9%. Compare that with the three-bet approach, where the likelihood of coming out positive for the day is combined probabilities of hitting two and three right, which comes out to 67.6%! Should I increase the number of games I bet? The math says: no.

This realization was hugely helpful in explaining the results I was seeing. It also convinces me to stick with the current approach of three bets. I am still not clear if my 62% hit rate is blind luck or if it’s something sustainable, so I will continue to probe further as I learn and run this experiment.

Predicting sports game outcomes

NBA model performance for the last month

Being a sports fan and someone who uses machine learning, it is just a matter of time before you will attempt to use the skills to predict the outcomes of the sports games. The temptation is too great: alure of making money on the side while bettering your skills combined with working on something that’s interesting outside of writing software is a recipe for action. The number of articles like this is huge. My goal is to share the lessons I learned and offer tips for others that might want to do a similar project in the future.

It was a fall of 2018 and I was a complete newbie when it came to sports wagering. I knew nothing about sports betting, lines, spreads, etc. It was gibberish that I heard on sports podcasts that I found amusing but never really dug in or cared too much about.

The question of “could I build a model that gave accurate predictions” kept on coming back ever since I picked up machine learning two years ago. I’ve built numerous models for work and for play since and I tossed the idea around but never executed on it. It kept on nagging at me until one weekend in the fall of 2018 I decided to jump in.

It took me about two weeks to gather the basic stats and build training database and start building models. I then spent the next two weeks simulating bets against real lines posted online looking for the winning strategies. Basically, a month (I worked on this during the weekends only for the most part) before I settled on a model I liked and evaluated against the real wagering numbers week to week.

Outcome

Let’s me summarize what was accomplished before I dive into details as to how things were done and what was learned:

  • I built an NFL prediction model that predicted 68% of the games correctly for the 2017 season, and 65% for the 2018 season. Not that impressive, some of the models out there that I had seen were achieving 70-73% rate, but good enough to make money if you used it to wager on a certain class of games.
  • I learned a ton about financial modeling and dissected two financial modeling books, treating NFL games like futures one could purchase and sell. I ended up with a system in place that allowed me to experiment with strategies, evaluate the results, graph the outcomes and see what works and does not work.
  • I learned a ton about gambling and how the system is basically very skewed against the gambler, and how gamblers don’t care and go for it anyway. Hey, sometimes you just want to have fun.
  • The final setup that was built was robust enough to be reused in predicting NBA games with similar overall accuracy but not as useful as the NFL model if one tried to use it for wagering.

Again, 65% might not sound that impressive, but the devil is in the details. I had some models that resulted in %69-70 accuracy but were not that useful from a money-making perspective. That’s the beauty of a real-world exercise vs a classroom problem. If you are working on a hypothetical model that will never be used in real world, you will do all kinds of crazy optimizations to achieve the best overall accuracy. But when you go out and try to use it against real-world data that’s available to you, the best accuracy model might not be the one that makes you the most money. More on that later.

Key Lessons learned

  1. As is usually the case, the machine learning part was a small part of the project. The amount of time spent on model type selection, feature selection, and training is small compared to the time you have to spend on gathering the data, setting up systems to fetch the results automatically, pre-processing it to fit your model needs, and the amount of time you spend on looking for winning strategies.
  2. You can’t predict randomness and searching for perfect accuracy is a futile attempt that probably ruins many that attempt this exercise. I could have spent time in trying to optimize the model and gather more data to perhaps bring up the model accuracy to the %70+ range but settled on something that was good enough to give me %28 profit if the money was spent on real wagering lines.
  3. Evaluate, evaluate, and evaluate your strategies. After using the model for the 2018 season and looking back at the results, I have a feeling I got lucky and should spend more time on the evaluation of my model and more plotting of its pasts results that would give me more confidence of its performance. I went with a bit of blind faith and gut feeling that the model was good enough but retroactively was able to prove out that indeed it was good enough.
  4. Reading financial machine learning books gave good ideas in the system setup and evaluation. “Building Winning Algorithmic Trading Systems” was fantastic in that regard, and the same can be said about “Advances in Financial Machine Learning“.

Future Posts

I want to dive in deeper into how things were done and some key ideas that were used in building a system to predict the games. In the next coming weeks, I will publish more details about the process that was used to build the model. Then will dive into the model evaluation, the most critical step, if you ask me and then share more lessons and tidbits of knowledge gathered. Depending on how much data I have gathered by then, will also share the results of the system and how it is doing for NBA game predictions.

Book Review: The Richest Man in Babylon

Rating: 4 stars.

Amazon Link

I wish I had read this book sooner.  I found it very useful, despite its unusual, parable-like, story style. The stories teach the reader how to achieve financial success. Even though the setting is ancient times, the advice conveyed is very practical and applies today as well.

When we think about “financial success,” we often think of immediate and big gains: stocks that multiple overnight, big payday, bonus, etc. The reality is quite different: financial success comes to those that work hard and smart, plan for it, and then take patient and steady approach.

The book, which was written in the 1920s by an American author, shares stories that are mostly about a wise man Arkad and how he achieved financial wellness.

Arkad’s main rules are simple:

  • Save 10% of your income

  • Spend less than you earn, after you put away that 10%

  • Once you have a nice amount of money saved up, don’t keep it idle but instead make it work for you. i.e., invest it somewhere so it earns money.

  • Invest it wisely, don’t invest in the areas you don’t understand without an expert guiding your way. Make sure you can get the principal back safely.

  • Own the place you live in, i.e., don’t pay rent

  • Insure your life, your earnings where applicable

  • Increase your capacity to earn by acquiring skills and knowledge.

Now you could argue with some of the points here, but the principles in general are very sound. Save part your income, don’t spend lavishly, then start investing and get back principal AND interest, while keeping insurance around and all the time seeking for ways to improve your ability to earn. Can’t go wrong with that.

Some of the other things that caught my eye were around how you go about saving money. When you start to save, don’t go crazy and frugal to the max, just make sure you start with 10% savings, and that’s a good enough start.

However do analyze your spending and see if there are expenses there that can be cut (but again, within reason). Sometimes we forget subscriptions/services that we keep, and perhaps those can be avoided.

And one of my favorite: “Opportunity is a haughty goddess who wastes no time with those who are unprepared.” When the opportunity comes, those that take it benefit, and to take it you have to be ready – you just never know when it will come.