Evaluate an NFL model against the closing line in Python
Build an Elo model, turn closing moneylines into probabilities and score both with log loss and Brier on 815 held-out games, with the gap and its interval.
Every script run against the live API on December 4, 2026. One full run: 85 credits.
The closing line is the market's last forecast before kickoff, and a good benchmark for any model that predicts who wins. This tutorial builds a simple model, converts the closing moneylines into probabilities, and scores both on games the model had not seen. It is an evaluation, not a strategy: the question is how close a forecast gets to the market's, and the answer here is that a plain Elo model is clearly behind it.
The data is every regular-season game from 2010 to 2025 (4,175 games, every one with a closing moneyline). The model is an Elo rating that learns game by game, so every probability is made before that game is played. It is scored on 2023 to 2025. One full run costs 85 credits: 16 calls to get_games, one per season, and one get_game_probabilities call to check the conversion.
1. Install the client and set your key
The client has no required dependencies. This tutorial uses pandas and numpy for the maths and matplotlib for the chart. The client reads your key from ENDZONEAPI_API_KEY.
pip install "endzoneapi[pandas]" numpy matplotlib
export ENDZONEAPI_API_KEY=your_key_here2. Pull 16 seasons of results and closing moneylines
One get_games call returns a whole season with limit=500. status="FINAL" leaves out games not yet played. Moneylines are on every game from 2010, which is why the file starts there.
import pandas as pd
from endzoneapi import Client, to_dataframe
client = Client() # reads ENDZONEAPI_API_KEY
frames = []
for season in range(2010, 2026):
games = client.get_games(season=season, game_type="REG", status="FINAL", limit=500)
frames.append(to_dataframe(games, key="games"))
df = pd.concat(frames, ignore_index=True)
cols = ["game_id", "season", "week", "gameday", "away_team", "home_team", "home_score", "away_score",
"result", "spread_line", "home_moneyline", "away_moneyline"]
df = df[cols].sort_values(["season", "week", "gameday", "game_id"]).reset_index(drop=True)
df.to_csv("nfl_2010_2025_final.csv", index=False)
print(len(df), "games,", df["home_moneyline"].notna().sum(), "with a closing moneyline")
print((df["result"] == 0).sum(), "ties")
print("credits left:", client.last_credits_remaining)Output
4175 games, 4175 with a closing moneyline
13 ties
credits left: 1002The last line is the credit balance of the key that ran it; yours will differ. The 13 ties have no winner and are left out of scoring, which leaves 4,162 games.
3. Turn the closing line into a probability and fit a model
Two forecasts get scored, plus a baseline.
- Closing line. An American moneyline is an implied probability with the book's margin in it. The two sides sum to more than 1, so the script scales them to sum to 1. That is the no-margin probability that the home team wins.
- Elo model. Each team starts at 1500. Before a game the model turns the rating gap, plus a home-field bonus, into a win probability and records it. After the game it moves both ratings by the result, more for bigger margins. Between seasons ratings shrink one third of the way back to 1500.
- Baseline. The home team's win rate before 2023, for every game.
import numpy as np
import pandas as pd
df = pd.read_csv("nfl_2010_2025_final.csv")
df = df[df["result"] != 0].reset_index(drop=True) # ties have no winner
df["home_win"] = (df["result"] > 0).astype(int)
def implied(ml):
"""American odds to implied probability, margin included."""
return np.where(ml < 0, -ml / (-ml + 100), 100 / (ml + 100))
# Closing line: remove the margin by scaling the two implied probabilities to sum to 1.
home_imp, away_imp = implied(df["home_moneyline"]), implied(df["away_moneyline"])
df["p_close"] = home_imp / (home_imp + away_imp)
# Model: Elo with a home-field bonus, a margin-of-victory multiplier and a pull toward 1500 each season.
K, HOME, REGRESS = 20.0, 48.0, 1 / 3
rating, season, p_model = {}, None, []
for row in df.itertuples():
if row.season != season:
rating = {t: 1500 + (r - 1500) * (1 - REGRESS) for t, r in rating.items()}
season = row.season
elo_h, elo_a = rating.get(row.home_team, 1500.0), rating.get(row.away_team, 1500.0)
diff = elo_h + HOME - elo_a
p = 1 / (1 + 10 ** (-diff / 400))
p_model.append(p) # recorded before the game is played
winner_diff = diff if row.home_win else -diff
mult = np.log(abs(row.result) + 1) * 2.2 / (winner_diff * 0.001 + 2.2)
delta = K * mult * (row.home_win - p)
rating[row.home_team] = elo_h + delta
rating[row.away_team] = elo_a - delta
df["p_model"] = p_model
# Baseline: the home team's win rate in the seasons before the test window.
df["p_base"] = df[df["season"] < 2023]["home_win"].mean()
df.to_csv("nfl_forecasts.csv", index=False)
print(df[["p_model", "p_close", "p_base"]].describe().loc[["count", "mean", "min", "max"]].round(3).to_string())Output
p_model p_close p_base
count 4162.000 4162.000 4162.000
mean 0.562 0.560 0.557
min 0.097 0.088 0.557
max 0.948 0.957 0.557All three forecasts cover the same 4,162 games. The baseline is one number, 0.557, the share of games the home team won before 2023.
4. Score both on the games the model had not seen
Log loss punishes a confident wrong forecast hard and is the usual score for a probability; lower is better. The Brier score is the mean squared error of the probability. The test window is 2023 to 2025, 815 games. Because the Elo ratings are updated one game at a time and each probability is recorded before its game, nothing in the 2023 to 2025 forecasts used those results. The script also puts an interval on the gap between the two forecasts: the average per-game difference in log loss, with a 95% interval from its standard error.
import numpy as np
import pandas as pd
df = pd.read_csv("nfl_forecasts.csv")
test = df[df["season"] >= 2023].copy()
test["y"] = test["home_win"]
def log_loss(p, y):
p = np.clip(p, 1e-6, 1 - 1e-6)
return -(y * np.log(p) + (1 - y) * np.log(1 - p))
for col in ["p_base", "p_model", "p_close"]:
test["ll_" + col[2:]] = log_loss(test[col], test["y"])
test["bs_" + col[2:]] = (test[col] - test["y"]) ** 2
summary = pd.DataFrame({
"log_loss": test[["ll_base", "ll_model", "ll_close"]].mean().values,
"brier": test[["bs_base", "bs_model", "bs_close"]].mean().values,
}, index=["Constant home rate", "Elo model", "Closing line"])
print(len(test), "games from 2023 to 2025")
print(summary.round(4).to_string())
gap = test["ll_model"] - test["ll_close"]
se = gap.std() / np.sqrt(len(gap))
print(f"model minus closing line, log loss per game: {gap.mean():.4f} (95% interval {gap.mean() - 1.96 * se:.4f} to {gap.mean() + 1.96 * se:.4f})")
print(test.groupby("season")[["ll_model", "ll_close"]].mean().round(4).to_string())Output
815 games from 2023 to 2025
log_loss brier
Constant home rate 0.6900 0.2484
Elo model 0.6375 0.2232
Closing line 0.6081 0.2103
model minus closing line, log loss per game: 0.0295 (95% interval 0.0152 to 0.0438)
ll_model ll_close
season
2023 0.6620 0.6273
2024 0.6125 0.5875
2025 0.6382 0.6094- Elo model
- Closing line
815 held-out games, 2023 to 2025. The closing line scored better in each season.
How to read it:
- Scores. The Elo model's log loss is 0.638, against 0.690 for always giving the home team the league rate and 0.608 for the closing line. A coin flip scores 0.693.
- The gap. The model is 0.030 behind the closing line per game, with a 95% interval of 0.015 to 0.044. The interval does not reach zero, and the closing line was ahead in each of the three seasons.
- Why that is the usual result. The closing line takes in everything known at kickoff, such as injuries and weather, which this model never sees. A model built only from past scores finishing behind it is the expected outcome. Closing the gap would take more inputs than game results.
5. Check calibration in bands
A probability is calibrated when games forecast at 60% are won about 60% of the time. Group the test games into bands of forecast and compare the average forecast with how often the home team won, with the game count in each band.
import pandas as pd
df = pd.read_csv("nfl_forecasts.csv")
test = df[df["season"] >= 2023].copy()
bins = [0, 0.3, 0.4, 0.5, 0.6, 0.7, 1]
for name, col in [("Elo model", "p_model"), ("Closing line", "p_close")]:
test["bin"] = pd.cut(test[col], bins)
table = test.groupby("bin", observed=True).agg(games=("home_win", "size"), forecast=(col, "mean"), home_won=("home_win", "mean"))
print(name)
print(table.round(3).to_string())Output
Elo model
games forecast home_won
bin
(0.0, 0.3] 57 0.238 0.351
(0.3, 0.4] 86 0.357 0.337
(0.4, 0.5] 155 0.450 0.394
(0.5, 0.6] 168 0.552 0.500
(0.6, 0.7] 149 0.646 0.664
(0.7, 1.0] 200 0.777 0.745
Closing line
games forecast home_won
bin
(0.0, 0.3] 80 0.230 0.225
(0.3, 0.4] 107 0.352 0.308
(0.4, 0.5] 145 0.444 0.393
(0.5, 0.6] 149 0.560 0.611
(0.6, 0.7] 147 0.645 0.653
(0.7, 1.0] 187 0.785 0.786The closing line's bands sit close to the home win rate in each one, with the largest gaps in the 50 to 60% band (0.560 forecast, 0.611 won, 149 games). The Elo model was too low on its biggest home underdogs: 57 games forecast at 23.8% were won 35.1% of the time. With 57 to 200 games a band, a gap of a few points is within noise.
6. Check the conversion against the served probability
get_game_probabilities returns the market's probability for one game across books: each book's implied probability, and a fair probability with the margin taken out of each book's two prices, then averaged. Compare it with the number the script worked out from the consensus moneyline.
import pandas as pd
from endzoneapi import Client
client = Client()
df = pd.read_csv("nfl_forecasts.csv")
game = df[df["game_id"] == "2025_18_WAS_PHI"].iloc[0]
served = client.get_game_probabilities(game["game_id"], snapshot_type="closing")
fair = served["moneyline"]["home"]["fair_prob"]
print(game["game_id"], "home moneyline", int(game["home_moneyline"]), "away", int(game["away_moneyline"]))
print("closing probability worked out here:", round(game["p_close"], 3))
print("fair_prob served by get_game_probabilities:", fair, "from", served["moneyline"]["books_used"], "books")
print("Elo model home probability:", round(game["p_model"], 3), "| home team won:", bool(game["home_win"]))
print("credits left:", client.last_credits_remaining)Output
2025_18_WAS_PHI home moneyline -180 away 150
closing probability worked out here: 0.616
fair_prob served by get_game_probabilities: 0.616 from 8 books
Elo model home probability: 0.834 | home team won: False
credits left: 997The conversion matches the served fair probability for the game (0.616) to three places. For this game the market put the home team at 61.6% and the Elo model at 83.4%; the home team lost. One game says nothing about either forecast, which is why the scoring above uses 815.
Tools and credits
- get_games: 16 calls, 80 credits (one call per season, 2010 to 2025).
- get_game_probabilities: 1 call, 5 credits (one game, optional).
One full run: 85 credits.
What you can do with the data
You may store these rows, train models and backtest on them, and build products that show your users what you derive. You may not redistribute the rows, or the odds as a raw feed, as a dataset or API of its own. Closing lines are market information. A past score is not a forecast of a future one.
Details: data timing and rights.
What to do next
Start with 500 free credits every month
No card. pip install endzoneapi, REST or MCP.