Chapter 23 Exercises: Time Series Analysis for Betting
Instructions: Complete all exercises in the parts assigned by your instructor. Show all work for calculation problems. For programming challenges, include comments explaining your logic and provide sample output. For analysis and research problems, cite your sources where applicable.
Part A: Conceptual Understanding
Each problem is worth 5 points. Answer in complete sentences unless otherwise directed.
Exercise A.1 --- Stationarity in Sports Contexts
Define stationarity in the context of a time series. Then provide three specific examples of sports performance metrics that are likely non-stationary over a full season, and explain the source of non-stationarity in each case (trend, structural break, seasonal pattern, or changing variance).
Exercise A.2 --- ADF vs. KPSS Tests
Explain the fundamental difference between the Augmented Dickey-Fuller (ADF) test and the KPSS test in terms of their null hypotheses. Why is it considered best practice to run both tests when assessing stationarity? Describe a scenario using sports data where the two tests might give contradictory results and what that would imply.
Exercise A.3 --- AR, MA, and ARIMA Intuition
In plain language, explain the difference between an autoregressive (AR) process and a moving average (MA) process. For each, give a concrete sports example where that model structure would be appropriate. Then explain why the integrated (I) component is necessary in ARIMA and what differencing accomplishes.
Exercise A.4 --- Mean Reversion in Betting Strategy
A team starts the NFL season 1-4 against the spread (ATS). A bettor argues that the team is "due" to cover soon because of mean reversion. Evaluate this argument. Under what conditions is mean reversion a valid basis for a betting strategy, and under what conditions is it a logical fallacy (the gambler's fallacy)? Reference the Ornstein-Uhlenbeck process in your answer.
Exercise A.5 --- Changepoint Detection Applications
Identify five specific real-world events in professional sports that would constitute changepoints in a team's performance time series. For each event, explain whether you would expect the changepoint to be (a) abrupt or gradual, (b) temporary or permanent, and (c) detectable in real time or only in retrospect. Discuss the implications for betting strategy timing.
Exercise A.6 --- Seasonal Patterns and Calendar Effects
Describe the concept of a calendar effect in sports betting. Identify three specific calendar effects that have been documented in the literature (e.g., day-of-week, back-to-back games, post-bye performance). For each, explain the hypothesized mechanism and discuss whether the effect is likely to persist once widely known.
Exercise A.7 --- ACF and PACF Interpretation
You compute the autocorrelation function (ACF) and partial autocorrelation function (PACF) for a weekly team scoring margin series. The ACF shows significant positive autocorrelation at lags 1 through 4, decaying gradually. The PACF shows a single significant spike at lag 1 and insignificant values at all subsequent lags. What ARIMA model order does this suggest, and why? Sketch hypothetical ACF and PACF plots that would suggest an MA(2) model instead.
Exercise A.8 --- Forecasting vs. Backtesting Pitfalls
A modeler fits an ARIMA model to five seasons of NFL team point differentials and reports excellent in-sample R-squared. Explain three specific pitfalls of this approach that could lead to poor out-of-sample betting performance. Describe how you would properly backtest a time series model for use in a betting system, including the concept of expanding or rolling windows.
Part B: Calculations
Each problem is worth 5 points. Show all work and round final answers to the indicated precision.
Exercise B.1 --- Stationarity Test Interpretation
An ADF test on a 100-game series of NBA team scoring margins yields a test statistic of -3.52, with critical values of -3.50 (1%), -2.89 (5%), and -2.58 (10%). A KPSS test on the same series yields a test statistic of 0.38, with critical values of 0.74 (1%), 0.46 (5%), and 0.35 (10%).
(a) State the conclusion of the ADF test at the 5% significance level.
(b) State the conclusion of the KPSS test at the 5% significance level.
(c) State the conclusion of the KPSS test at the 10% significance level.
(d) What is the overall assessment of stationarity for this series? Explain any ambiguity.
Exercise B.2 --- ARIMA Model Forecasting
A fitted ARIMA(1,0,0) model for weekly team scoring margin has the form:
$$X_t = 2.5 + 0.6 X_{t-1} + \varepsilon_t$$
where $\varepsilon_t \sim N(0, \sigma^2 = 16)$.
(a) If the team's scoring margin last week was $X_{t-1} = 8$, compute the one-step-ahead forecast $\hat{X}_t$.
(b) Compute the 95% prediction interval for $\hat{X}_t$.
(c) Compute the two-step-ahead forecast $\hat{X}_{t+1}$.
(d) What is the long-run (unconditional) mean of this process? Show the derivation.
Exercise B.3 --- Mean Reversion Half-Life
An Ornstein-Uhlenbeck (OU) process for NFL team passing yards per game has the estimated parameters: $\theta = 0.15$ (mean reversion speed), $\mu = 230$ (long-run mean), and $\sigma = 18$ (volatility).
(a) Calculate the half-life of mean reversion (in weeks). Use the formula: half-life = $\ln(2) / \theta$.
(b) If a team is currently averaging 270 passing yards per game, what does the OU model predict their average will be in 4 weeks?
(c) After how many weeks will the team's expected average be within 5 yards of the long-run mean?
(d) Explain how a bettor could use this half-life information to time bets on passing-related props or totals.
Exercise B.4 --- Seasonal Decomposition
A weekly NBA team scoring series over a full 82-game season has been decomposed into trend, seasonal, and residual components using STL decomposition. The following values are observed for Week 20:
- Observed value: 112.4 points per game
- Trend component: 108.0
- Seasonal component: +3.2
- Residual: ?
(a) Calculate the residual for Week 20.
(b) If the trend has been increasing by 0.5 points per week and the seasonal pattern repeats, what is the expected value for Week 21 if the seasonal component at Week 21 is -1.1?
(c) The residual standard deviation over the full season is 4.8. Is the Week 20 residual significant at the 2-sigma level?
(d) What might a large positive residual indicate about a team's recent performance relative to its underlying trend?
Exercise B.5 --- CUSUM Changepoint Calculation
A team's game-by-game scoring margins over 10 games are: [3, 5, 2, -1, -8, -12, -7, -10, -6, -9]. The overall mean is -4.3.
(a) Compute the cumulative sum (CUSUM) statistic $S_k = \sum_{i=1}^{k}(x_i - \bar{x})$ for each $k$ from 1 to 10.
(b) Identify the game at which the CUSUM reaches its maximum absolute value. This is the estimated changepoint.
(c) Calculate the mean scoring margin before and after the identified changepoint.
(d) Perform a two-sample t-test to determine whether the difference in means is statistically significant. Use the appropriate degrees of freedom and report the p-value range.
Exercise B.6 --- SARIMA Model Identification
A weekly NBA team performance series spanning three seasons (approximately 246 observations) shows:
- Strong autocorrelation at lags 1, 2, and 3 in the ACF, with a slow decay
- PACF significant at lag 1 only (non-seasonal)
- ACF spikes at lags 82 and 164 (seasonal period = 82 games)
- PACF spike at lag 82 only (seasonal)
(a) What seasonal ARIMA order SARIMA(p,d,q)(P,D,Q)[s] would you propose? Justify each component.
(b) The series fails the ADF test at the 5% level. What differencing would you apply?
(c) After first differencing, the seasonal spikes remain but the non-seasonal decay disappears. Revise your proposed model.
(d) Explain why modeling the seasonal component is important even though an NBA season does not have traditional "seasons" like weather data.
Exercise B.7 --- Forecast Evaluation Metrics
A time series model produces the following predictions versus actual outcomes over 8 games:
| Game | Predicted | Actual |
|---|---|---|
| 1 | 4.5 | 7 |
| 2 | 3.2 | -2 |
| 3 | 5.1 | 6 |
| 4 | -1.0 | -4 |
| 5 | 2.8 | 3 |
| 6 | 4.0 | 8 |
| 7 | -2.5 | -1 |
| 8 | 1.5 | 2 |
(a) Calculate the Mean Absolute Error (MAE).
(b) Calculate the Root Mean Squared Error (RMSE).
(c) Calculate the Mean Error (ME / bias). Is the model systematically over- or under-predicting?
(d) A naive benchmark that always predicts the historical mean (2.375) achieves an RMSE of 4.12. Calculate the RMSE skill score relative to this benchmark.
Part C: Programming Challenges
Each problem is worth 10 points. Write clean, well-documented Python code. Include docstrings, type hints, and at least three test cases per function.
Exercise C.1 --- Stationarity Testing Suite
Write a Python module that takes a pandas Series of sports performance data and returns a comprehensive stationarity report:
def stationarity_report(series: pd.Series, significance: float = 0.05) -> dict:
"""
Run ADF and KPSS tests, return a stationarity assessment.
Returns:
Dictionary with 'adf_statistic', 'adf_pvalue', 'kpss_statistic',
'kpss_pvalue', 'is_stationary_adf', 'is_stationary_kpss',
'overall_assessment', and 'recommendation' (e.g., 'difference once').
"""
Include rolling mean and rolling standard deviation plots to visually assess stationarity. Test on simulated stationary and non-stationary sports data.
Exercise C.2 --- ARIMA Model Selection Pipeline
Write a Python function that automates ARIMA model selection for a sports time series:
def select_arima(
series: pd.Series,
max_p: int = 5,
max_d: int = 2,
max_q: int = 5,
criterion: str = "aic"
) -> dict:
"""
Test all ARIMA(p,d,q) combinations up to the specified maxima.
Returns:
Dictionary with 'best_order', 'best_criterion_value',
'model_summary', 'residual_diagnostics', and 'all_results' DataFrame.
"""
Include residual diagnostic checks (Ljung-Box test, normality test). Demonstrate on a real or simulated NBA team scoring margin series.
Exercise C.3 --- Mean Reversion Estimator
Write a Python class that estimates mean reversion parameters from sports data:
class MeanReversionEstimator:
def __init__(self, series: pd.Series, frequency: str = "weekly"):
"""Initialize with a time series and sampling frequency."""
def fit_ou_process(self) -> dict:
"""Fit an Ornstein-Uhlenbeck process. Return theta, mu, sigma."""
def half_life(self) -> float:
"""Return the half-life of mean reversion in the series' time units."""
def predict(self, current_value: float, horizons: list[int]) -> pd.DataFrame:
"""Predict expected values at multiple future horizons."""
def plot_reversion_path(self, current_value: float, max_horizon: int = 20) -> None:
"""Plot the expected reversion path with confidence bands."""
Test on multiple sports metrics (scoring margin, three-point percentage, rushing yards) and compare half-lives across metrics.
Exercise C.4 --- Changepoint Detection System
Write a Python module that implements multiple changepoint detection methods:
def detect_changepoints(
series: pd.Series,
method: str = "pelt",
min_segment_length: int = 5,
significance: float = 0.05
) -> dict:
"""
Detect changepoints using the specified method ('pelt', 'binseg', 'bocpd').
Returns:
Dictionary with 'changepoints' (list of indices), 'segment_means',
'segment_stds', 'confidence_scores', and 'method_used'.
"""
Include visualization of the detected changepoints overlaid on the original series. Test on synthetic data with known changepoints and on real NBA team performance data around the trade deadline.
Exercise C.5 --- Calendar Effect Analyzer
Write a Python class that systematically tests for calendar effects in sports betting data:
class CalendarEffectAnalyzer:
def __init__(self, games_df: pd.DataFrame):
"""Initialize with a DataFrame containing game dates, results, and spreads."""
def test_day_of_week(self) -> dict:
"""Test for day-of-week effects on ATS performance."""
def test_rest_days(self) -> dict:
"""Test for rest-day effects (back-to-back, extra rest, etc.)."""
def test_monthly_patterns(self) -> dict:
"""Test for monthly performance patterns (early season, late season, etc.)."""
def test_post_break(self, break_type: str = "all_star") -> dict:
"""Test for performance changes after scheduled breaks."""
def summary_report(self) -> pd.DataFrame:
"""Generate a summary table of all calendar effects with effect sizes and p-values."""
Include multiple comparison corrections (Bonferroni, Holm) and effect size measures (Cohen's d). Demonstrate on a multi-season NBA dataset.
Part D: Analysis & Interpretation
Each problem is worth 5 points. Provide structured, well-reasoned responses.
Exercise D.1 --- Interpreting a Real Changepoint
During the 2023-24 NBA season, the Oklahoma City Thunder were 15-12 through 27 games, then went 42-3 over the final 45 games. Analyze this as a time series changepoint problem:
(a) What time series method would be most appropriate to detect this shift, and why?
(b) What are the most likely real-world explanations for this changepoint?
(c) How could a bettor have identified this shift early and profited from it?
(d) If lines continued to reflect the team's early-season record for several weeks after the changepoint, estimate the approximate ATS edge a bettor could have captured.
Exercise D.2 --- Mean Reversion Strategy Design
Design a complete mean reversion betting strategy for NFL team ATS performance:
(a) What metric would you use as the basis for mean reversion bets, and what is the empirical evidence that it mean-reverts?
(b) How would you estimate the parameters of the mean reversion process (speed, long-run mean)?
(c) Describe the specific entry and exit criteria for bets. When would you bet for a team and when against?
(d) How would you backtest this strategy while avoiding look-ahead bias? Describe the exact procedure.
(e) What are the primary risks of this strategy, and how would you mitigate them?
Exercise D.3 --- ARIMA Forecast vs. Market Line
You have built an ARIMA(2,1,1) model for a college football team's game-by-game scoring margins. Your model forecasts the team to win by 10.5 points in their next game, with a 95% prediction interval of [1.2, 19.8]. The sportsbook line is Team -7.5.
(a) Does your model suggest value on the team or the opponent? Explain using the point estimate and the prediction interval.
(b) What is the approximate probability your model assigns to the team covering the -7.5 spread? (Assume the forecast error is normally distributed.)
(c) Convert this probability to implied odds and compare to the sportsbook's standard -110/-110 line. Is this a positive EV bet?
(d) Your model's 95% prediction interval spans 18.6 points. Is this level of uncertainty concerning for a betting application? What does it tell you about the practical utility of point estimates from time series models?
Exercise D.4 --- Seasonal ARIMA for Season Win Totals
A sportsbook posts an NBA team's season win total at Over/Under 48.5. You want to use time series analysis to evaluate this bet.
(a) What data would you need, and at what point in the season would a time series approach become useful?
(b) Describe how you would use a rolling ARIMA model updated after each game to generate a running win total projection.
(c) At what point during the season would you expect the ARIMA projection to diverge significantly from the pre-season line, creating potential betting value?
(d) What are the limitations of using ARIMA for this purpose compared to a game-by-game simulation approach?
Exercise D.5 --- Comparing Time Series Methods
You are modeling an NFL team's weekly offensive yards per play. Compare the following three approaches and recommend one:
(a) Exponential smoothing (ETS) with weekly updates.
(b) ARIMA(1,0,0) with the most recent 16 games as the training window.
(c) Ornstein-Uhlenbeck process with parameters estimated from three seasons of data.
For each approach, discuss the advantages, disadvantages, data requirements, and assumptions. Under what conditions would each be the best choice?
Part E: Research & Extension
Each problem is worth 5 points. These require independent research beyond Chapter 23. Cite all sources.
Exercise E.1 --- State-Space Models for Sports
Research state-space models (also called dynamic linear models or DLMs) and their application to sports prediction. Write a report covering:
(a) How state-space models differ from standard ARIMA in their representation of time-varying parameters.
(b) At least two published papers that apply state-space models to sports data.
(c) How the Kalman filter is used for online updating of team strength estimates.
(d) A comparison of the strengths and weaknesses of state-space approaches versus the methods covered in Chapter 23.
(e) A sketch (pseudocode or mathematical formulation) of a simple state-space model for tracking an NFL team's offensive strength over a season.
Exercise E.2 --- Vector Autoregression for Multi-Team Systems
Research Vector Autoregression (VAR) models and their potential application in sports betting:
(a) Explain how a VAR model differs from a univariate ARIMA model.
(b) Describe a scenario where modeling the joint dynamics of two or more teams' performance would be valuable for betting.
(c) Discuss the curse of dimensionality in VAR: how many parameters must be estimated in a VAR(1) model with 30 NBA teams?
(d) Propose a dimensionality reduction approach that makes VAR feasible for a full league (e.g., grouping teams, using factor models).
(e) Implement a simple VAR(1) model for two rival teams' scoring margins and interpret the Granger causality tests.
Exercise E.3 --- GARCH Models for Sports Volatility
Research GARCH (Generalized Autoregressive Conditional Heteroskedasticity) models and their application to sports betting:
(a) Explain what GARCH models capture that ARIMA models do not.
(b) Why might the volatility of a sports metric (not just its level) be important for betting?
(c) Describe how GARCH could be used to model the changing variance of NFL game totals over a season.
(d) Fit a GARCH(1,1) model to a simulated or real sports data series and interpret the parameters.
(e) Discuss how volatility forecasts from GARCH could inform bet sizing (not just bet selection).
Exercise E.4 --- Bayesian Structural Time Series
Research Bayesian Structural Time Series (BSTS) methods, particularly the CausalImpact framework:
(a) Describe the BSTS model structure and how it handles trend, seasonality, and regression components simultaneously.
(b) How does CausalImpact differ from traditional changepoint detection?
(c) Propose a specific sports betting application where CausalImpact would be more appropriate than the changepoint methods in Chapter 23.
(d) Discuss the Bayesian advantages: automatic uncertainty quantification, prior specification for regularization, and model averaging.
(e) Implement a simple BSTS model for a sports series using Python's tfp (TensorFlow Probability) or pymc library.
Exercise E.5 --- Machine Learning for Time Series Forecasting
Research modern machine learning approaches to time series forecasting and compare them to classical methods:
(a) Describe how LSTMs (Long Short-Term Memory networks) and Transformer-based models approach time series forecasting differently from ARIMA.
(b) Summarize at least two published papers comparing ML and classical methods for sports prediction.
(c) Under what conditions do ML methods outperform ARIMA for sports time series? When does ARIMA remain competitive?
(d) Discuss the overfitting risks of ML time series models when applied to small sports datasets (one season of weekly data = ~16-82 observations).
(e) Propose a hybrid approach that combines the strengths of ARIMA and ML for a specific sports betting application.
Scoring Guide
| Part | Problems | Points Each | Total Points |
|---|---|---|---|
| A: Conceptual Understanding | 8 | 5 | 40 |
| B: Calculations | 7 | 5 | 35 |
| C: Programming Challenges | 5 | 10 | 50 |
| D: Analysis & Interpretation | 5 | 5 | 25 |
| E: Research & Extension | 5 | 5 | 25 |
| Total | 30 | --- | 175 |
Grading Criteria
Part A (Conceptual): Full credit requires clear, accurate explanations that demonstrate understanding of time series theory and its application to sports betting. Partial credit for incomplete but correct reasoning.
Part B (Calculations): Full credit requires correct final answers with all work shown. Partial credit for correct methodology with arithmetic errors.
Part C (Programming): Graded on correctness (40%), code quality and documentation (30%), and test coverage (30%). Code must execute without errors.
Part D (Analysis): Graded on analytical depth, logical reasoning, and appropriate application of chapter concepts. Multiple valid approaches may exist.
Part E (Research): Graded on research quality, source credibility, analytical depth, and clear writing. Minimum source requirements specified per problem.
Solutions: Complete worked solutions for all exercises are available in
code/exercise-solutions.py. For programming challenges, reference implementations are provided in thecode/directory.