STAT-API
← NBA Cookbook

Compare NBA Common Random Numbers spread overrides

Reusing the same `seed` across baseline and what-if runs applies Common Random Numbers (CRN), isolating the exact effect of changing `home_spread` from market noise.

What it is
Runs two NBA simulations on game `6029936` with identical `seed: 42` — market baseline vs `home_spread: -8.5` — to measure pure pricing sensitivity.
When to use it
Use this when modeling alternate spread lines, injury market reactions, or correlated game script shifts without Monte Carlo sampling noise.
What you get back
Side-by-side baseline vs override totals, home win probabilities, simulated margins, and the exact causal delta.

1.Run the market baseline simulation (seed 42)

Simulate 200 draws on game `6029936` without market overrides.

POST request (requires your API key in STAT_API_KEY). Run the SDK program on the right or the curl snippet below.

{
  "game_id": 6029936,
  "n_draws": 200,
  "seed": 42,
  "include": {
    "summary": true,
    "distributions": false,
    "scorebox": false,
    "pbp": false,
    "scenarios": false,
    "simulations": false
  }
}
const baseline = await api.sim.nba.run({ game_id: 6029936, n_draws: 200, seed: 42, include: { summary: true, distributions: false, scorebox: false, pbp: false, scenarios: false, simulations: false } })

Every step as one runnable file. It reads STAT_API_KEY from the environment, and is the same file that ships in the cookbook project for each SDK.

import { StatApi } from '@stat-api/client'

const api = new StatApi() // reads STAT_API_KEY from the environment

// Run the market baseline simulation (seed 42)
const baseline = await api.sim.nba.run({ game_id: 6029936, n_draws: 200, seed: 42, include: { summary: true, distributions: false, scorebox: false, pbp: false, scenarios: false, simulations: false } })

// Re-simulate with an alternate home spread (-8.5, seed 42)
const shifted = await api.sim.nba.run({ game_id: 6029936, n_draws: 200, seed: 42, include: { summary: true, distributions: false, scorebox: false, pbp: false, scenarios: false, simulations: false }, home_spread: -8.5 })

// Print the CRN sensitivity delta
const baseS = baseline.output.summary
const overS = shifted.output.summary
if (!baseS || !overS) throw new Error('missing summary')
const _nz = (v: number) => (Math.abs(v) < 0.005 ? 0 : v)
console.log(`Baseline total=${baseS.sim_total_mean.toFixed(2)} home_win_pct=${(baseS.home_win_prob * 100).toFixed(2)}% spread_home=${baseS.sim_spread_home_mean.toFixed(2)}`)
console.log(`Override total=${overS.sim_total_mean.toFixed(2)} home_win_pct=${(overS.home_win_prob * 100).toFixed(2)}% spread_home=${overS.sim_spread_home_mean.toFixed(2)}`)
console.log(`Delta total=${_nz(overS.sim_total_mean - baseS.sim_total_mean).toFixed(2)} home_win_pp=${_nz((overS.home_win_prob - baseS.home_win_prob) * 100).toFixed(2)}`)

Verified output across all 4 SDKs

TypeScript, Python, Go, and Java execute cleanly and print byte-identical output:

Baseline total=220.41 home_win_pct=43.50% spread_home=1.50
Override total=220.58 home_win_pct=77.00% spread_home=-8.56
Delta total=0.17 home_win_pp=33.50