Skip to content

rohans11/mlb-forecasting

Repository files navigation

MLB Outcome Forecasting & Sequential Risk Modeling

A Monte Carlo framework for probabilistic forecasting of MLB game outcomes — a pitcher-adjusted Elo model, recalibrated and validated against real out-of-sample results — with an application to sequential decision-making and capital allocation under uncertainty (Kelly vs flat sizing).

Suggested repo name: mlb-forecasting or monte-carlo-risk-modeling.

The point of the project is the modeling and validation methodology; the capital-allocation study is one application of it. Everything below applies to any domain with probabilistic forecasts and a market price, not just sports.

Methods

  • Forecast model — pitcher-adjusted Elo (538-style: the starting pitcher's rating enters both the win-probability prediction and the rating update, so team strength is isolated from starter quality). Features: team strength, home advantage, margin of victory, and starting-pitcher quality from prior-season FIP (shrunk toward league mean for small samples).
  • Calibration — isotonic / Platt recalibration of the raw model, validated out of time on a held-out season. The run prints Brier score, log-loss, and a reliability table.
  • Monte Carlo engine — moving-block bootstrap (preserves schedule/streak autocorrelation), per-replication parameter perturbation (the probability estimate is itself uncertain), common random numbers (the two allocation strategies see identical scenarios, giving a clean paired comparison), and Monte Carlo standard errors plus a convergence table on every reported statistic.
  • Market model & closing-price value (CLV) — outcomes are priced with a realistic margin (overround) and an opening/closing price gap; CLV (beating the closing price) is the standard out-of-sample test of whether a forecast actually has signal against an efficient market.

What this is — and isn't

  • Calibration is not predictive edge. Well-calibrated probabilities mean your 58% forecasts occur ~58% of the time. Outperforming a market additionally requires your probability to differ from the market-implied probability by more than its margin — a much higher bar.
  • The capital-trajectory charts are conditional scenario analysis. In the forward simulation, outcomes are drawn from the model's own probabilities, so they answer "if the model is exactly right, how does capital evolve?" Real models are miscalibrated in ways out-of-sample validation underestimates, so the reported risk_of_ruin is optimistic.
  • Sports-market prices are efficient. A team-Elo + starter model rarely beats the closing price consistently. Treat a positive simulated result as a hypothesis to test, not a result.

Limitations & highest-value next steps

  • Pitcher coverage depends on data availability. Historical schedules often omit probable starters, so on past seasons the pitcher term may be largely inactive (the run prints coverage and warns when it's low). The rigorous fix: pull the actual starter from each game's boxscore, cache to disk, and key FIP off the starter's MLB id.
  • Prior-season FIP ignores current form and rookies — blend a preseason projection with an in-season rolling estimate (Marcel / ZiPS / 538 style).
  • No park, weather, bullpen, rest, or lineup features — each is a real lever on calibration.
  • For an honest historical evaluation, add a walk-forward backtest that replays real games with realized outcomes and real closing prices, evaluated primarily on CLV.

Usage

pip install -r requirements.txt
python main.py

Calibration pulls real results from MLB-StatsAPI (needs internet) and pitcher FIP from pybaseball. The market-price source defaults to a synthetic fallback so the pipeline runs end-to-end; set odds_source="csv" (columns date,home,away,home_close_decimal, away_close_decimal, optional *_open_decimal to enable real CLV) or odds_source="theoddsapi" (export ODDS_API_KEY=...) for real prices. Use full team names (e.g. "New York Yankees") to match StatsAPI.

Project layout

config.py (parameters) · probability.py (calibration + metrics) · data.py (Elo, real data, pitcher ratings) · market.py (price model + CLV) · allocation.py (Kelly / flat sizing) · simulator.py (Monte Carlo) · analysis.py (statistics) · main.py (entry point).

Note on the sports-market application

This is a quantitative modeling and educational project. The capital-allocation component is demonstrated on sports-market prices; it is not financial or wagering advice.

About

Monte Carlo probabilistic forecasting and risk modeling, applied to MLB outcomes

Resources

License

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages