Guest User

Untitled

a guest
Jun 13th, 2014
337
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.76 KB | None | 0 0
  1. from matplotlib.pyplot import gcf, legend, plot, savefig, show, title, xlabel, ylabel
  2. import numpy
  3. from numpy import arange, array, cumsum, zeros_like
  4. from numpy.random import random
  5.  
  6. BLOCK_REWARD = 1
  7.  
  8. def difficulties(diff_increase, epochs, length):
  9.     exps = numpy.floor(numpy.linspace(0, epochs, epochs * length, endpoint=False))
  10.     return diff_increase ** exps
  11.  
  12. def payouts(diffs, hashrate, pool_hashrate):
  13.     pool_rewards = random(len(diffs)) < pool_hashrate / diffs
  14.     return hashrate / pool_hashrate * pool_rewards
  15.  
  16. def accumulate(times, hashrate, pool_hashrate, diff_increase, epochs, epoch_length):
  17.     diffs = difficulties(diff_increase, epochs, epoch_length)
  18.     pays = zeros_like(diffs)
  19.     for _ in xrange(times):
  20.         pays += payouts(diffs, hashrate, pool_hashrate)
  21.     return pays / times
  22.  
  23. def plot_cum_payouts(times, hashrate, pool_hashrate, diff_increase, epochs, epoch_length, linetype, label, **plot_kwargs):
  24.     pays = accumulate(times, hashrate, pool_hashrate, diff_increase, epochs, epoch_length)
  25.     cum_pays = cumsum(pays)
  26.     ticks = arange(len(pays))
  27.     plot(ticks, cum_pays, linetype, label=label, **plot_kwargs)
  28.  
  29. def plot_times_cum_payouts(times, hashrate, pool_hashrate, diff_increase, epochs, epoch_length, linetype, label):
  30.     for i in xrange(times):
  31.         label_i = label if i == 0 else None
  32.         plot_cum_payouts(1, hashrate, pool_hashrate, diff_increase, epochs, epoch_length, linetype, label_i)
  33.  
  34. def plot_cloud():
  35.     times = 100
  36.     inverse_hashrate = 1000
  37.     red_pool_percent = 50
  38.     blue_pool_percent = 20
  39.     difficulty_inc_percent = 15
  40.     epochs = 10
  41.     epoch_length = 100
  42.     plot_times_cum_payouts(times, 1.0/inverse_hashrate, red_pool_percent/100.0, (1 + difficulty_inc_percent/100.0), epochs, epoch_length, 'r-', "%d%% pool" % red_pool_percent)
  43.     plot_times_cum_payouts(times, 1.0/inverse_hashrate, blue_pool_percent/100.0, (1 + difficulty_inc_percent/100.0), epochs, epoch_length, 'b-', "%d%% pool" % blue_pool_percent)
  44.     legend(loc='upper left')
  45.     title("{times} earnings simulations: {difficulty_inc_percent}% difficulty increase every {epoch_length} blocks, {block_reward} btc block reward, miner hash rate = 1/{inverse_hashrate} initial network hash rate".format(
  46.         times=times,
  47.         difficulty_inc_percent=difficulty_inc_percent,
  48.         epoch_length=epoch_length,
  49.         block_reward=BLOCK_REWARD,
  50.         inverse_hashrate=inverse_hashrate))
  51.     xlabel('block')
  52.     ylabel('cumulative earnings')
  53.     gcf().set_size_inches(16,12)
  54.     savefig('simulated_pool_variance.png', dpi=50)
  55.     show()
  56.  
  57. def plot_average():
  58.     times = 10000
  59.     inverse_hashrate = 1000
  60.     red_pool_percent = 50
  61.     blue_pool_percent = 20
  62.     difficulty_inc_percent = 15
  63.     epochs = 10
  64.     epoch_length = 100
  65.     plot_cum_payouts(times, 1.0/inverse_hashrate, red_pool_percent/100.0, (1 + difficulty_inc_percent/100.0), epochs, epoch_length, 'r-', "%d%% pool" % red_pool_percent, linewidth=10)
  66.     plot_cum_payouts(times, 1.0/inverse_hashrate, blue_pool_percent/100.0, (1 + difficulty_inc_percent/100.0), epochs, epoch_length, 'b--', "%d%% pool" % blue_pool_percent, linewidth=10)
  67.     legend(loc='upper left')
  68.     title("average earnings from {times} simulations: {difficulty_inc_percent}% difficulty increase every {epoch_length} blocks, {block_reward} btc block reward, miner hash rate = 1/{inverse_hashrate} initial network hash rate".format(
  69.         times=times,
  70.         difficulty_inc_percent=difficulty_inc_percent,
  71.         epoch_length=epoch_length,
  72.         block_reward=BLOCK_REWARD,
  73.         inverse_hashrate=inverse_hashrate))
  74.     xlabel('block')
  75.     ylabel('cumulative earnings')
  76.     gcf().set_size_inches(16,12)
  77.     savefig('simulated_pool_average.png', dpi=50)
  78.     show()
  79.  
  80. plot_cloud()
  81. plot_average()
Advertisement
Add Comment
Please, Sign In to add comment