Advertisement
plasticuproject

coin

Feb 25th, 2018
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.35 KB | None | 0 0
  1. from random import randint
  2. """
  3. Written by Nick Bowling
  4.  
  5. I made this simulation based on just 3 simple equations:
  6.  
  7. l-d = b
  8. b/l = p
  9. k = m * (2*p - 1)
  10.  
  11. Where:
  12.      l = length of boundary space in one dimension
  13.      d = diameter of circular object in one dimension
  14.      b = length of space where center of circular object can
  15.          exist, in one dimension, without crossing the boundary space
  16.      p = probability that circular object will randomly appear without
  17.          crossing the boundary space
  18.      m = your current betting bankroll
  19.      k = Kelly equation, used to compute the amount of your bankroll you
  20.          should bet to maximize your return in a long term, multiple,
  21.          betting situation
  22. """
  23.  
  24. #Initial Parameters:
  25.  
  26.               # length of each side of hypercube is 10
  27.               # length of diameter of hypersphere is 4
  28.  
  29.               # Volume of hypercube = 10^4
  30.               # Volume of hypersphere's hypercube boundary = 4^4
  31.  
  32. inside = []   # Volume where center of hypersphere can exist while
  33.               # keeping hypersphere in bounds of hypercube = 10^4-4^4 = 6^4
  34.  
  35. outside = []  # Volume where center of hypersphere can exist where
  36.               # edge of hypersphere crosses boundary of hypercube = 10^4-6^4
  37.  
  38.  
  39.               # Ratio of center inside volume to hypercube volume is 6^4/10^4 = 81/625
  40.               # Probability that hypersphere will not cross boundary of hypercube is p = 12.96%
  41.  
  42.  
  43. coin_in = 0
  44. coin_out = 0
  45. money = 0
  46. count = 0
  47. for i in range(1, 82):  # Produces number list for volumes
  48.     inside.append(i)
  49. for i in range(82, 626):
  50.     outside.append(i)
  51. def coin(z):
  52.     global count
  53.     global coin_in
  54.     global coin_out
  55.     global money
  56.     money = float(bank_roll)
  57.     wager = money * (2 * 0.8704 - 1)   # 2*(1-p)-1 <--Kelly equation betting that hypersphere
  58.                                        # will cross hypercube boundary
  59.     for i in range(int(z)):
  60.         count += 1
  61.         wager = money * (2 * 0.8704 - 1)
  62.         x = randint(1, 625)  # Creates random placement of center of hypersphere inside
  63.         if x in inside:      # hypercube
  64.             coin_in += 1
  65.             money -= wager
  66.         elif x in outside:
  67.             coin_out += 1
  68.             money += wager  # Makes a bet that hypersphere WILL cross boundary of hypercube
  69.         if money < 0:
  70.             break
  71.  
  72. print()
  73. print()
  74. print('This program will simulate a 4^4 hypersphere randomly appearing in a 10^4')
  75. print('hypercube space, while you bet, in succession, a Kelly amount of your bankroll that the')
  76. print('hypersphere will cross the boundary of the hypercube space.')
  77. print()
  78. print()
  79. z = input('Number of simulations to run: ')
  80. print()
  81. bank_roll = input('How much money do you have to bet with?: $')
  82. wager1 = float(bank_roll) * 0.7408  # Initial Kelly value based on probability
  83. print()
  84. print('Based on the Kelly Criterion you should initially wager 74.08% of your bankroll, which '
  85.       'is $', float(wager1))
  86. print()
  87. print()
  88. coin(z)
  89. print('Simulations: ', count)  # Number of simulations
  90. print('Hypersphere inside boundary (lose) :', coin_in)  # Number of times hypersphere in bounds of hypercube
  91. print('Hypersphere crossed boundary (win) :', coin_out)  # Number of times hypersphere crossed boundary of hypercube
  92. money = int(money)
  93. print('Bankroll : $', money)  # Your current bankroll
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement