Team strength assessment based on statistics (building your own ELO rating)

What is the Elo rating in sports and how to assess the strength of teams using it

The Elo rating is a statistical model that allows for a quantitative assessment of a team’s strength based on the results of its matches. Originally, the method was developed for chess, but today it is actively adapted for football, hockey, basketball, tennis, and other sports. Unlike a regular tournament table, which only takes into account the number of points scored, Elo reflects the actual form of the team considering the strength of opponents, the venue of the match, and the dynamics of results.

The main idea is simple: each team has a numerical rating. Before the match, the expected result is calculated — the probability of winning, drawing, or losing. If the club performs better than expected (for example, defeating a stronger opponent away), its rating increases more significantly. Conversely, if the favorite unexpectedly loses, it loses a significant portion of points, while the outsider gains a meaningful increase. This way, the Elo rating quickly responds to changes in form and becomes a convenient tool for analytics and modeling.

In sports, Elo is used for various tasks: from building internal club metrics and media ratings to algorithms for predicting outcomes and comparing one’s own assessments with bookmaker lines. With detailed data available API de eventos deportivos calculations can be automated and fresh rankings can be maintained for hundreds of tournaments and thousands of teams in various sports, updating them immediately after each match ends.

How to build your own Elo rating for sports teams based on match statistics

Building your own Elo rating starts with defining the basic parameters of the model. First, the starting rating values for all teams are set (for example, the same level at the beginning of the season or inheriting the rating from the previous year). Next, the model’s sensitivity coefficient is chosen. K-factor: the higher it is, the stronger the rating jumps will be after each match. For stable tournaments (for example, national leagues), more moderate values are usually taken, while for youth or fast esports leagues, the coefficient can be increased.

Then it is necessary to determine how exactly the match statistics will affect the calculation. Basic Elo relies on the final result (win, draw, loss), but in team sports, modifiers can be added: goal or puck difference, home field advantage, importance of the tournament, or playoff stage. For example, a large victory of 5:0 may bring slightly more points than a minimal victory of 1:0, while success in the final will weigh more than a mid-season match. All these parameters are set at the level of your business logic and are easily scalable if you have structured data on matches.

By using statistics from a sports API, you can go even further and incorporate additional factors into the model: expected goals (xG, if available in the source), number of shots, possession, quality of the opponent based on your own rating. In practice, this transforms Elo from a «just a rating» into a flexible system for assessing team strength that adapts to your niche: media projects, analytical services, recommendation systems for betting, or internal BI analytics for clubs and leagues.

Which sports event APIs to use for calculating the Elo rating

A reliable source of match data is required for a full Elo rating calculation: who played against whom, when, with what score, in which tournament, and at what stage. All this data is centrally available through por el API de eventos deportivos api-sport.ru, which supports football, hockey, basketball, tennis, table tennis, esports, and other disciplines. One API is enough to build a unified rating calculation pipeline for different sports.

The basis for the model is the match endpoints. Through the method /v2/{sportSlug}/partidos you get a list of games with filters by date, tournament, season, team, and status (completed, live, scheduled). The field puntajeLocal и puntajeVisitante allows you to extract the final score, and the attributes of the tournament and season help to set different weights in the Elo formula. If necessary, you can additionally refer to the methods of the tournament structure /v2/{sportSlug}/torneo/{tournamentId} и /v2/{sportSlug}/torneo/{tournamentId}/temporadas, to build separate rankings by leagues, countries, or types of competitions.

A separate advantage of the API api-sport.ru is the availability of bookmaker data. The match object includes a field oddsBase with markets and odds, which allows you to compare your Elo rating with market expectations and calibrate the model to real lines. This approach is especially useful for betting services and analytical platforms that build value models and want to understand in which matches their strength assessments significantly diverge from bookmaker odds.

curl "https://api.api-sport.ru/v2/football/matches?date=2025-09-03&tournament_id=7" \
  -H "Authorization: YOUR_API_KEY" | jq '.matches[] | {id, homeTeam: .homeTeam.name, awayTeam: .awayTeam.name, homeScore, awayScore}'

How to obtain match statistics via API to update the Elo rating

To keep the Elo rating always up to date, it needs to be updated promptly after each completed match. In the API api-sport.ru, this can be conveniently done through the method /v2/{sportSlug}/partidos with a filter by status and date. For example, you can request all matches with the status completado for the current day every few minutes and process only new events. Thanks to the fields homeScore.current и awayScore.current one request is enough to get the final score and immediately recalculate the teams’ ratings.

For more advanced Elo models, a field will be useful estadísticasDelPartido, where detailed metrics on ball possession, shots, xG-like statistics, duels, and other metrics are contained. This data allows for the construction of «extended Elo,» where not only the result but also the quality of play is taken into account. Together with historical data from seasons, you get a stable foundation for long-term analytics and the construction of complex strength metrics.

Access to the data is possible from any stack: Python, PHP, Node.js, Go, etc. Below is a simple example in Python that shows how to retrieve past football matches for a specified date and prepare them for further Elo calculation. An API key can be obtained at tu cuenta personal en api-sport.ru and passed in the header Autorización.

import requests
API_KEY = "YOUR_API_KEY"
BASE_URL = "https://api.api-sport.ru/v2/football/matches"
params = {
    "date": "2025-09-03",
    "status": "finished"
}
response = requests.get(
    BASE_URL,
    headers={"Authorization": API_KEY},
    params=params,
    timeout=10
)
response.raise_for_status()
data = response.json()
for match in data.get("matches", []):
    home = match["homeTeam"]["name"]
    away = match["awayTeam"]["name"]
    home_goals = match["homeScore"]["current"]
    away_goals = match["awayScore"]["current"]
    # Здесь вы вызываете свою функцию пересчёта Elo
    # update_elo(home, away, home_goals, away_goals)

Example of calculating and updating the Elo rating based on API data

The classic Elo formula for team sports is built around the expected result and the actual outcome of the match. Let the home and away teams have ratings R_home и R_away. First, the expected share of points for the hosts is calculated: E_home = 1 / (1 + 10 ** ((R_away - R_home) / 400)). Similarly, the expectation for the guests is determined E_away = 1 - E_home. The actual result is then encoded as 1 for a win, 0.5 for a draw, and 0 for a loss.

After that, we apply the update formula: R_new = R_old + K * (S - E), where K — the model’s sensitivity coefficient, S — the actual result (1 / 0.5 / 0), E — the expected result. In practical implementations, this formula often includes adjustments: a bonus for a large score difference, an increase for an away win, a decrease for friendly matches, and an increase for playoffs. All these parameters can be conveniently stored in a configuration and applied when processing data obtained from the API.

Below is a simplified example of a function in Python that takes the current team ratings and the match result (based on data from /v2/{sportSlug}/partidos) and returns the updated Elo values. Such a block can be easily integrated into a pipeline that automatically processes all completed games and maintains an up-to-date rating for hundreds of teams.

import math
def update_elo(home_rating, away_rating, home_goals, away_goals, k=20):
    # Фактический результат
    if home_goals > away_goals:
        s_home, s_away = 1.0, 0.0
    elif home_goals < away_goals:
        s_home, s_away = 0.0, 1.0
    else:
        s_home, s_away = 0.5, 0.5
    # Ожидания по формуле Elo
    e_home = 1 / (1 + 10 ** ((away_rating - home_rating) / 400))
    e_away = 1 - e_home
    # Обновление рейтингов
    new_home = home_rating + k * (s_home - e_home)
    new_away = away_rating + k * (s_away - e_away)
    return new_home, new_away
# Пример использования с данными из API
# new_home, new_away = update_elo(r_home, r_away, home_goals, away_goals)

Automating the recalculation of the Elo rating in Python using a sports API

When the rating formula is defined, the next logical step is to automate the entire process: from obtaining data from the API to saving the updated Elo in the database or cache. In practice, this is implemented as a periodic script or a small service that queries /v2/{sportSlug}/partidos, finds new completed matches, recalculates ratings for the involved teams, and records the results. This approach allows using Elo in real-time in applications, recommendation systems, and betting algorithms.

Thanks to the unified data format in the API api-sport.ru, the same code can be easily adapted for different sports: just change sportSlug (for example, from fútbol to baloncesto or hockey sobre hielo) and, if necessary, adjust the coefficients in the model. In the future, the emergence of a WebSocket interface and AI tools on api-sport.ru will allow updating ratings not only after the match ends but also in live mode, reacting to important events and changes in coefficients.

Below is an example of a basic pipeline in Python: the script retrieves all completed matches for the day, stores team ratings in a dictionary, and recalculates them as it processes the games. In a real project, you can replace the dictionary with a database and API calls with a task queue or cloud function, but the basic logic will remain the same.

import requests
API_KEY = "YOUR_API_KEY"
SPORT = "football"  # football, basketball, ice-hockey, tennis, esports
BASE_URL = f"https://api.api-sport.ru/v2/{SPORT}/matches"
ratings = {}  # team_id -> elo
def get_team_rating(team_id, default=1500):
    return ratings.get(team_id, default)

def set_team_rating(team_id, value):
    ratings[team_id] = value

def fetch_finished_matches(date):
    resp = requests.get(
        BASE_URL,
        headers={"Authorization": API_KEY},
        params={"date": date, "status": "finished"},
        timeout=15,
    )
    resp.raise_for_status()
    return resp.json().get("matches", [])

for match in fetch_finished_matches("2025-09-03"):
    home_id = match["homeTeam"]["id"]
    away_id = match["awayTeam"]["id"]
    home_goals = match["homeScore"]["current"]
    away_goals = match["awayScore"]["current"]
    r_home = get_team_rating(home_id)
    r_away = get_team_rating(away_id)
    new_home, new_away = update_elo(r_home, r_away, home_goals, away_goals, k=20)
    set_team_rating(home_id, new_home)
    set_team_rating(away_id, new_away)
# На этом этапе словарь ratings содержит обновлённый рейтинг Elo для всех участвовавших команд

How to apply the Elo rating for predicting the outcomes of sports matches

Once the Elo rating is consistently calculated and updated, it can be used as a basis for predicting match outcomes. The difference in team ratings is directly converted into probabilities of winning, drawing, and losing through a logistic function. For example, knowing R_home и R_away, you get the expected probability of the home team winning and based on it, you build your own «line» on the outcomes. By comparing these probabilities with the actual odds from bookmakers, it is easy to find overvalued and undervalued teams.

Integration with the bookmaker’s API and field oddsBase in these matches allows you to automatically pull up current odds and match them with your estimates. If your model believes that a team should win in 60% cases, while the market gives odds equivalent to a 50% probability, this is a potential value point. This approach works well in football and hockey, as well as in basketball, tennis, and esports, where Elo accurately reflects the relative strength of participants with sufficient statistical volume.

Based on the data from api-sport.ru you can build entire ecosystems: recommendation services for betting, dashboards for Telegram and web bots, internal scouting and analytics systems for clubs. With the emergence of WebSocket connections and AI tools, it will become possible to conduct dynamic recalibration of ratings during the match and build more complex live prediction models that use not only the outcome of the game but also streaming statistics, changes in odds, and key game events.