How roman-smith/oddsapi_ev works
Purpose and Public Entry Point
This is a small Python library that finds potentially positive-expected-value sports bets. Its sole public workflow is data(), implemented in ev.py, which acquires Odds API-shaped event/market data, derives fair odds and EV metrics, filters/sorts candidates, and returns a pandas DataFrame.
Grounding: ev.py
Input Boundary: Live API or JSON Snapshot
data() supports two mutually alternative raw-data sources:
• A live request to The Odds API, requiring a caller-provided API key.
• A local JSON file whose schema matches the Odds API response.
API-oriented options select sports, bookmaker regions, and markets; file-oriented execution applies most of those choices as local filtering. This boundary makes calculation logic usable both against quota-metered external data and reproducible offline captures.
Grounding: ev.py, README.md
Validation and Query Configuration
The function owns validation/defaulting for its large parameter surface. It ensures an API key or filename exists, constrains API selection values (regions, markets, EV modes), reconciles preferred EV filtering/sorting with selected calculation modes, and applies a recommended preset that overrides normal filters.
Invalid acquisition or EV-mode inputs terminate the workflow; invalid numeric filter inputs are treated more leniently and may leave that filter unapplied.
Grounding: ev.py
Odds Normalization and Market Modeling
Raw upcoming-event odds are transformed from nested API/JSON structures into tabular positions representing a bookmaker’s offered line for an event, market, and outcome. The calculation must preserve comparable sides of a market so bookmaker margin, fair lines, widths, and cross-book consensus can be derived before final output projection.
The supported market classes are head-to-head, spreads, and totals; bets are represented in American odds terms.
Grounding: ev.py, README.md
Fair-Odds and EV Calculation
The core analytical stage removes sportsbook vig from implied probabilities to derive fair_line and vig_pct, then calculates:
• Average EV: consensus fair odds across bookmakers after margin removal.
• Pinnacle EV: fair odds based on Pinnacle’s de-vigged market.
• Optional simultaneous calculation of both methods.
It also calculates market width, contributing-bookmaker count (num_books), ev_pct, and Kelly staking percentage (kelly_pct). These derived values distinguish candidate bet offers from the reference “true odds” model.
Grounding: ev.py, README.md
Candidate Filtering, Ranking, and Output Contract
After metrics are available, the pipeline filters by event horizon, books, American-odds range, width, vig, minimum EV, and minimum contributing books. A contradictory minimum/maximum odds range yields an empty DataFrame.
Results are sorted by a specified operational metric or default multi-field ordering. expanded=False returns essential analysis columns; expanded=True exposes intermediate/calculation fields. The stable user-facing result is always a pandas DataFrame.
Grounding: ev.py
Runtime and External Dependencies
The package runs in Python and depends materially on pandas/numpy for tabular and numeric processing, requests for API calls, and JSON/date-time libraries (datetime, dateutil.parser, pytz) for source parsing and future-event filtering. The only identified external service is The Odds API; users supply its credential and absorb request-quota implications.
Grounding: ev.py, README.md
Main entry points: ev.py Parameters & presets
Components 14
Acquisition
Alternative live and offline sources.
- Parameters & presets · Validates inputs, defaults, modes, and recommended overrides.
ev.py - The Odds API · Live upcoming-event odds source requiring a caller API key.
- Live request · Requests selected sports, regions, and markets.
ev.py - JSON snapshot · Offline Odds API-shaped response data.
ev.py - Local source filters · Applies applicable sport, region, and market choices to file data.
ev.py
EV Pipeline
Tabular odds modeling through ranked candidates.
- Raw event markets · Nested upcoming-event bookmaker and outcome data.
ev.py - Market positions · Comparable event, market, outcome, bookmaker, line, and American-odds rows.
ev.py - De-vig market metrics · Derives implied probabilities, fair lines, vig, width, and book counts.
ev.py - Average / Pinnacle EV · Builds consensus or Pinnacle fair-odds reference and computes EV and Kelly.
ev.py - Candidate filters · Filters horizon, books, odds, width, vig, EV, and contributor count.
ev.py - Ranking & projection · Sorts candidates and selects essential or expanded columns.
ev.py
Other components
- data() · Single public function returning a pandas DataFrame.
ev.py - pandas DataFrame · Stable user-facing candidate-bet result.
ev.py - Python numeric stack · pandas, numpy, requests, JSON, and date-time parsing support the workflow.
Connections 20
- data() → Parameters & presets: validates call
- Parameters & presets → Live request: live source
- Parameters & presets → JSON snapshot: file source
- Live request → The Odds API: HTTP request
- The Odds API → Raw event markets: API response
- JSON snapshot → Local source filters: loads
- Parameters & presets → Local source filters: local choices
- Local source filters → Raw event markets: filtered events
- Raw event markets → Market positions: normalizes nested odds
- Market positions → De-vig market metrics: groups comparable sides
- De-vig market metrics → Average / Pinnacle EV: fair lines and market context
- Parameters & presets → Average / Pinnacle EV: EV mode
- Average / Pinnacle EV → Candidate filters: priced candidates
- Parameters & presets → Candidate filters: filter thresholds
- Candidate filters → Ranking & projection: eligible candidates
- Parameters & presets → Ranking & projection: sort and expanded option
- Ranking & projection → pandas DataFrame: returns
- Python numeric stack → Live request: requests
- Python numeric stack → Market positions: pandas / numpy
- Python numeric stack → pandas DataFrame: DataFrame