The Summer of Jeff

Python code for WPA stats

Posted in baseball analysis, programming by Jeff on February 7, 2011

A long time ago I put together a python version of the win expectancy/volatility calculations contained in Studes’s WPA spreadsheet.  Those were the days–if we wanted a post-game WPA graph, we had to do it ourselves :).

I’ve brushed off the cobwebs and published the code.  Click here to see it.

All this does is calculate the win expectancy and volatility (~leverage) in any situation.  It doesn’t calculate WPA on the play.  Of course, if you’re running this on a play-by-play log, it’s trivial to compare the WX of one play and the next.

‘Volatility’ is the difference between the win expectancies that would result from a home run and from a strikeout.  To normalize it so that the average volatility is 1.0, I have this code divide the result by 0.133.  Depending on your dataset, that might not be quite right.  There are more sophisticated ways to measure leverage, though this one is adequate for many purposes.

Thank you Studes, Tango, and others for publishing all that you have.  As is so often the case, I’m just the code monkey.

Advertisements

Comments Off on Python code for WPA stats

%d bloggers like this: