Skip to contents

This vignette compares prices and removes the bookmaker margin (the “vig”) using parlayapiR and keyless synthetic sandbox endpoints. It demonstrates calculations, not a tested profitable strategy. Keep market definitions and outcomes aligned before comparing real quotes.

1. Pull a board of odds

Sandbox mode serves synthetic but structurally identical data from /v1/sandbox/ endpoints. Prices come back in American format.

events <- pa_odds("basketball_nba", markets = "h2h", sandbox = TRUE)
events[, c("home_team", "away_team", "commence_time")]
#>               home_team       away_team        commence_time
#> 1    Los Angeles Lakers  Boston Celtics 2026-12-04T15:08:00Z
#> 2 Golden State Warriors      Miami Heat 2026-12-04T09:30:08Z
#> 3        Denver Nuggets Milwaukee Bucks 2026-12-04T03:31:52Z

Each event carries a bookmakers list-column in the same shape used by The Odds API v4: bookmakers, then markets, then outcomes.

2. Flatten to one row per quote

quotes <- do.call(rbind, lapply(seq_len(nrow(events)), function(i) {
  ev <- events[i, ]
  books <- ev$bookmakers[[1]]
  do.call(rbind, lapply(seq_len(nrow(books)), function(b) {
    mkt <- books$markets[[b]][1, ]
    outs <- mkt$outcomes[[1]]
    data.frame(
      event = paste(ev$away_team, "at", ev$home_team),
      book = books$key[b],
      outcome = outs$name,
      american = outs$price
    )
  }))
}))
quotes$decimal <- pa_american_to_decimal(quotes$american)
head(quotes)
#>                                  event       book            outcome american
#> 1 Boston Celtics at Los Angeles Lakers draftkings Los Angeles Lakers     -150
#> 2 Boston Celtics at Los Angeles Lakers draftkings     Boston Celtics      110
#> 3 Boston Celtics at Los Angeles Lakers    fanduel Los Angeles Lakers      120
#> 4 Boston Celtics at Los Angeles Lakers    fanduel     Boston Celtics     -120
#> 5 Boston Celtics at Los Angeles Lakers     betmgm Los Angeles Lakers      100
#> 6 Boston Celtics at Los Angeles Lakers     betmgm     Boston Celtics      130
#>    decimal
#> 1 1.666667
#> 2 2.100000
#> 3 2.200000
#> 4 1.833333
#> 5 2.000000
#> 6 2.300000

3. Line shopping: the best price per outcome

For this single-market sandbox example, find the highest decimal price for each outcome. With real data, first check exact event, market, period and line identity; matching team names alone is insufficient:

best <- aggregate(decimal ~ event + outcome, data = quotes, FUN = max)
names(best)[3] <- "best_decimal"
best <- merge(
  best,
  quotes,
  by.x = c("event", "outcome", "best_decimal"),
  by.y = c("event", "outcome", "decimal")
)
best[, c("event", "outcome", "book", "best_decimal")]
#>                                   event               outcome       book
#> 1  Boston Celtics at Los Angeles Lakers        Boston Celtics     betmgm
#> 2  Boston Celtics at Los Angeles Lakers    Los Angeles Lakers    fanduel
#> 3  Boston Celtics at Los Angeles Lakers    Los Angeles Lakers   pinnacle
#> 4   Miami Heat at Golden State Warriors Golden State Warriors draftkings
#> 5   Miami Heat at Golden State Warriors            Miami Heat    caesars
#> 6   Miami Heat at Golden State Warriors            Miami Heat     bovada
#> 7     Milwaukee Bucks at Denver Nuggets        Denver Nuggets    fanduel
#> 8     Milwaukee Bucks at Denver Nuggets        Denver Nuggets    caesars
#> 9     Milwaukee Bucks at Denver Nuggets       Milwaukee Bucks   pinnacle
#> 10    Milwaukee Bucks at Denver Nuggets       Milwaukee Bucks polymarket
#> 11    Milwaukee Bucks at Denver Nuggets       Milwaukee Bucks    fanduel
#>    best_decimal
#> 1          2.30
#> 2          2.20
#> 3          2.20
#> 4          2.45
#> 5          2.10
#> 6          2.10
#> 7          2.45
#> 8          2.45
#> 9          2.10
#> 10         2.10
#> 11         2.10

4. Devig a reference book to get fair probabilities

A quoted -110 / -110 market implies 52.4% for each side, which sums to 104.8%: the extra 4.8% is the margin. pa_devig() removes it. Here we devig one book’s two-way market three ways:

ev1 <- quotes[quotes$event == quotes$event[1], ]
ref <- ev1[ev1$book == ev1$book[1], ]
ref
#>                                  event       book            outcome american
#> 1 Boston Celtics at Los Angeles Lakers draftkings Los Angeles Lakers     -150
#> 2 Boston Celtics at Los Angeles Lakers draftkings     Boston Celtics      110
#>    decimal
#> 1 1.666667
#> 2 2.100000

pa_devig(ref$american, odds_format = "american")
#>     implied fair_prob fair_decimal
#> 1 0.6000000 0.5575221     1.793651
#> 2 0.4761905 0.4424779     2.260000
pa_devig(ref$american, odds_format = "american", method = "additive")
#>     implied fair_prob fair_decimal
#> 1 0.6000000 0.5619048     1.779661
#> 2 0.4761905 0.4380952     2.282609
pa_devig(ref$american, odds_format = "american", method = "power")
#>     implied fair_prob fair_decimal
#> 1 0.6000000 0.5643479     1.771957
#> 2 0.4761905 0.4356521     2.295410

The multiplicative method scales everything by the same factor. The power method shrinks long shots harder, which better matches the favorite-longshot bias in real markets. For two-way markets near even money the three methods agree closely.

5. Edge: fair probability versus the best available price

An edge exists when the best shopped price implies a lower probability than your fair estimate:

fair <- pa_devig(ref$american, odds_format = "american", method = "power")
comp <- data.frame(
  outcome = ref$outcome,
  fair_prob = fair$fair_prob,
  best_decimal = best$best_decimal[match(
    paste(ev1$event[1], ref$outcome),
    paste(best$event, best$outcome)
  )]
)
comp$edge <- comp$fair_prob * comp$best_decimal - 1
comp
#>              outcome fair_prob best_decimal        edge
#> 1 Los Angeles Lakers 0.5643479          2.2 0.241565365
#> 2     Boston Celtics 0.4356521          2.3 0.001999845

A positive edge means the price exceeds the threshold implied by this particular probability estimate. It does not establish that the estimate is accurate or that a wager has positive expected value.

6. Size the bet with the Kelly criterion

plays <- comp[comp$edge > 0, ]
if (nrow(plays)) {
  plays$stake <- pa_kelly(
    prob = plays$fair_prob,
    odds = plays$best_decimal,
    fraction = 0.25,
    bankroll = 1000
  )
}
plays
#>              outcome fair_prob best_decimal        edge      stake
#> 1 Los Angeles Lakers 0.5643479          2.2 0.241565365 50.3261177
#> 2     Boston Celtics 0.4356521          2.3 0.001999845  0.3845857

The fraction here is an illustrative input. Kelly sizing is sensitive to probability error; this example is not a staking recommendation.

Going live

Everything above works identically against live data. Get a free key (1,000 credits per month, no card required) at parlay-api.com, then:

pa_auth("your-api-key")
events <- pa_odds("basketball_nba", markets = "h2h,spreads,totals")
props <- pa_props("basketball_nba", markets = "player_points")
closes <- pa_closing_odds("basketball_nba", season = "2024")

Historical odds reach back to 2005, and closing lines include more than 30 million player prop closes since 2022, which makes pa_closing_odds() the natural calibration target for any model you backtest in R.