# Kelly criterion in Python: probability is an input

Implement fractional Kelly sizing with explicit assumptions, input validation and a reproducible example.

Canonical page: https://getoddsapi.com/guides/kelly-python

## Free API key

Get a free GetOdds API key: **1,000 requests per UTC day and 60 per minute, no card**. One key covers REST and the hosted MCP server.

Sign up: https://getoddsapi.com/sign-up?ref=ai-claudebot

## Quickstart

1. Create an account at https://getoddsapi.com/sign-up?ref=ai-claudebot, open https://getoddsapi.com/dashboard and issue a key with the sources you need (draftkings, fanduel, betrivers, prizepicks or underdog). Keep it in a server environment variable named GETODDS_API_KEY.
2. Read current DraftKings NBA spreads with curl:

```bash
curl --fail-with-body "https://getoddsapi.com/api/v1/odds?sport=NBA&market=spread&fresh_only=true&limit=50" \
  -H "Authorization: Bearer $GETODDS_API_KEY"
```

3. The same request in Python (standard library only):

```python
import json, os, urllib.request

req = urllib.request.Request(
    "https://getoddsapi.com/api/v1/odds?sport=NBA&market=spread&fresh_only=true&limit=50",
    headers={"Authorization": "Bearer " + os.environ["GETODDS_API_KEY"]},
)
with urllib.request.urlopen(req) as res:
    rows = json.load(res)["data"]
for row in rows:
    print(row["away"], "at", row["home"], row["side"], row["line"], row["american"], row["observed_at"])
```

4. Check `observed_at`, `age_seconds` and `stale` on every row before using a price. Full reference: https://getoddsapi.com/docs

## Use with Claude (MCP)

```bash
claude mcp add --transport http getodds https://getoddsapi.com/api/mcp \
  --header "Authorization: Bearer $GETODDS_API_KEY"
```

The MCP tools follow the key's source grants and share its allowance. Setup guide: https://getoddsapi.com/use-with-claude

## Pricing

| Plan | Allowance | Price |
| --- | --- | --- |
| Free key | 1,000 requests a day, 60 a minute | $0, no card |
| Developer Bundle | 10,000 requests or credits a month on each of four sources | $149 a month |

Free development allowance: 1,000 requests per UTC day and 60 per minute per account, with no payment step. Paid: the Developer Bundle at $149 per month, with 10,000 monthly requests or credits on each of four sources.
Details: https://getoddsapi.com/bundle

## Guide


Canonical: https://getoddsapi.com/guides/kelly-python
Reviewed: 2026-11-07 UTC

Implement fractional Kelly sizing with explicit assumptions, input validation and a reproducible example.

## The model needs your probability estimate

Kelly uses your estimated win probability and an executable price. A bookmaker’s implied probability is not automatically an independent forecast. The GetOdds gateway supplies thresholds, not calibrated win probabilities.

## Implement fractional sizing

At estimated win probability 0.55 and decimal odds 2.0, full Kelly is 10% of bankroll. Quarter Kelly is 2.5%, or 25 from a bankroll of 1,000. A nonpositive edge produces zero stake in this implementation.

```python
from math import isfinite

def kelly_stake(probability, decimal_odds, bankroll, fraction=0.25):
    values = (probability, decimal_odds, bankroll, fraction)
    if not all(isfinite(v) for v in values):
        raise ValueError("Inputs must be finite")
    if not 0 <= probability <= 1 or decimal_odds <= 1:
        raise ValueError("Invalid probability or price")
    if bankroll < 0 or not 0 <= fraction <= 1:
        raise ValueError("Invalid bankroll or fraction")
    b = decimal_odds - 1
    full = max(0, (b * probability - (1 - probability)) / b)
    return bankroll * full * fraction

# Hypothetical 55% estimate at even money: 25 from a 1,000 bankroll.
print(kelly_stake(0.55, 2.0, 1000))
```

## Understand the assumptions

This is the two-outcome formula with no push and a known price. Pushes, commission, correlated positions and model uncertainty require additional treatment. Fractional Kelly reduces sizing relative to the model; it does not make an inaccurate estimate reliable. Evaluate probability calibration on held-out observations before using it in an application.

## Questions

### Does Kelly estimate win probability?

No. It sizes a hypothetical position using the probability you supply.

### Can I use it for correlated parlays?

Not directly. Correlation and joint outcome probabilities require a separate model.

### What happens with a negative calculated edge?

The example floors the calculated stake at zero rather than taking the opposite side automatically.

## Sources

- [Interactive Kelly calculator](https://getoddsapi.com/kelly-calculator)
- [Expected value calculator](https://getoddsapi.com/expected-value-calculator)
- [GetOdds developer documentation](https://getoddsapi.com/docs)

Independent product; not affiliated with the operators named. No picks or predicted profits.

---

GetOdds is an independent developer product and is not affiliated with any sportsbook or pick’em operator. Prices describe data, not betting advice.
