Welcome to Baseball Sim Engine

Baseball Sim Engine is an open-source baseball simulation engine built to model the game from the pitch up.

I’ve been working on baseball simulations for years. Over time, what started as code for running a fictional baseball league became something much more general: a simulation engine capable of turning player ratings, ballparks, matchups, and game situations into complete baseball games.

Eventually it became clear that the engine itself should be its own project.

So that’s what Baseball Sim Engine is.

A Baseball Game, Not a Box Score Generator

Baseball Sim Engine doesn’t start with a target box score and work backward. It simulates the events that happen during a baseball game and lets the statistics emerge from them.

Games are built from individual interactions between pitchers, hitters, fielders, and runners.

A pitcher throws a pitch. The hitter decides whether to swing. If he swings, he may miss, foul it off, or put it into play. A ball in play has a type, location, and quality of contact. Fielders have an opportunity to turn it into an out. Runners can advance, hold, steal, or be thrown out.

Those events accumulate into plate appearances.

Plate appearances accumulate into innings.

And innings accumulate into baseball games.

The statistics come from what happens in the simulated game.

Players Are More Than a Single Rating

The same idea applies to players.

Hitters aren’t represented by a single number describing how good they are. Their ratings describe different parts of their game, including contact, plate discipline, power, speed, defense, throwing ability, and performance against right- and left-handed pitching.

Pitchers have their own ratings for power, control, movement, handedness splits, and the quality of the pitches they throw.

That gives the engine room to model players who are good in very different ways.

A high-contact hitter and a three-true-outcomes slugger shouldn’t reach the same result through the same process. A power pitcher with shaky control shouldn’t behave like a command pitcher simply because the two happen to have similar overall value.

The differences between players are part of the simulation.

Built Against Real Baseball

Baseball Sim Engine can simulate fictional players, but real Major League Baseball provides an extremely useful test of whether the model actually works.

The project includes tools for turning historical MLB performance into player ratings and running those players through the simulation.

That creates a feedback loop.

Real baseball tells us what happened. The ratings system describes the players who produced it. The simulation then asks whether players with those characteristics can produce baseball that looks like the real thing.

We can compare the results against MLB at both the league and player level: scoring, batting average, on-base percentage, slugging, strikeouts, walks, home runs, balls in play, stolen bases, and much more.

When something is wrong, the goal isn’t simply to patch the final statistic. It’s to find the part of the baseball model that is producing it.

Why Open Source?

Baseball simulation gets much more interesting when you can see how it works.

Baseball Sim Engine is available as a TypeScript library rather than being locked inside a particular game or website. The engine can be used as a foundation for other projects: simulations, leagues, experiments, prediction systems, baseball games, or things I haven’t thought of.

The source code is public, too.

That means the assumptions behind the simulation don’t have to be mysterious. They can be inspected, tested, questioned, and improved.

View on GitHub

What’s Coming Next

This site will document both the engine and the work behind it.

I’ll be writing about how individual plate appearances are simulated, how real MLB statistics are converted into player ratings, how the engine is tested against real baseball, and some of the applications that can be built on top of it.

I’ll also publish player pages showing the ratings generated by the engine alongside the real statistics that produced them.

Baseball is complicated. That’s a large part of what makes trying to simulate it interesting.

Baseball Sim Engine is an attempt to model as much of that complexity as we reasonably can—and to make the result available for other people to use.