Skip to content

An end-to-end MLOps app which accurately predicts handicap results in the J1 League and optimises the potential return on bets.

License

Notifications You must be signed in to change notification settings

Jack-cky/Wager-Optimiser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

⚽️ Wager Optimiser


Living by the philosophy, "Small bets for entertainment, big bets to become like Li Ka-Shing," sports wagering offers an adrenaline-filled experience. The hook lies in the unpredictable outcome, which keeps the excitement high throughout the match.

Over the decades, we have donated an enormous amount of money to the Hong Kong Jockey Club (HKJC) because of losing bets. Our betting was based on intuition and conviction rather than rigid strategies. With the 2022 FIFA World Cup on the horizon, discussions around strategic betting escalated, leading to the idea of developing machine learning models to predict match outcomes.

Image Credit: Ping Wo Fund

First Published: 26 November 2022
Last Updated: 23 August 2024

Table of Contents

Motivation: Optimise Return on Bets

In our experience, we have found that Asian Handicap is extremely intriguing, yet the harshest option. It levels the playing field between the home and away teams, making it a real challenge to predict the winning side. That being said, dealers usually offer more favourable odds.

Our goal is to make predictions on Asian Handicap, specifically on the J1 League. Wager Optimiser covers an end-to-end machine learning (ML) lifecycle from data gathering to ML model management. By leveraging the power of ML, gamblers worldwide (end users) can easily get betting hints toward the results and optimise return on bets (RoB).

Credit: itspusher@GIPHY

Does it really work?

As of the time of writing, the optimiser has achieved an F1 score of 0.67 in handicap prediction for the 2024 season. Let's say you are betting with HKJC, the average odds are around 1.8. The optimiser recommended betting on 171 games, of which 116 were bingo. The minimum cost was HKD 34,200, and the expected return was HKD 41,760. This results in a RoB of 22.1%. Does it sound appealing?

Caution

Any betting decisions made based on these recommendations are at users' own risk.

Who Are You Going to Bet On?

If you are an addicted gambler, do you dare to bet on Asian Handicap with us? Are you brave enough to bet on a team without analysing any historical data, but putting your trust in the optimiser?

Predict the Next Winner

Simply visit Wager Optimiser on Streamlit Community Cloud and you can find the latest recommended bets.

Tip

Life is too short to regret not betting on Asian Handicap.

Match Summary
Users can select teams for the upcoming match to review their recent performance and the match summary.
Handicap Prediction
Users can input additional match information to request a prediction for the selected match.
Model Training
There are 2 options for model training: (1) training a seasonal model and (2) training a latest model. The seasonal model is trained on a full season of historical results, whereas the latest model is trained on all available records. Because the latest model has the potential to overfit the current season data, its evaluation function is disabled.
Model Evaluation
Users can select up to 5 models to evaluate their performance on the current season. This helps users choose the most high-performing model for prediction.
Model Register
Users can register a model to be used for predictions. This allows users to select a model they want to use for future predictions.

Hosting Your Wager Optimiser

You can host a full version of Wager Optimiser in your preferred environment. The instructions below will guide you through the deployment process. Due to copyright issues, team logos are not bundled within the repository and the Docker image. You might need to source those images by yourself if you wish to fully reproduce the app.

Caution

Any betting decisions made based on these recommendations are at users' own risk.

🐳 Docker Host

The optimiser consists of two parts: a backend server and a frontend server. Docker Compose will help create these containers all at once. Before following the steps, make sure your computer has Docker installed to host the optimiser.

  1. Clone the repository and navigate inside the folder.
    $ git clone https://github.com/Jack-cky/Wager-Optimiser.git
    $ cd Wager-Optimiser/docker
  2. Host the optimiser.
    $ docker compose up -d
☁️ AWS ECS Host (Recommended)

Because H2O has certain hardware requirements, it is recommended to deploy it on a cloud service. Before following the steps, make sure your computer has Terraform installed to provision an ECS service on AWS.

  1. Clone the repository and navigate inside the folder.
    $ git clone https://github.com/Jack-cky/Wager-Optimiser.git
    $ cd Wager-Optimiser/terraform
  2. Update AWS access keys inside main.tf
    access_key = "your_aws_access_key"
    secret_key = "your_aws_secret_key"
    
  3. Initialise a working directory.
    $ terraform init
  4. Create an execution plan for AWS environment.
    $ terraform plan
  5. Provision an ECS to host the optimiser.
    $ terraform apply -auto-approve

Once your deployment is ready, simply visit <ip_address>:8000 for the backend API service and <ip_address>:8501 for the frontend platform.

Solution Architecture

The architecture comprises two components: a frontend server and a backend server. Every week, Football-Data updates leagues match results and odds records in tabular data format.

The backend server downloads the data and processes it for statistics queries and match predictions. There are two ML models trained in the optimiser: (1) the Goal Probability Matrix (GPM) and (2) the Handicap Predictor (HCP). The GPM models are trained using the Poisson model API from statsmodels, while the HCP models are trained using H2O AutoML.

Since the optimiser handles two ML tasks with multiple models, we adopted MLflow to manage the ML experiments and keep track of their performance for each task. After cherry-picking the models, they are served as API endpoints with FastAPI.

The frontend server is a multi-serving platform built with Streamlit. It is used not only for match queries and predictions, but also for managing ML models on the same platform.

Regard Losing Less as Winning

As experienced gamblers, we can state with certainty that no single game outcome is guaranteed. An outstanding team can suddenly underperform when facing a seemingly weaker team (outliers). Likewise, a team's performance can vary dramatically from season to season (data drift). Handling these shifts manually can become burdensome. That's why predicting the handicap necessitates the use of MLOps to alleviate the depressing task of hyperparameter tuning and retraining models on a seasonal basis.

Goal Probability Matrix forecasts the probabilities of correct scores.

The GPM model assumes the number of goals follows a Poisson distribution and formulates the difference as a Skellam distribution. (Credit goes this post for the modelling idea). Theoretically, it models the correct score accurately when teams behave according to a Poisson distribution. We hope this WRONG model could be USEFUL enough to provide gamblers with a high-level insight into their past score distribution.

Handicap Predictor predicts the results of Asian Handicap.

The HCP is a two step model with two steps: (1) predicting which side is winning and (2) deciding whether the game is a confident bet. The first layer learns from the net difference in team properties, such as seasonal rank and scores, while the second layer builds upon the predicted probabilities and the actual result. This design aims to prevent gamblers from betting on uncertain games.

Production Scenario

Suppose you want to deploy the optimiser in an AWS environment. It will be deployed to an ECS to host both the frontend and the backend in a single service. As each team plays a game once a week, running the service for one hour per week is sufficient for prediction and ML model management. This will cost approximately USD 0.35 per month for operation, which can definitely be offset by the RoB. Detailed price calculations can be found on the calculator.

Changelog

[2.0.1] 2024-08-23
Revamped the project for model training process and served models as an API with a user interface.

Added

  • Leveraged MLflow to track model experiments.
  • Hosted the models' API with FastAPI at the backend server.
  • Built a frontend interface using Streamlit to productionise the workflow.

Changed

  • Switched the data source from using TotalCorner to Football-Data.
  • Used H2O AutoML to replace manual model tuning.
[1.0.1] 2022-11-26
Initial publication.

Product Backlog

This project is managed with a product backlog. You can review the backlog to understand the prioritised list of features, changes, enhancements, and bug fixes planned for future development.

License

This project is licensed under the MIT License. See the LICENSE file for details. Feel free to fork and contribute to its further development!

About

An end-to-end MLOps app which accurately predicts handicap results in the J1 League and optimises the potential return on bets.

Topics

Resources

License

Stars

Watchers

Forks