Computer Picks

How to Create a Sports Betting Algorithm, One Step at a Time

9 min read
How to create a sports betting algorithm in a spreadsheet

Learning how to create a sports betting algorithm comes down to a handful of steps: pick one sport and one bet type, collect final scores and betting lines, turn those scores into offense and defense ratings for every team, adjust them for opponent and home field, and use them to project a score. Then compare that projection with the sportsbook's line, and only trust the result after testing it on games it hasn't seen.

That's the whole idea, and it fits in a spreadsheet. We run a free sportsbook with its own computer picks model built on exactly these steps, so this guide walks through them with made-up teams and plain math. If you'd like the bigger picture first (what different kinds of models do and how they compare), our guide to how sports betting models work covers that.

Step 1: Pick one sport and one bet type

Start with one league and one market. A betting model that tries to handle the NFL, the NBA and MLB moneyline bets all at once usually does none of them well, because each sport scores differently and each market asks a different question.

Point spreads and totals are the easiest place to begin. Both come down to points: who wins by how much, and how many get scored. A score projection answers both at the same time. Player props need player performance data and minutes, and live betting needs live data feeds, so leave those for later.

Football and basketball suit this kind of model well. There are plenty of games, scoring is steady enough to measure, and the lines are easy to find. If you're not sure what a spread or total is yet, our list of betting terms in plain English will get you there.

Step 2: Get the data (final scores and lines)

You need two things for every game: the final score and the betting line. That's it for a first model. Date, home team, away team, home score, away score, closing spread and closing total, one game per row. That row is your whole dataset.

Two seasons of historical data is a good amount. One season is thin, and much more than two starts measuring teams that don't exist anymore. Write down the line at kickoff, not the opening line, because that's the number you'll be graded against later.

Plenty of people want to add more inputs right away: injuries, weather, rest days, the referee crew, betting trends. Leave them out for now. Every extra input is a new way to fool yourself. Get a simple model working first and add things one at a time, keeping only what makes the test results better.

Step 3: Build team ratings from final scores

Each team gets two numbers, an offense rating and a defense rating, and they do most of the work in the algorithm. Say the league average is 22 points per team per game. Team A has scored 27 a game and allowed 19. Team B has scored 21 and allowed 24. In plain spreadsheet words:

  • Offense rating = points scored per game minus the league average.
  • Defense rating = the league average minus points allowed per game.

So Team A is +5 on offense and +3 on defense. Team B is -1 on offense and -2 on defense. Positive is good on both.

Two changes make these ratings a lot better. First, let recent games count more than old ones. A simple way is to give each game a weight that shrinks the older it gets, then take a weighted average instead of a plain one. Second, pull every rating part of the way back toward zero, especially early in the season. A team that's +5 after three games probably isn't really +5. Small samples run hot and cold, and the pull toward average keeps your model from believing them too much.

Step 4: Adjust for the opponent and home field

Raw averages lie when schedules are uneven. If Team A's 27 points a game came against defenses that usually allow 25, Team A is really only 2 points better than those defenses normally give up, not 5.

The fix is to rate each game against the opponent. For every game, compare what a team scored with what that opponent usually allows, and average those differences. Do the same on defense. Then recalculate everyone with the new ratings and run it again. After a few rounds the numbers stop moving, and you have opponent-adjusted ratings. In a spreadsheet this is a few columns you copy across three or four times; in Python it's a short loop.

Home field is the other adjustment. Home teams score a little more and allow a little less, and you can measure how much from your own data: average home margin across all games in the league. For our example we'll use 2 points, split as +1 for the home team and -1 for the visitor. Measure it yourself, though, because it changes by league and has shrunk over the years in some sports.

Step 5: Project a score

Now you can predict a game. Team A hosts Team B. In plain words:

  • Home projected points = league average + home offense rating minus away defense rating + home edge.
  • Away projected points = league average + away offense rating minus home defense rating minus home edge.

Using the raw ratings: Team A gets 22 + 5 + 2 + 1 = 30. Team B gets 22 - 1 - 3 - 1 = 17. That's Team A by 13, with 47 total points.

Now pull every rating a third of the way toward zero, as in Step 3. Team A becomes +3.3 on offense and +2 on defense, Team B -0.7 and -1.3. The projection drops to about Team A 27.7, Team B 18.3. Team A by 9.3, with 46 total points. The teams and scores haven't changed, but the answer has moved almost 4 points. This one setting changes your picks more than almost anything else, which is why it's worth testing carefully.

Step 6: Compare the projection to the line

Suppose the sportsbook has Team A -9.5 and the total at 44.5.

With the raw ratings, your model says Team A by 13, which is 3.5 points better than the line. With the pulled-back ratings, it says Team A by 9.3, almost exactly the line, so there's no bet on the side. On the total, the pulled-back model has 46 against 44.5, a lean to the over of 1.5 points.

The gap between your number and the line is your edge. Small gaps are noise. The sportsbooks have their own algorithms and a lot more data than you, and the odds set by sportsbooks are usually close to right. Most of the time your projection and the line will be within a point or two, and those games should be passes. You're looking for the few where the gap is large.

It helps to think in implied probabilities. A bet at -110 has an implied probability of 52.4% (110 divided by 210). That's the share of bets you have to win to break even. A value bet, or a bet with positive expected value, is one where you think the real chance of winning is higher than that. Turning a point gap into a win chance takes one more table from your backtest: how often teams covered when your model disagreed with the line by 1 point, 2 points, 3 points and so on. Some modelers simulate each game thousands of times instead (a Monte Carlo simulation), but the table is simpler and does the same job for spreads and totals.

Step 7: Backtest honestly, without peeking

This is where most homemade models fall apart, and usually without the builder noticing.

The rule is simple: when you test a game, the model may only use games played before it. If you build ratings from the full season and then "predict" week 3 with them, the ratings already know what happened in week 3. Your results will look great and mean nothing. Do it walk-forward instead. Rate the teams with games through week 2, project week 3, record the picks, then add week 3 and project week 4. A spreadsheet can do this with one tab per week, or with a date filter on the averages.

The second trap is trying fifty settings on the same seasons and keeping the best. Something always looks good by luck. Pick your settings on one season, then test them on another one the model has never touched. An edge that only shows up in the season you tuned on was luck.

And give it enough bets. Over 100 bets, a model with no edge at all will land somewhere between about 42% and 62% most of the time, just from luck. A few hundred graded picks is the least you need before you believe a win rate, and more is better. Count the pushes separately and grade every pick against the line you'd actually have gotten.

Step 8: Track closing lines

Win rate is slow to tell you anything. The closing line is faster. Write down the line when your model makes a pick and the line at kickoff. If the line keeps moving toward your side (you liked Team A at -9.5 and it closed -11), the betting markets are agreeing with you after the fact. A model that beats the closing line more often than not has a good chance of being a winner over time, even through a losing month. If the line moves against you most of the time, treat that as a warning, hot streak or not.

Step 9: Size your bets

Bet the same amount on every pick to start. One unit, around 1% to 2% of your bankroll. Once you have a long, honest record, you can bet a little more on the biggest edges, but keep the steps small. A model that's right 54% of the time still loses five or six in a row now and then, and big bets turn a normal cold run into a broken bankroll. Our unit-sizing guide goes through it in more detail.

Start small even then. We'd rather you find out your model's real record with a free balance than with rent money. You can bet every pick on a free sportsbook like CentSports' NFL lines and let it grade the results for you.

Our model as a real example

Our computer picks follow the same recipe. Each team gets an offense and a defense rating built from final scores over two seasons, with recent games counting more. The ratings are adjusted for the opponent and home field, the model projects a score, and it compares that score with the line. The side it favors is the pick, against the spread and on the total, for every game. A team needs at least 4 games played before it gets a pick.

Each pick gets 1 to 5 stars depending on how far the projection is from the line: 5 is a Top pick, then Strong, Solid, Lean and Slight lean. Once a league has 60 or more picks in a year, 5 stars works out to about the top 10%. Picks update until kickoff, then lock and get graded on the line at kickoff.

The honest testing part runs every week. The model replays the last 6 weeks with other settings, such as how fast old games fade and how far ratings are pulled toward average, and keeps the one with the smallest miss. Past picks never change, so the record is what it really did. You can see that record for free (overall, by star level, spreads and totals, week by week) on the free nfl computer picks page and the nba computer picks record, along with college football and college basketball.

No model is a sure thing, ours included. What building one gives you is a reason behind every bet and a record that shows whether the reason holds up, which makes it a lot easier to stay consistent through a bad week.

CentSports is for players 21 and over. Gambling problem? Call 1-800-GAMBLER.

FAQ

Is there an algorithm for sports betting?
There are lots of them, from simple power ratings to machine learning models. Sportsbooks use their own to set odds, and bettors build theirs to find lines that look wrong. None of them wins every bet.
Do I need to know how to code to build a betting model?
No. A spreadsheet can handle team ratings, projected scores and a backtest for one league. Python or another language helps once you want to pull data automatically or test many settings at once.
Can a sports betting algorithm beat the sportsbooks?
Some can, by a small margin, in some markets. At standard -110 odds you need to win about 52.4% of your bets to break even, and the closing line is sharp, so most homemade models end up close to break even. Test yours honestly before you trust it.
Can I make a sports betting algorithm in Excel?
Yes. Put one game per row with the final score and the line, work out each team's offense and defense rating with averages, then project the next game from those ratings. Everything in this guide can be done in Excel or Google Sheets.

Build a streak today

15 in a row = $100 · 21 in a row = $1,500 · Free to play.

Join free

More from Computer Picks