Skip to content

Instantly share code, notes, and snippets.

@mharris717
Last active August 29, 2015 14:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mharris717/d67f83289ac5b90ea758 to your computer and use it in GitHub Desktop.
Save mharris717/d67f83289ac5b90ea758 to your computer and use it in GitHub Desktop.
Home Chance
# the home team's win chance for a normal team not at a neutral field
def home_chance_normal(sim_context,away_team_arg,home_team_arg)
# away team dvoa, minus 5% if it's the divisional round
away = sim_context.dvoa(away_team_arg) - home_extra_bonus.to_f
# home team dvoa, capped at 40%
home = [0.40,sim_context.dvoa(home_team_arg)].min
# min_max(-0.35..0.35) restricts the value to between -35% and 35%
# abs_exp(2) squares it and returns the absolute value
# home_cold_bonus adds 0.0957 if a cold weather team hosts a warm weather team in week 13 or later
res = 0.606
- away*0.637
+ home*0.868
+ home.min_max(-0.35..0.35).abs_exp(2)*-1.414
+ home_cold_bonus(sim_context)
res.min_max(0.05..0.95)
end
# handles the special cases (mostly neutral field)
# calls home_chance_normal for almost all games
def home_chance(sim_context)
if home_super_bowl?
home_super_bowl_chance(sim_context)
elsif neutral_field?
# for a neutral field game, get the home win% if we pretend that each team is home
# then average them
regular_chance = home_chance_normal(sim_context,away_team,home_team)
reverse_chance = 1.0-home_chance_normal(sim_context,home_team,away_team)
res = [regular_chance,reverse_chance]
res.sum / 2.0
else
home_chance_normal(sim_context,away_team,home_team)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment