Skip to content

Add pa_hold(): bookmaker margin from quoted odds #2

Open

Description

@JacobiusMakes

The package converts odds (pa_american_to_decimal, pa_implied_prob in R/odds-utils.R) and removes the margin (pa_devig() in R/devig.R, which exposes the overround as an attribute), but there is no direct way to ask the everyday question: how much margin is in this market's prices? Add pa_hold().

Proposed change

  1. New exported function in R/odds-utils.R:
pa_hold <- function(odds = NULL,
                    probs = NULL,
                    odds_format = c("decimal", "american")) {
  # sum(pa_implied_prob(odds)) - 1, or sum(probs) - 1
}
  1. Semantics: takes the quoted odds for ALL outcomes of one market (both sides of a total, three outcomes of a soccer match) and returns a single number, the bookmaker hold, e.g. pa_hold(c(-110, -110), odds_format = "american") is about 0.0476.
  2. Validation mirrors pa_devig(): exactly one of odds or probs, at least 2 outcomes, probabilities strictly in (0, 1). Reuse pa_implied_prob() for the conversion rather than duplicating it.
  3. Full roxygen block in the style of the neighboring functions, with @examples covering a 2-way and a 3-way market, plus a NEWS.md entry. Regenerate NAMESPACE with roxygen so the export lands.

Acceptance criteria

  • pa_hold(c(-110, -110), odds_format = "american") returns approximately 0.0476.
  • pa_hold(c(2.45, 3.40, 3.10)) returns the 3-way overround, matching attr(pa_devig(c(2.45, 3.40, 3.10)), "overround") exactly.
  • pa_hold(c(-110)) errors with a clear message.
  • testthat tests in tests/testthat/test-odds-utils.R cover the three cases above, no network needed.
  • R CMD check passes.
  • No new dependencies.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions