import numpy as np
import random
def averaged_run_stats(total_runs, starting_cash, trade_size, payout, accuracy):
total_bankruptcies = 0
average_nonbankrupt_cash = 0
for i in range(total_runs):
cash = starting_cash
bankrupt = False
for j in range(1000):
if(cash < trade_size):
total_bankruptcies += 1
bankrupt = True
break
cash -= trade_size
if(random.random() <= accuracy):
cash += trade_size + trade_size * payout
if(not bankrupt):
average_nonbankrupt_cash += cash
return total_bankruptcies, average_nonbankrupt_cash/total_runs/1000
print("payouts %:")
print(np.arange(0.6, 0.8,0.025)*100)
for accuracy in np.arange(0.54, 0.78,0.02): # 12 steps of accuracy from 54% to 76%
print(str(accuracy*100)+"% ", end=": ")
for payout in np.arange(0.6, 0.8,0.025):
runs = 100000
res = averaged_run_stats(runs, 250, 24, payout, accuracy)
print(str(res[0]/runs*100) + "", end = ",")
print()
print("\n")
print("payouts %:")
print(np.arange(0.6, 0.8,0.025)*100)
for accuracy in np.arange(0.54, 0.78,0.02): # 12 steps of accuracy from 54% to 76%
print(str(accuracy*100)+"% ", end=": ")
for payout in np.arange(0.6, 0.8,0.025):
runs = 100000
res = averaged_run_stats(runs, 250, 24, payout, accuracy)
print(str(res[1]) + "", end = ",")
print()