Created
June 18, 2016 05:19
-
-
Save jtoomim/6a130f4400d7c7cc1d5916cc22d5c09a to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
def get_reward(shares): | |
return shares[0] / float(1+sum(shares[1:])) | |
def run_sim(low, high, N): | |
# preload the share chain | |
shares = [random.randint(low, high) for i in range(N)] | |
# add shares and sum the expected revenue from each | |
revenue = 0. | |
for i in range(N): | |
revenue += get_reward(shares) | |
shares.pop() | |
shares.insert(0, random.randint(low, high)) | |
return revenue | |
if __name__ == "__main__": | |
for i in range(10): | |
print run_sim(1,10,2016) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment