# roman-smith/oddsapi_ev architecture

> Architecture diagram of the GitHub repository roman-smith/oddsapi_ev, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-18). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/roman-smith/oddsapi_ev
- Repository: https://github.com/roman-smith/oddsapi_ev

## Overview

#### 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`](https://github.com/roman-smith/oddsapi_ev/blob/main/ev.py) (Parameters & presets)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_input["Acquisition"]
  node_parameters["Parameters &amp; presets<br/>validation<br/>[ev.py]"]
  node_odds_api{{"The Odds API<br/>external service"}}
  node_live_request["Live request<br/>acquisition<br/>[ev.py]"]
  node_json_snapshot["JSON snapshot<br/>local input<br/>[ev.py]"]
  node_source_filtering["Local source filters<br/>filtering<br/>[ev.py]"]
end

subgraph group_analysis["EV Pipeline"]
  node_raw_events["Raw event markets<br/>Odds API schema<br/>[ev.py]"]
  node_positions["Market positions<br/>tabular model<br/>[ev.py]"]
  node_market_metrics["De-vig market metrics<br/>fair-odds engine<br/>[ev.py]"]
  node_ev_models["Average / Pinnacle EV<br/>EV engine<br/>[ev.py]"]
  node_candidate_filters["Candidate filters<br/>filtering<br/>[ev.py]"]
  node_ranking_projection["Ranking &amp; projection<br/>output shaping<br/>[ev.py]"]
end

node_public_data["data&#40;&#41;<br/>public workflow<br/>[ev.py]"]
node_results[("pandas DataFrame<br/>public result<br/>[ev.py]")]
node_python_stack["Python numeric stack<br/>runtime dependency"]

node_public_data -->|"validates call"| node_parameters
node_parameters -->|"live source"| node_live_request
node_parameters -->|"file source"| node_json_snapshot
node_live_request -->|"HTTP request"| node_odds_api
node_odds_api -->|"API response"| node_raw_events
node_json_snapshot -->|"loads"| node_source_filtering
node_parameters -->|"local choices"| node_source_filtering
node_source_filtering -->|"filtered events"| node_raw_events
node_raw_events -->|"normalizes nested odds"| node_positions
node_positions -->|"groups comparable sides"| node_market_metrics
node_market_metrics -->|"fair lines and market context"| node_ev_models
node_parameters -->|"EV mode"| node_ev_models
node_ev_models -->|"priced candidates"| node_candidate_filters
node_parameters -->|"filter thresholds"| node_candidate_filters
node_candidate_filters -->|"eligible candidates"| node_ranking_projection
node_parameters -->|"sort and expanded option"| node_ranking_projection
node_ranking_projection -->|"returns"| node_results
node_python_stack -.->|"requests"| node_live_request
node_python_stack -.->|"pandas / numpy"| node_positions
node_python_stack -.->|"DataFrame"| node_results

click node_public_data "https://github.com/roman-smith/oddsapi_ev/blob/main/ev.py"
click node_parameters "https://github.com/roman-smith/oddsapi_ev/blob/main/ev.py"
click node_live_request "https://github.com/roman-smith/oddsapi_ev/blob/main/ev.py"
click node_json_snapshot "https://github.com/roman-smith/oddsapi_ev/blob/main/ev.py"
click node_source_filtering "https://github.com/roman-smith/oddsapi_ev/blob/main/ev.py"
click node_raw_events "https://github.com/roman-smith/oddsapi_ev/blob/main/ev.py"
click node_positions "https://github.com/roman-smith/oddsapi_ev/blob/main/ev.py"
click node_market_metrics "https://github.com/roman-smith/oddsapi_ev/blob/main/ev.py"
click node_ev_models "https://github.com/roman-smith/oddsapi_ev/blob/main/ev.py"
click node_candidate_filters "https://github.com/roman-smith/oddsapi_ev/blob/main/ev.py"
click node_ranking_projection "https://github.com/roman-smith/oddsapi_ev/blob/main/ev.py"
click node_results "https://github.com/roman-smith/oddsapi_ev/blob/main/ev.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_parameters,node_odds_api,node_live_request,node_json_snapshot,node_source_filtering toneBlue
class node_raw_events,node_positions,node_market_metrics,node_ev_models,node_candidate_filters,node_ranking_projection toneAmber
class node_public_data,node_results,node_python_stack toneNeutral
```

## Components

### Acquisition

Alternative live and offline sources.

- [Parameters & presets](https://github.com/roman-smith/oddsapi_ev/blob/main/ev.py): validation · Validates inputs, defaults, modes, and recommended overrides. · `ev.py`
- **The Odds API**: external service · Live upcoming-event odds source requiring a caller API key.
- [Live request](https://github.com/roman-smith/oddsapi_ev/blob/main/ev.py): acquisition · Requests selected sports, regions, and markets. · `ev.py`
- [JSON snapshot](https://github.com/roman-smith/oddsapi_ev/blob/main/ev.py): local input · Offline Odds API-shaped response data. · `ev.py`
- [Local source filters](https://github.com/roman-smith/oddsapi_ev/blob/main/ev.py): filtering · Applies applicable sport, region, and market choices to file data. · `ev.py`

### EV Pipeline

Tabular odds modeling through ranked candidates.

- [Raw event markets](https://github.com/roman-smith/oddsapi_ev/blob/main/ev.py): Odds API schema · Nested upcoming-event bookmaker and outcome data. · `ev.py`
- [Market positions](https://github.com/roman-smith/oddsapi_ev/blob/main/ev.py): tabular model · Comparable event, market, outcome, bookmaker, line, and American-odds rows. · `ev.py`
- [De-vig market metrics](https://github.com/roman-smith/oddsapi_ev/blob/main/ev.py): fair-odds engine · Derives implied probabilities, fair lines, vig, width, and book counts. · `ev.py`
- [Average / Pinnacle EV](https://github.com/roman-smith/oddsapi_ev/blob/main/ev.py): EV engine · Builds consensus or Pinnacle fair-odds reference and computes EV and Kelly. · `ev.py`
- [Candidate filters](https://github.com/roman-smith/oddsapi_ev/blob/main/ev.py): filtering · Filters horizon, books, odds, width, vig, EV, and contributor count. · `ev.py`
- [Ranking & projection](https://github.com/roman-smith/oddsapi_ev/blob/main/ev.py): output shaping · Sorts candidates and selects essential or expanded columns. · `ev.py`

### Other components

- [data()](https://github.com/roman-smith/oddsapi_ev/blob/main/ev.py): public workflow · Single public function returning a pandas DataFrame. · `ev.py`
- [pandas DataFrame](https://github.com/roman-smith/oddsapi_ev/blob/main/ev.py): public result · Stable user-facing candidate-bet result. · `ev.py`
- **Python numeric stack**: runtime dependency · pandas, numpy, requests, JSON, and date-time parsing support the workflow.

## Connections

- 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
