Skip to content

Instantly share code, notes, and snippets.

@dooglus
Created February 3, 2016 07:35
Show Gist options
  • Save dooglus/1426a596d59b722d3312 to your computer and use it in GitHub Desktop.
Save dooglus/1426a596d59b722d3312 to your computer and use it in GitHub Desktop.
import random, math
num_sims = 1000
num_rolls = 1000
chance = 5/100.0
edge = 1 - 2*chance
start_bank = 1000
risk = 0
while risk < 1:
sim_count = 0
sum_log_banks = 0
while sim_count < num_sims:
bank = start_bank
roll_count = 0
while roll_count < num_rolls:
if random.random() < chance:
bank *= (1-risk)
else:
bank *= (1+risk)
roll_count += 1
sum_log_banks += math.log(bank/start_bank)
sim_count += 1
print risk, sum_log_banks / sim_count
risk += 0.01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment