Skip to content

Instantly share code, notes, and snippets.

@Mortal
Created May 7, 2019 16:05
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 Mortal/9037b271a96ab64e1ad2375bde88df84 to your computer and use it in GitHub Desktop.
Save Mortal/9037b271a96ab64e1ad2375bde88df84 to your computer and use it in GitHub Desktop.
"""
Suppose the better places a bet of one dollar and wins x dollars with probability p;
with probability 1-p the bookmaker keeps the one dollar.
The expected profit for the bookmaker is (1-p) - x p
= 1 - p (1 + x)
If we want the profit greater than zero, the odds x must be
1 - p (1 + x) > 0
1 > p (1 + x)
1 / p > (1 + x)
x < (1/p) - 1
The probability, given the odds x, must be
1 - p (1 + x) > 0
1 > p (1 + x)
p < 1 / (1 + x)
"""
# From https://da.wikipedia.org/wiki/Partibogstav
names = dict(
A="Socialdemokratiet",
B="Radikale Venstre",
C="Det Konservative Folkeparti",
D="Nye Borgerlige",
E="Klaus Riskær Pedersen",
F="Socialistisk Folkeparti",
I="Liberal Alliance",
K="Kristendemokraterne,",
O="Dansk Folkeparti",
P="Stram Kurs",
V="Venstre",
Ø="Enhedslisten",
Å="Alternativet",
)
# Source: Danske Spil, retrieved 2019-05-07
# https://danskespil.dk/oddset/politik/danmark/dansk-politik/n%C3%A6ste-regering-efter-folketingsvalget-1278243.html
odds = dict(
A=1.55,
AF=8.00,
AFB=13.00,
AB=15.00,
VC=20.00,
VCO=22.00,
AO=22.00,
VO=28.00,
VLC=28.00,
V=28.00,
VA=28.00,
AFØ=40.00,
AFØBÅ=40.00,
VOCID=75.00,
)
result = []
for letter, name in sorted(names.items()):
is_in = []
is_out = []
for combination, x in odds.items():
if letter in combination:
is_in.append(x)
else:
is_out.append(x)
in_prob = sum(1 / (1 + x) for x in is_in)
out_prob = sum(1 / (1 + x) for x in is_out)
sum_of_odds = sum(is_in)
result.append((in_prob, out_prob, letter, sum_of_odds))
result.sort(reverse=True)
for in_prob, out_prob, letter, sum_of_odds in result:
print("%s inde: %.2f%%" % (letter, in_prob * 100))
assert result == [
(0.7639380525799134, 0.2077034790875239, "A", 167.55),
(0.24218623770821357, 0.7294552939592238, "V", 229.0),
(0.23132017034456057, 0.7403213613228766, "F", 101.0),
(0.15831881533101044, 0.8133227163364268, "B", 68.0),
(0.13873796184614456, 0.8329035698212927, "C", 145.0),
(0.1345971750966622, 0.8370443565707751, "O", 147.0),
(0.04878048780487805, 0.9228610438625592, "Ø", 80.0),
(0.024390243902439025, 0.9472512877649982, "Å", 40.0),
(0.013157894736842105, 0.9584836369305951, "I", 75.0),
(0.013157894736842105, 0.9584836369305951, "D", 75.0),
(0, 0.9716415316674373, "P", 0),
(0, 0.9716415316674373, "K", 0),
(0, 0.9716415316674373, "E", 0),
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment