Building a random bettor

For the next season of Fußball-Bundesliga, we’ll use kicktipp for betting on the results, as we have in the previous seasons. This time, we want to introduce additional dummies, ‘Heimsieg’ (home victory) and ‘Zufall’ (randomness), as yardsticks of predictive performance (i. e., if your bets are worse, you should be ashamed).

Of course, for Heimsieg the question is, what exact result should it use (two suggestions are 1:0 and 2:1)? And how should Zufall produce its values? Enter statistics.

Of course, you could just roll dice, subtract one, and use that for the bets, but some results (e. g., 0:5) are rather unlikely to happen in real life. Therefore, the idea is to construct a random bettor which produces results with the same frequencies as historical results.

So I took the results of the last two seasons (Bundesliga 2006/07 and 2007/08) and counted the results (or rather, let the computer do it). A 1:0 is different from a 0:1, of course. There were a total of 612 matches (2 × 34 × 9). Sorted by frequency: 1:1 occured 71 times (11.6%), 1:0 59 times (9.6%), 2:1 57 times (9.3%), 2:0 47 times (7.7%), 0:0 43 times (7.0%), and 1:2, the first loss for the home team, 41 times (6.7%).

The question whether Heimsieg should bet 1:0 or 2:1 is still a matter of taste, as the difference (59 vs. 57 times) is small. For Zufall, the result statistics offer a spectrum which to use for random bets.

Next step would be to predict the results for the next season of Heimsieg and Zufall by running them against the old seasons (with the rule set from kicktipp).

Some comments on programming (after all, this blog is called irgendwasmitcomputern and thus should have a computer angle, at least sometimes):

For counting the occurrences of results, a simple data structure comes handy, the bag (more pompously called multi-set). Python offers dictionaries, which are nearly all you need for a bag (it is amazing what flexibility dictionaries/hashmaps have to offer; Python, JavaScript, Common Lisp are well equipped with them; I can’t understand why Scheme doesn’t establish them in the core language). So, let’s implement a bag in Python:

def bag_add(b, e):
  if e in b: b[e] += 1
  else:     b[e] = 1

bag = {}            # new empty bag
bag_add(bag, (2,1)) # add 2:1 to bag

That’s about it. You see why I love Python’s dictionaries. You just gather all results in the bag; afterwards you have to choose elements randomly, but according to their relative weight (i. e., frequency). Again, this is rather simple:

def bag_choice(b):
  total = sum(b.values())
  r = random.randint(1, total)
  sofar = 0
  for k, v in b.items():
    if sofar < r <= sofar+v: return k
    sofar += v

By the way, Python uses the Mersenne Twister as a random number generator, which is good enough for all practical purposes (with the exception of cryptography, of course). Original paper: M. Matsumoto and T. Nishimura, "Mersenne Twister: A 623-dimensionally equidistributed uniform pseudorandom number generator", ACM Trans. on Modeling and Computer Simulation Vol. 8, No. 1, January pp. 3-30 (1998); also online at www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/ARTICLES/mt.pdf.

About Daniel Tiggemann

Software-developer living in Cologne, Germany. Was once a physicist, specialized in computer simulations and parallel programming. Now more into JavaScript, web frontend development, and especially mobile computing.
This entry was posted in Programming, Randomness, Soccer. Bookmark the permalink.

858 Responses to Building a random bettor

  1. Pingback: medycyna

  2. Pingback: biznes

  3. Pingback: mieszkania

  4. Pingback: Teeter Hang Ups Adapter Kit

  5. Pingback: A1 Chicago Limo Service Airport ORD O'Hare Limo

  6. Pingback: http://youtu.be/zP1HDeLvwEk

  7. Pingback: best water park in Long Island

  8. Pingback: http://youtu.be/_HRGJmevV4o

  9. Pingback: http://youtu.be/v1Nk3_NwZcY

  10. Pingback: Full Article

  11. Pingback: Christians in Politics

  12. Pingback: 4xbiznes.com.pl

  13. Pingback: firmymax.com.pl

  14. Pingback: informatorbiznesu.net.pl

  15. Pingback: profirmy.net.pl

  16. Pingback: tadawul fx

  17. Pingback: paczki dla dzieci

  18. Pingback: paczki dla dzieci

  19. Pingback: Flying When Pregnant

  20. Pingback: palm springs tours

  21. Pingback: how to make money from the internet

  22. Pingback: Reptilienshop

  23. Pingback: ogrzewanie

  24. Pingback: ogrzewanie

  25. Pingback: ogrzewanie

  26. Pingback: herbata

  27. Pingback: herbata

  28. Pingback: herbata

  29. Pingback: herbata

  30. Pingback: ogrzewanie

  31. Pingback: ogrzewanie

  32. Pingback: herbata

  33. Pingback: herbata

  34. Pingback: ogrzewanie

  35. Pingback: herbata

  36. Pingback: forex

  37. Pingback: cialis

  38. Pingback: ways to make money online

  39. Pingback: viagra

  40. Pingback: viagra

  41. Pingback: buy cialis

  42. Pingback: viagra

  43. Pingback: cheap viagra

  44. Pingback: Viagra

  45. Pingback: valium

  46. Pingback: cialis

  47. Pingback: adipex

  48. Pingback: Viagra

  49. Pingback: biznes

  50. Pingback: nieruchomości