Title: | Weighted and Standard Elo Rates |
---|---|
Description: | Estimates the standard and weighted Elo (WElo, Angelini et al., 2022 <doi:10.1016/j.ejor.2021.04.011>) rates. The current version provides Elo and WElo rates for tennis, according to different systems of weights (games or sets) and scale factors (constant, proportional to the number of matches, with more weight on Grand Slam matches or matches played on a specific surface). Moreover, the package gives the possibility of estimating the (bootstrap) standard errors for the rates. Finally, the package includes betting functions that automatically select the matches on which place a bet. |
Authors: | Vincenzo Candila [aut, cre] |
Maintainer: | Vincenzo Candila <[email protected]> |
License: | GPL-3 |
Version: | 0.1.4 |
Built: | 2024-11-15 06:29:02 UTC |
Source: | CRAN |
Tennis data for male matches played in 2019. Details can be found on http://www.tennis-data.co.uk/notes.txt
data(atp_2019)
data(atp_2019)
An object of class "data.frame"
.
Tennis archive from http://www.tennis-data.co.uk/
head(atp_2019) str(atp_2019)
head(atp_2019) str(atp_2019)
Places bets using the WElo and Elo probabilities, on the basis of two thresholds and
, according to Angelini et al. (2022).
By default, the amount of $1 is placed on the best odds (that is, the highest odds available) for player
for all
the matches where it holds that
where is the estimated probability (coming from the WElo or Elo model) that player
wins the match
against player
and
is its implied probability obtained as the reciprical of the Bet365 odds. The implied
probability
is assumed to be greater than
. If
, all the players are considered. If
increases,
heavy longshot players are excluded.
In general, higher thresholds
and
imply less betting opportunities.
betting( x, r, q, model, bets = "Best_odds", R = 2000, alpha = 0.1, start_oos = NULL, end_oos = NULL )
betting( x, r, q, model, bets = "Best_odds", R = 2000, alpha = 0.1, start_oos = NULL, end_oos = NULL )
x |
an object of class 'welo', obtained from the |
r |
Vector or scalar identifying the threshold of the ratio between the estimated and the implied probability (see above) |
q |
Scalar parameter used to exclude the heavy underdogs signalled by Bet365 bookmaker.
No bets will be placed on those matches where players have implied probabilities smaller than |
model |
Valid choices are: "WELO" and "ELO" |
bets |
optional Parameter identifying on which type of odds the bet is placed. Default to "Best_odds". Valid choices are: "Best_odds", "Avg_odds" and "B365_odds". "Best_odds" are the highest odds available. "Avg_odds" are the average odds for that match and "B365_odds" are the Bet365 odds |
R |
optional Number of bootstrap replicates to calculate the confidence intervals. Default to 2000 |
alpha |
optional Significance level for the boostrap confidence intervals. Default to 0.1 |
start_oos |
optional Character parameter denoting the starting year for the bets. If included (default to NULL), then the bets will be placed on matches starting in that year. It has to be formatted as "YYYY" |
end_oos |
optional Character parameter denoting the ending year for the bets. If included (default to NULL), then the bets will be placed on matches included in the period "start_oos/end_oos". It has to be formatted as "YYYY" |
A matrix including the number of bets placed, the Return-on-Investiment (ROI), expressed in percentage, and its boostrap confidence interval,
calculated using replicates and the significance level
.
data(atp_2019) db_clean<-clean(atp_2019) db_est<-welofit(db_clean) bets<-betting(db_est,r=c(1.1,1.2,1.3),q=0.3,model="WELO") bets
data(atp_2019) db_clean<-clean(atp_2019) db_est<-welofit(db_clean) bets<-betting(db_est,r=c(1.1,1.2,1.3),q=0.3,model="WELO") bets
Cleans the dataset in order to create a suitable data.frame ready to be used in the welofit
function.
clean(x, MNM = 10, MRANK = 500)
clean(x, MNM = 10, MRANK = 500)
x |
Data to be cleaned. It must be a data.frame coming from http://www.tennis-data.co.uk/. |
MNM |
optional Minimum number of matches played by each player to include in the cleaned dataset. Default to 10. This means that each player has to play at least 10 matches |
MRANK |
optional Maximum rank of the players to consider. Default to 500. This means that all the matches with players with ranks greater than 500 are dropped |
The cleaning operations are:
Remove all the uncompleted matches;
Remove all the NAs from B365 odds;
Remove all the NAs from the variable "ranking";
Remove all the NAs from the variable "games";
Remove all the NAs from the variable "sets";
Remove all the matches where the B365 odds are equal;
Define players and
and their outcomes (
and
);
Remove all the matches of players who played less than MNM matches;
Remove all the matches of players with rank greater than MRANK;
Sort the matches by date.
Data.frame cleaned
data(atp_2019) db_clean<-clean(atp_2019) str(db_clean)
data(atp_2019) db_clean<-clean(atp_2019) str(db_clean)
Places bets on players and
randomly chosen, among all the matches selected by
the following strategy:
by default, the amount of $1 is placed on the best odds (that is, the highest odds available) for player
for all
the matches where it holds that
where is the estimated probability (coming from the WElo or Elo model) that player
wins the match
against player
and
is its implied probability obtained as the reciprical of the Bet365 odds. The implied
probability
is assumed to be greater than
. If
, all the players are considered. If
increases,
heavy longshot players are excluded.
Once got the number of matches satisfying the previously described strategy, each player (
and
) on which
place a bet is randomly selected. Then the Return-on-Investiment (ROI) of this strategy is stored. Finally, the mean of the ROI
obtained from repeating this operation
times is reported.
random_betting( x, r, q, model, bets = "Best_odds", B = 10000, start_oos = NULL, end_oos = NULL )
random_betting( x, r, q, model, bets = "Best_odds", B = 10000, start_oos = NULL, end_oos = NULL )
x |
an object of class 'welo', obtained from the |
r |
Vector or scalar identifying the threshold of the ratio between the estimated and the implied probability (see above) |
q |
Scalar parameter used to exclude the heavy underdogs signalled by B365 bookmaker.
No bets will be placed on those matches where players have odds smaller than |
model |
Valid choices are: "WELO" and "ELO" |
bets |
optional Parameter identifying on which type of odds the bet is placed. Default to "Best_odds". Valid choices are: "Best_odds", "Avg_odds" and "B365_odds". "Best_odds" are the highest odds available. "Avg_odds" are the average odds and "B365_odds" are the Bet365 odds |
B |
optional Number of replicates to calculate the overall mean ROI. Default to 10000 |
start_oos |
optional Character parameter denoting the starting year for the bets. If included (default to NULL), then the bets will be placed on matches starting in that year. It has to be formatted as "YYYY" |
end_oos |
optional Character parameter denoting the ending year for the bets. If included (default to NULL), then the bets will be placed on matches included in the period "start_oos/end_oos". It has to be formatted as "YYYY" |
A matrix reporting the number of bets and the mean of the ROI (in percentage) across the values for every
threshold r used
data(atp_2019) db_clean<-clean(atp_2019) db_est<-welofit(db_clean) rand_bets<-random_betting(db_est,r=c(1.1,1.2,1.3),q=0.3,model="WELO",B=1000) rand_bets
data(atp_2019) db_clean<-clean(atp_2019) db_est<-welofit(db_clean) rand_bets<-random_betting(db_est,r=c(1.1,1.2,1.3),q=0.3,model="WELO",B=1000) rand_bets
Plots the official (ATP or WTA) rates.
rank_plot(x, players, line_width = 1.5, nbreaks = 1)
rank_plot(x, players, line_width = 1.5, nbreaks = 1)
x |
An object of class 'welo', obtained after running the |
players |
A character vector including the players whose rates will be plotted. The indication of the player has to be: 'Surname N.'. For instance, 'Roger Federer' will be included in the 'players' vector as 'Federer R.' |
line_width |
optional Line width, by default it is 1.5 |
nbreaks |
optional Number of breaks for y-axis, by default it is 1 |
A ggplot2 plot
db<-tennis_data("2022","ATP") db_clean<-clean(db,MNM=5) res_welo<-welofit(db_clean) players<-c("Nadal R.","Djokovic N.","Berrettini M.","Sinner J.") rank_plot(res_welo,players,line_width=1.5)
db<-tennis_data("2022","ATP") db_clean<-clean(db,MNM=5) res_welo<-welofit(db_clean) players<-c("Nadal R.","Djokovic N.","Berrettini M.","Sinner J.") rank_plot(res_welo,players,line_width=1.5)
Imports ATP or WTA data from the site http://www.tennis-data.co.uk/
tennis_data(YEAR, Circuit)
tennis_data(YEAR, Circuit)
YEAR |
Year to consider, in "YYYY" format. Only years from 2013 onwards are allowed |
Circuit |
Valid choices for Circuit are: "ATP" or "WTA" |
Data.frame for the YEAR and Circuit specified
db<-tennis_data("2022","ATP") head(db)
db<-tennis_data("2022","ATP") head(db)
Calculates the probability that player wins over player
for match at time
using the WElo or Elo rates at time
. Formally:
where and
are the WElo or Elo rates at time
.
tennis_prob(i, j)
tennis_prob(i, j)
i |
WElo or Elo rates for player |
j |
WElo or Elo rates for player |
Probability that player wins the match against player
tennis_prob(2000,2000) tennis_prob(2500,2000)
tennis_prob(2000,2000) tennis_prob(2500,2000)
Plots WElo and Elo rates.
welo_plot(x, players, rates = "WElo", SP = 1500, line_width = 1.5)
welo_plot(x, players, rates = "WElo", SP = 1500, line_width = 1.5)
x |
An object of class 'welo', obtained after running the |
players |
A character vector including the players whose rates will be plotted. The indication of the player has to be: 'Surname N.'. For instance, 'Roger Federer' will be included in the 'players' vector as 'Federer R.' |
rates |
optional Rates to be plotted. Valid choices are 'WElo' (by default) and 'Elo' |
SP |
optional Starting points from which the rates originate. By default, SP is 1500 |
line_width |
optional Line width, by default it is 1.5 |
A ggplot2 plot
db<-tennis_data("2022","ATP") db_clean<-clean(db,MNM=5) res_welo<-welofit(db_clean) players<-c("Nadal R.","Djokovic N.","Berrettini M.","Sinner J.") welo_plot(res_welo,players,rates="WElo",SP=1500,line_width=1.5)
db<-tennis_data("2022","ATP") db_clean<-clean(db,MNM=5) res_welo<-welofit(db_clean) players<-c("Nadal R.","Djokovic N.","Berrettini M.","Sinner J.") welo_plot(res_welo,players,rates="WElo",SP=1500,line_width=1.5)
Calculates the WElo and Elo rates according to Angelini et al. (2022). In particular, the Elo updating system
defines the rates (for player ) as:
where is the Elo rate at time
,
is the outcome (1 or 0) for player
in the match at time
,
is a scale factor, and
is the probability of winning for match at time
, calculated using
tennis_prob
.
The scale factor determines how much the rates change over time. By default, according to Kovalchik (2016), it is defined as
where is the number of matches disputed by player
up to time
. Alternately,
can be multiplied by 1.1 if
the match at time
is a Grand Slam match or is played on a given surface. Finally, it can be fixed to a constant value.
The WElo rating system is defined as:
where denotes the WElo rate for player
,
the probability of winning using
tennis_prob
and
the WElo rates, and represents a function whose values depend on the games (by default) or sets won in the previous match.
In particular, when parameter 'W' is set to "GAMES",
is defined as:
where and
represent the number of games won by player
and player
in match
, respectively.
When parameter 'W' is set to "SET",
is:
where and
represent the number of sets won by player
and player
in match
, respectively.
The scale factor
is the same as the Elo model.
welofit( x, W = "GAMES", SP = 1500, K = "Kovalchik", CI = FALSE, alpha = 0.05, B = 1000, new_data = NULL )
welofit( x, W = "GAMES", SP = 1500, K = "Kovalchik", CI = FALSE, alpha = 0.05, B = 1000, new_data = NULL )
x |
Data cleaned through the function |
W |
optional Weights to use for the WElo rating system. Valid choices are: "GAMES" (by default) and "SETS" |
SP |
optional Starting points for calculating the rates. 1500 by default |
K |
optional Scale factor determining how much the WElo and Elo rates change over time. Valid choices are:
"Kovalchik" (by default), "Grand_Slam", "Surface_Hard", "Surface_Grass", "Surface_Clay" and, finally, a constant value |
CI |
optional Confidence intervals for the WElo and Elo rates. Default to FALSE. If 'CI' is set to "TRUE", then the confidence intervals are calculated, according to the procedure explained by Angelini et al. (2022) |
alpha |
optional Significance level of the confidence interval. Default to 0.05 |
B |
optional Number of bootstrap samples used to calculate the confidence intervals. Default to 1000 |
new_data |
optional New data, cleaned through the function |
welofit
returns an object of class 'welo', which is a list containing the following components:
results: The data.frame including a variety of variables, among which there are the estimated WElo and Elo rates, before and
after the match , for players
and
,
the lower and upper confidence intervals (if CI=TRUE) for the WElo and Elo rates, labelled as '_lb' and '_ub', respectively, and the probability of winning the match for player
(labelled as 'WElo_pi_hat' and
'Elo_pi_hat', respectively, for the WElo and Elo models).
matches: The number of matches analyzed.
period: The sample period considered.
loss: The Brier score (Brier 1950) and log-loss (used by Kovalchik (2016), among others) averages, calculated considering the distance with respect to the outcome of the match.
highest_welo: The player with the highest WElo rate and the relative date.
highest_elo: The player with the highest Elo rate and the relative date.
dataset: The dataset used for the estimation of the WElo and Elo rates.
Angelini G, Candila V, De Angelis L (2022).
“Weighted Elo rating for tennis match predictions.”
European Journal of Operational Research, 297(1), 120–132.
Brier GW (1950).
“Verification of forecasts expressed in terms of probability.”
Monthly weather review, 78(1), 1–3.
Kovalchik SA (2016).
“Searching for the GOAT of tennis win prediction.”
Journal of Quantitative Analysis in Sports, 12(3), 127–138.
data(atp_2019) db_clean<-clean(atp_2019) res<-welofit(db_clean) # append new data db_clean_1<-db_clean[1:500,] db_clean_2<-db_clean[501:1200,] res_1<-welofit(db_clean_1) res_2<-welofit(res_1,new_data=db_clean_2)
data(atp_2019) db_clean<-clean(atp_2019) res<-welofit(db_clean) # append new data db_clean_1<-db_clean[1:500,] db_clean_2<-db_clean[501:1200,] res_1<-welofit(db_clean_1) res_2<-welofit(res_1,new_data=db_clean_2)
Tennis data for female matches played in 2019. Details can be found on http://www.tennis-data.co.uk/notes.txt
data(wta_2019)
data(wta_2019)
An object of class "data.frame"
.
Tennis archive from http://www.tennis-data.co.uk/
head(wta_2019) str(wta_2019)
head(wta_2019) str(wta_2019)