Created
May 11, 2020 05:34
-
-
Save nagataka/6319f9082860f003f1ef9ceee58a01a7 to your computer and use it in GitHub Desktop.
Experiment on coin flipping game
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 numpy as np | |
np.random.seed(0) | |
def kerri(p, b): | |
"""https://en.wikipedia.org/wiki/Kelly_criterion | |
""" | |
return (p*(b+1)-1 )/b | |
N = 300 | |
p = 0.6 | |
winning = 0 | |
fund = 25.0 | |
for n in range(N): | |
ratio = kerri(p, 1) | |
bet = fund*ratio | |
#bet = 1 # for fixed betting experiment | |
if winning + bet > 250: | |
bet = 250 - winning # simulate $250 award cap | |
# simulate a coin which shows head 60% | |
if np.random.rand() < p: | |
# Player's win | |
print("Player's win. Got ", bet) | |
winning += bet | |
fund += bet | |
else: | |
print("Player's lose. Lost ", bet) | |
winning -= bet | |
fund -= bet | |
if winning >= 250: | |
print("Winning reward reached at the cap in {}th game. Finish.".format(n)) | |
break | |
print("Total win ${} for skewed coin. Ended with ${}.".format(winning, fund)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment