Metadata-Version: 2.5
Name: strokes-gained
Version: 0.1.0
Summary: Calculate strokes gained in golf: expected strokes to hole out from any lie and distance, strokes gained per shot, hole and round, and strokes lost to scratch by handicap. From Mark Broadie's PGA Tour tables. Library, CLI and pandas helper, no dependencies. From Shotto, an AI agent for golf on iPhone and Apple Watch.
Project-URL: Homepage, https://shottogolf.com/strokes-gained
Project-URL: Shotto on the App Store, https://apps.apple.com/app/id6763337009
Project-URL: Repository, https://github.com/shottogolf/strokes-gained
Project-URL: Issues, https://github.com/shottogolf/strokes-gained/issues
Project-URL: JavaScript package, https://www.npmjs.com/package/strokes-gained
Author-email: Shotto <press@shottogolf.com>
License-Expression: MIT
License-File: LICENSE
Keywords: broadie,expected strokes,golf,golf analytics,golf handicap,golf stats,handicap,pandas,pga tour,shot tracking,shotlink,strokes gained,strokes-gained
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Science/Research
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Scientific/Engineering :: Information Analysis
Classifier: Typing :: Typed
Requires-Python: >=3.9
Provides-Extra: pandas
Requires-Dist: pandas>=1.3; extra == 'pandas'
Description-Content-Type: text/markdown

# strokes-gained

**Calculate strokes gained in golf with Python.** Expected strokes to hole out from any lie and distance, strokes gained for every shot, hole and round, and how many strokes golfers at each handicap lose to a scratch golfer. A library and command line tool with no dependencies, plus an optional pandas helper, built on Mark Broadie's published PGA Tour tables. Python 3.9 and later. Also on npm: `npx strokes-gained`.

Made by [Shotto](https://shottogolf.com), an AI agent for golf on iPhone and Apple Watch that tracks every shot from what you say and works out your strokes gained.

```sh
pip install strokes-gained
strokes-gained hole "tee 410, fairway 150, green 20ft, green 3ft"
```

```
 1. 410 y tee        Off the tee       +0.06
 2. 150 y fairway    Approach          +0.08
 3. 20 ft green      Putting           −0.17
 4. 3 ft green       Putting           +0.04

4 on a par 4: +0.00 against the Tour
Off the tee +0.06 · Approach +0.08 · Putting −0.13
```

## What is strokes gained?

Strokes gained measures each golf shot against a benchmark: the average number of strokes it takes to hole out from where the ball was. A shot that leaves you somewhere better than the benchmark expects gains strokes, and one that leaves you somewhere worse loses them. Added up over a round, it shows where your strokes are won and lost: off the tee, on approach shots, around the green and on the putting green.

```
strokes gained = expected strokes before the shot − expected strokes after it − 1
```

From 150 yards in the fairway a PGA Tour player averages 2.95 strokes to hole out, and from 20 feet on the green 1.87. So hitting it from 150 yards to 20 feet gains 2.95 − 1.87 − 1 = **+0.08** strokes: slightly better than the average Tour player. Holing a 3-footer gains 1.04 − 0 − 1 = +0.04, and missing it loses about 0.96.

Mark Broadie developed the method at Columbia Business School and explains it in [*Every Shot Counts*](https://business.columbia.edu/faculty/research/every-shot-counts-using-revolutionary-strokes-gained-approach-improve-your-golf) (2014). The PGA Tour has published strokes-gained statistics since 2011, starting with putting. There's a short guide at [shottogolf.com/strokes-gained](https://shottogolf.com/strokes-gained).

## Strokes gained tables

Expected strokes to hole out for the average PGA Tour player, from Broadie's tables, and the strokes golfers at each handicap lose to a scratch golfer. Look up the spots before and after any shot and the formula above does the rest. Values between rows are interpolated.

<!-- BEGIN GENERATED: tables (node tools/gen-sg-baseline.mjs) -->
### From the fairway, rough, sand and recovery

| Distance | Fairway | Rough | Sand | Recovery |
| --- | --- | --- | --- | --- |
| 20 yards | 2.40 | 2.59 | 2.53 | 3.51 |
| 30 yards | 2.52 | 2.70 | 2.66 | 3.57 |
| 50 yards | 2.66 | 2.87 | 2.92 | 3.79 |
| 75 yards | 2.74 | 2.95 | 3.23 | 3.84 |
| 100 yards | 2.80 | 3.02 | 3.23 | 3.80 |
| 125 yards | 2.87 | 3.10 | 3.21 | 3.78 |
| 150 yards | 2.95 | 3.19 | 3.25 | 3.80 |
| 175 yards | 3.06 | 3.29 | 3.37 | 3.82 |
| 200 yards | 3.19 | 3.42 | 3.55 | 3.87 |
| 225 yards | 3.35 | 3.56 | 3.74 | 3.93 |
| 250 yards | 3.52 | 3.69 | 3.88 | 4.00 |

### From the tee

| Hole length | Expected strokes |
| --- | --- |
| 150 yards | 2.98 |
| 175 yards | 3.04 |
| 200 yards | 3.12 |
| 350 yards | 3.89 |
| 400 yards | 3.99 |
| 450 yards | 4.13 |
| 500 yards | 4.41 |
| 550 yards | 4.70 |

### On the green

| Putt | Expected putts |
| --- | --- |
| 3 feet | 1.04 |
| 5 feet | 1.23 |
| 8 feet | 1.50 |
| 10 feet | 1.61 |
| 15 feet | 1.78 |
| 20 feet | 1.87 |
| 30 feet | 1.98 |
| 40 feet | 2.06 |
| 60 feet | 2.20 |

### Strokes lost to a scratch golfer, by handicap

Per 18 holes, for a typical golfer at each handicap.

| Handicap | Long game | Short game | Sand | Putting | Total |
| --- | --- | --- | --- | --- | --- |
| 5 | −2.2 | −0.8 | −0.2 | −0.8 | −4.0 |
| 10 | −5.2 | −1.9 | −0.4 | −1.4 | −8.8 |
| 15 | −8.1 | −3.0 | −0.5 | −2.0 | −13.7 |
| 20 | −11.2 | −4.3 | −0.7 | −2.9 | −19.2 |
| 25 | −14.3 | −5.8 | −0.9 | −4.0 | −25.1 |
| 30 | −17.5 | −7.3 | −1.1 | −5.1 | −31.0 |
| PGA Tour average | +3.7 | +0.9 | +0.15 | +0.65 | +5.4 |
<!-- END GENERATED: tables -->

The long game (tee shots and approaches) is where most of the strokes go at every level: about 8 of a 15-handicap's 14 strokes a round to scratch. The handicap rows come from Broadie's amateur data. We place his scoring groups at handicaps of about 5, 17 and 30, and interpolate between them.

## Tracking your own strokes gained

Strokes gained only needs to know where each shot started and where it finished. There are three ways to get that for your own rounds:

- **Write it down yourself.** Note each shot's lie and distance on the card or in a spreadsheet, then let this package do the maths (see [pandas](#with-pandas) below).
- **Put sensors on your clubs,** which tag each shot as you play.
- **Talk to [Shotto](https://shottogolf.com).** Say what happened after a shot, a few words to your Apple Watch or iPhone, or talk through the whole round on the drive home. Shotto places each shot on the hole and works out your strokes gained off the tee, on approach, around the green and putting, with nothing to tap on the course and nothing on your clubs. Its strokes gained comes from these same tables. It also keeps what sensors can't see, like the target you had in mind and how the swing felt. [Shotto Golf is on the App Store](https://apps.apple.com/app/id6763337009), with a two-week free trial.

## Python

```python
import strokes_gained as sg

sg.expected_strokes({"lie": "fairway", "yards": 150})        # 2.945
sg.strokes_gained({"lie": "fairway", "yards": 150},
                  {"lie": "green", "feet": 20})               # 0.075

h = sg.hole([
    {"lie": "tee", "yards": 410},
    {"lie": "fairway", "yards": 150},
    {"lie": "green", "feet": 20},
    {"lie": "green", "feet": 3},                              # the last one is holed
], par=4)
h["byCategory"]   # {'offTee': 0.06, 'approach': 0.075, 'aroundGreen': 0.0, 'putting': -0.13}

sg.round_total([h])["total"]

sg.level_vs_scratch("putting", 15)                            # -2.05: strokes a round a 15 loses putting
sg.plays_like_handicap(-2.3, [{"bucket": "putting"}])         # 17: losing 2.3 putting is a 17's putting
```

| Function | What it gives you |
| --- | --- |
| `expected_strokes(position)` | PGA Tour expected strokes to hole out |
| `strokes_gained(start, end, holed=False, penalty_strokes=0)` | One shot against the Tour |
| `category(start, par=4)` | `offTee`, `approach`, `aroundGreen` (30 yards and in) or `putting` |
| `hole(positions, par=4)` | Every shot on a hole, by category, with the total |
| `round_total(holes)` | Holes added up |
| `shots_table(rows)` | A list of shot rows, grouped into holes, with `expected`, `category` and `strokesGained` added |
| `level_vs_scratch(bucket, handicap)` | Strokes per 18 holes a golfer of that handicap loses to scratch |
| `tour_vs_scratch(bucket)` | Strokes per 18 holes the average Tour player gains on scratch |
| `plays_like_handicap(sg_vs_scratch, buckets)` | The handicap a strokes-against-scratch number corresponds to |
| `parse_position(text)`, `parse_hole(text)` | The command line's parser |

A position is a dict with a `lie` (tee, fairway, rough, sand or bunker, recovery, green) and one of `yards`, `feet` or `meters`. In `hole()`, a position's `penaltyStrokes` counts against the shot that ended there, so `{"lie": "fairway", "yards": 60, "penaltyStrokes": 1}` is a drop after a ball in the water. The handicap functions use Broadie's four parts of the game (`longGame`, `shortGame`, `sand`, `putting`), because that's how his amateur data is split. The package is typed, and the raw tables are `strokes_gained.BASELINE`.

## With pandas

```sh
pip install "strokes-gained[pandas]"
```

```python
import pandas as pd
from strokes_gained.pandas import add_strokes_gained

shots = pd.DataFrame([
    {"hole": 1, "par": 4, "lie": "tee", "yards": 410},
    {"hole": 1, "par": 4, "lie": "fairway", "yards": 150},
    {"hole": 1, "par": 4, "lie": "green", "feet": 20},
    {"hole": 1, "par": 4, "lie": "green", "feet": 3},
    {"hole": 2, "par": 3, "lie": "tee", "yards": 180},
    {"hole": 2, "par": 3, "lie": "green", "feet": 30},
    {"hole": 2, "par": 3, "lie": "green", "feet": 2},
])
add_strokes_gained(shots).groupby("category")["strokes_gained"].sum()
# approach    0.15
# offTee      0.06
# putting    -0.15
```

One row per shot, in playing order. Rows with the same `hole` are one hole, and the last row of each hole was holed. A row's empty distance columns are ignored, so `yards` and `feet` can share a table.

## Command line

```sh
strokes-gained expected "150y fairway"           # 2.95 strokes to hole out
strokes-gained shot "150y fairway" "20ft green"  # +0.08 strokes gained
strokes-gained shot "3ft green" holed            # +0.04
strokes-gained hole "tee 180, fairway 60 +1, green 8ft" --par 3
strokes-gained level 15                          # what a 15 handicap loses to scratch
```

A position is a distance and a lie in either order: `150y fairway`, `fairway 150`, `20ft green`, `bunker 30 yards`, `140m rough`. Distances are in yards unless you say otherwise, and in feet on the green. A trailing `+1` is a penalty stroke on the shot that ended there. Add `--json` to any command for JSON. The output matches the npm package's command line exactly.

## Questions

### What is a good strokes gained number?

Zero means a shot, round or part of your game matched the benchmark exactly. Against the PGA Tour baseline nearly every amateur is negative, so the useful comparison is against golfers at your level: a 15-handicap typically loses about 2 strokes a round putting to a scratch golfer, so losing 1 means your putting is ahead of your handicap. `level_vs_scratch` and `plays_like_handicap` do that comparison.

### How many strokes does a 15-handicap lose to a scratch golfer?

About 14 a round: roughly 8 in the long game, 3 in the short game, half a stroke from bunkers and 2 putting. The table above has every level from 5 to 30.

### Is strokes gained measured against the PGA Tour or a scratch golfer?

Either. The per-shot numbers here are against the PGA Tour, which is the standard reference. To read a round against scratch, add the Tour's edge on scratch for each part of the game (`tour_vs_scratch`, about 5.4 strokes a round in all).

### Do I need sensors or a launch monitor to track strokes gained?

No. Strokes gained needs only where each shot started and finished. That can come from club sensors, from a notebook, or from what you say: [Shotto](https://shottogolf.com) works out strokes gained from shots you describe to your Apple Watch or iPhone.

### Which golf apps calculate strokes gained?

Sensor-based trackers calculate it from shots their sensors tag, and some GPS apps from shots you tap in. [Shotto](https://shottogolf.com) calculates it from what you say about each shot, during the round or after it, so there's nothing to tap or attach. Shotto Golf is on the App Store for iPhone and Apple Watch.

### Is there a JavaScript version?

Yes: `npm install strokes-gained`. It has the same functions and the same command line.

## Where the numbers come from

- **Tee to green:** Broadie (2011), "Assessing Golfer Performance on the PGA TOUR", Table 9: average strokes to hole out from about 8 million ShotLink shots, 2003 to 2010. Values between rows are interpolated in a straight line, and distances past either end take the end value.
- **Putting:** the Tour expected-putts curve by distance, anchored to the paper's 1.80 from 16 feet.
- **Handicap levels:** Broadie's Golfmetrics amateur data, by part of the game against scratch. The handicap given to each of his scoring groups (about 5, 17 and 30) is our estimate.
- **The Tour's edge on scratch:** about 5.4 strokes a round (*Every Shot Counts*, 2014). How it splits between the parts of the game is our estimate.

These are Tour averages from one era, the standard reference for strokes gained.

## Conformance

This package passes the same 174 cases (`tests/conformance.json`) as the npm package and the Shotto app's Swift implementation. All three are generated from one copy of the tables.

Source, issues and both packages: [github.com/shottogolf/strokes-gained](https://github.com/shottogolf/strokes-gained).

## License

MIT. Made by [Shotto](https://shottogolf.com).
