brackt/app/services/simulations/ncaam-simulator.ts
chrisp 3e50619629
All checks were successful
🚀 Deploy / 🧪 Test (push) Successful in 3m1s
🚀 Deploy / ʦ🔍 Typecheck & Lint (push) Successful in 1m17s
🚀 Deploy / 🐳 Build (push) Successful in 1m9s
🚀 Deploy / 🚀 Deploy (push) Successful in 11s
claude/probability-config-review-1tdolw (#119)
Co-authored-by: Claude <noreply@anthropic.com>
Reviewed-on: #119
2026-06-30 23:24:48 +00:00

32 lines
1.3 KiB
TypeScript

import { NCAABasketballSimulator } from "./ncaa-basketball-simulator";
import type { Simulator, SimulationResult } from "./types";
import { optionalPositiveNumber } from "./config-access";
const KENPOM_SCALE_FACTOR = 7.5;
/**
* NCAAM neutral-court win probability using a KenPom-like adjusted efficiency
* margin. Ratings are season-scoped simulator inputs, not hardcoded data.
*/
export function kenpomWinProbability(netrtgA: number, netrtgB: number): number {
return 1 / (1 + Math.exp(-(netrtgA - netrtgB) / KENPOM_SCALE_FACTOR));
}
function kenpomWinProbabilityWithScale(scaleFactor: number): (netrtgA: number, netrtgB: number) => number {
return (netrtgA, netrtgB) => 1 / (1 + Math.exp(-(netrtgA - netrtgB) / scaleFactor));
}
export class NCAAMSimulator implements Simulator {
private readonly simulator = new NCAABasketballSimulator({
source: "ncaam_bracket_rating",
missingRatingName: "KenPom-like rating",
selectionRatingDivisor: 8,
winProbability: kenpomWinProbability,
getWinProbability: (config) =>
kenpomWinProbabilityWithScale(optionalPositiveNumber(config.ratingScaleFactor, KENPOM_SCALE_FACTOR)),
});
simulate(sportsSeasonId: string): Promise<SimulationResult[]> {
return this.simulator.simulate(sportsSeasonId);
}
}