discrete_instance_pi_headstart.py 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import os
  2. import numpy
  3. from core.strategy import *
  4. from core.lottery import *
  5. import matplotlib.pyplot as plt
  6. import scipy.stats as stats
  7. import math
  8. from draw import draw
  9. os.system("rm log/*_feedback.hist; rm log/*_output.hist; rm log/darkie*.log")
  10. RUNNING_TIME = int(input("running time:"))
  11. NODES=1000
  12. PREMINT = 2.1*10**7
  13. if __name__ == "__main__":
  14. mu = PREMINT/NODES
  15. darkies = [Darkie(random.gauss(mu, mu/10), strategy=LinearStrategy(EPOCH_LENGTH)) for _ in range(NODES)]
  16. #dt = DarkfiTable(0, RUNNING_TIME, CONTROLLER_TYPE_DISCRETE, kp=-0.010399999999938556, ki=-0.0365999996461878, kd=0.03840000000000491, r_kp=-2.53, r_ki=29.5, r_kd=53.77)
  17. dt = DarkfiTable(PREMINT, RUNNING_TIME, CONTROLLER_TYPE_DISCRETE, kp=-0.010399999999938556, ki=-0.0365999996461878, kd=0.03840000000000491, r_kp=-0.719, r_ki=1.6, r_kd=0.1)
  18. for darkie in darkies:
  19. dt.add_darkie(darkie)
  20. acc, avg_apy, avg_reward, stake_ratio, avg_apr = dt.background(rand_running_time=False)
  21. #sum_zero_stake = sum([darkie.stake for darkie in darkies[NODES:]])
  22. print('acc: {}, avg(apr): {}%, avg(reward): {}, stake_ratio: {}'.format(acc, round(avg_apr*100,2), avg_reward, stake_ratio))
  23. #print('total stake of 0mint: {}, ratio: {}'.format(sum_zero_stake, sum_zero_stake/ERC20DRK))
  24. dt.write()
  25. aprs = []
  26. fortuners = 0.0
  27. for darkie in darkies:
  28. aprs += [float(darkie.apr_scaled_to_runningtime())]
  29. if darkie.initial_stake[-1] - darkie.initial_stake[0] > 0:
  30. fortuners+=1
  31. print('fortuners: {}'.format(str(fortuners/len(darkies))))
  32. # distribution of aprs
  33. aprs = sorted(aprs)
  34. mu = float(sum(aprs)/len(aprs))
  35. shifted_aprs = [apr - mu for apr in aprs]
  36. plt.plot([round(apr*100,2) for apr in aprs])
  37. plt.title('annual percentage return, avg: {:}'.format(mu*100))
  38. plt.savefig('img/apr_distribution.png')
  39. plt.show()
  40. variance = sum(shifted_aprs)/(len(aprs)-1)
  41. print('mu: {}, variance: {}'.format(str(mu), str(variance)))
  42. draw()