Created
August 30, 2019 20:00
-
-
Save gnmerritt/4e8dc99e00e52bcb39f88c271e9e5883 to your computer and use it in GitHub Desktop.
EV is a lie
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
import statistics | |
random.seed("FOOBAR") | |
def won_round(): | |
return random.choice([True, False]) | |
START = 10 | |
WIN = 1.5 | |
LOSE = 0.6 | |
PER_TRIAL = 1000 | |
TRIALS = 100 | |
def trial(win=WIN, lose=LOSE): | |
bankroll = START | |
for _ in range(0, PER_TRIAL): | |
if won_round(): | |
bankroll *= win | |
else: | |
bankroll *= lose | |
return bankroll | |
print(f"running 50/50 bet with win={WIN}, lose={LOSE}, bankroll starting at {START}") | |
ev = .5 * (WIN + LOSE) | |
print(f"EV per round = .5 * {WIN} + .5 * {LOSE} = {ev}") | |
print(f"EV across {PER_TRIAL} rounds = start * {ev}**{PER_TRIAL} = {START * ev**PER_TRIAL}") | |
print("") | |
last_mean = -1 | |
num_trials = TRIALS | |
trials = [] | |
while last_mean < 0: | |
trials = trials + [trial() for _ in range(0, num_trials - len(trials))] | |
print(f"after {num_trials} trials") | |
print(f" min = {min(trials)}, max = {max(trials)}") | |
last_mean = statistics.mean(trials) | |
print(f" mean = {last_mean}, median = {statistics.median(trials)}") | |
try: | |
print(f" mode = {statistics.mode(trials)}") | |
except statistics.StatisticsError: | |
pass | |
print("") | |
num_trials *= 10 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment