Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from random import randint
- """
- Written by Nick Bowling
- I made this simulation based on just 3 simple equations:
- l-d = b
- b/l = p
- k = m * (2*p - 1)
- Where:
- l = length of boundary space in one dimension
- d = diameter of circular object in one dimension
- b = length of space where center of circular object can
- exist, in one dimension, without crossing the boundary space
- p = probability that circular object will randomly appear without
- crossing the boundary space
- m = your current betting bankroll
- k = Kelly equation, used to compute the amount of your bankroll you
- should bet to maximize your return in a long term, multiple,
- betting situation
- """
- #Initial Parameters:
- # length of each side of hypercube is 10
- # length of diameter of hypersphere is 4
- # Volume of hypercube = 10^4
- # Volume of hypersphere's hypercube boundary = 4^4
- inside = [] # Volume where center of hypersphere can exist while
- # keeping hypersphere in bounds of hypercube = 10^4-4^4 = 6^4
- outside = [] # Volume where center of hypersphere can exist where
- # edge of hypersphere crosses boundary of hypercube = 10^4-6^4
- # Ratio of center inside volume to hypercube volume is 6^4/10^4 = 81/625
- # Probability that hypersphere will not cross boundary of hypercube is p = 12.96%
- coin_in = 0
- coin_out = 0
- money = 0
- count = 0
- for i in range(1, 82): # Produces number list for volumes
- inside.append(i)
- for i in range(82, 626):
- outside.append(i)
- def coin(z):
- global count
- global coin_in
- global coin_out
- global money
- money = float(bank_roll)
- wager = money * (2 * 0.8704 - 1) # 2*(1-p)-1 <--Kelly equation betting that hypersphere
- # will cross hypercube boundary
- for i in range(int(z)):
- count += 1
- wager = money * (2 * 0.8704 - 1)
- x = randint(1, 625) # Creates random placement of center of hypersphere inside
- if x in inside: # hypercube
- coin_in += 1
- money -= wager
- elif x in outside:
- coin_out += 1
- money += wager # Makes a bet that hypersphere WILL cross boundary of hypercube
- if money < 0:
- break
- print()
- print()
- print('This program will simulate a 4^4 hypersphere randomly appearing in a 10^4')
- print('hypercube space, while you bet, in succession, a Kelly amount of your bankroll that the')
- print('hypersphere will cross the boundary of the hypercube space.')
- print()
- print()
- z = input('Number of simulations to run: ')
- print()
- bank_roll = input('How much money do you have to bet with?: $')
- wager1 = float(bank_roll) * 0.7408 # Initial Kelly value based on probability
- print()
- print('Based on the Kelly Criterion you should initially wager 74.08% of your bankroll, which '
- 'is $', float(wager1))
- print()
- print()
- coin(z)
- print('Simulations: ', count) # Number of simulations
- print('Hypersphere inside boundary (lose) :', coin_in) # Number of times hypersphere in bounds of hypercube
- print('Hypersphere crossed boundary (win) :', coin_out) # Number of times hypersphere crossed boundary of hypercube
- money = int(money)
- print('Bankroll : $', money) # Your current bankroll
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement