EnkyNakamura

Bitcoin Production Cost

May 11th, 2020
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.02 KB | None | 0 0
  1. // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
  2. // © capriole_charles
  3.  
  4. //@version=4
  5. study("Bitcoin Production Cost",overlay=true)
  6.  
  7. // INPUTS
  8.  
  9. p_old = input(0.05,"Ave. Electricity Cost $USD KWh (Pre June 2019)")
  10. p_new = input(0.04,"Ave. Electricity Cost $USD KWh (Post June 2019")
  11. elec_pct = input(0.60,"% electricity to Total Mining Costs")
  12. plot_mp = input(true,"Plot BTC Miner Price (Close + Transaction Fee Revenue / BTC)")
  13. plot_tc = input(true,"Plot Production & Electricity Cost Curves")
  14. labels = input(false,"Plot Annual Profit Margin Labels?")
  15.  
  16. // DATA
  17.  
  18. fees = security("QUANDL:BCHAIN/TRFUS","D",close)
  19.  
  20. elec_consumption() =>
  21. // Cambridge Bitcoin Electricity Consumption Index (CBECI) - Bitcoin's global electricity consumption in TwH.
  22. // NB: Uses MONTHLY averages of raw data from CBECI. TV script run-time is too slow with Daily/Weekly data here.
  23. // This requires manual updating once a month for ongoing accuracy.
  24.  
  25. d = dayofmonth
  26. m = month
  27. y = year
  28.  
  29. e = float(na)
  30. e := d==1 and m==12 and y==2014? 1.85803466666667 :
  31. d==1 and m==1 and y==2015? 1.84261966666667 :
  32. d==1 and m==2 and y==2015? 1.910415 :
  33. d==1 and m==3 and y==2015? 2.07733266666667 :
  34. d==1 and m==4 and y==2015? 2.125437 :
  35. d==1 and m==5 and y==2015? 2.10028 :
  36. d==1 and m==6 and y==2015? 2.149371 :
  37. d==1 and m==7 and y==2015? 2.21597833333333 :
  38. d==1 and m==8 and y==2015? 2.335304 :
  39. d==1 and m==9 and y==2015? 2.32026033333333 :
  40. d==1 and m==10 and y==2015? 2.15466433333333 :
  41. d==1 and m==11 and y==2015? 2.29930733333333 :
  42. d==1 and m==12 and y==2015? 2.83890766666667 :
  43. d==1 and m==1 and y==2016? 3.76853166666667 :
  44. d==1 and m==2 and y==2016? 4.984321 :
  45. d==1 and m==3 and y==2016? 5.751456 :
  46. d==1 and m==4 and y==2016? 6.09711766666667 :
  47. d==1 and m==5 and y==2016? 6.65274233333333 :
  48. d==1 and m==6 and y==2016? 6.44479366666667 :
  49. d==1 and m==7 and y==2016? 5.618041 :
  50. d==1 and m==8 and y==2016? 4.439068 :
  51. d==1 and m==9 and y==2016? 4.43830366666667 :
  52. d==1 and m==10 and y==2016? 4.95330933333334 :
  53. d==1 and m==11 and y==2016? 5.12000766666667 :
  54. d==1 and m==12 and y==2016? 5.80765 :
  55. d==1 and m==1 and y==2017? 6.54180066666666 :
  56. d==1 and m==2 and y==2017? 7.62688133333333 :
  57. d==1 and m==3 and y==2017? 7.09545833333333 :
  58. d==1 and m==4 and y==2017? 6.71110866666667 :
  59. d==1 and m==5 and y==2017? 7.62911266666667 :
  60. d==1 and m==6 and y==2017? 11.720838 :
  61. d==1 and m==7 and y==2017? 13.17811 :
  62. d==1 and m==8 and y==2017? 12.0859133333333 :
  63. d==1 and m==9 and y==2017? 14.9976133333333 :
  64. d==1 and m==10 and y==2017? 17.342 :
  65. d==1 and m==11 and y==2017? 19.9178833333333 :
  66. d==1 and m==12 and y==2017? 22.4013633333333 :
  67. d==1 and m==1 and y==2018? 28.01982 :
  68. d==1 and m==2 and y==2018? 34.9384066666667 :
  69. d==1 and m==3 and y==2018? 34.81782 :
  70. d==1 and m==4 and y==2018? 36.8095066666667 :
  71. d==1 and m==5 and y==2018? 37.6163133333333 :
  72. d==1 and m==6 and y==2018? 41.5086133333333 :
  73. d==1 and m==7 and y==2018? 44.4878133333333 :
  74. d==1 and m==8 and y==2018? 49.8791433333333 :
  75. d==1 and m==9 and y==2018? 51.38618 :
  76. d==1 and m==10 and y==2018? 51.4356766666667 :
  77. d==1 and m==11 and y==2018? 47.8622633333333 :
  78. d==1 and m==12 and y==2018? 36.0539266666667 :
  79. d==1 and m==1 and y==2019? 36.1260666666667 :
  80. d==1 and m==2 and y==2019? 36.2145133333333 :
  81. d==1 and m==3 and y==2019? 36.9071833333333 :
  82. d==1 and m==4 and y==2019? 39.3832533333333 :
  83. d==1 and m==5 and y==2019? 41.2841866666667 :
  84. d==1 and m==6 and y==2019? 47.9736866666667 :
  85. d==1 and m==7 and y==2019? 56.3321133333333 :
  86. d==1 and m==8 and y==2019? 61.70129 :
  87. d==1 and m==9 and y==2019? 67.4179133333333 :
  88. d==1 and m==10 and y==2019? 77.0788966666667 :
  89. d==1 and m==11 and y==2019? 73.8160033333333 :
  90. d==1 and m==12 and y==2019? 72.26226 :
  91. d==1 and m==1 and y==2020? 71.86089 :
  92. d==1 and m==2 and y==2020? 78.92965667 :
  93. d==1 and m==3 and y==2020? 82.84 :
  94. d==1 and m==4 and y==2020? 65.96 :
  95. d==1 and m==5 and y==2020? 77.71 :na
  96. e
  97.  
  98. btc_mined_per_day() =>
  99. blocks_per_day = 144
  100. block_reward = time < timestamp(2012,11,28,0,0) ? 50 :
  101. time < timestamp(2016,7,9,0,0) ? 25 :
  102. time < timestamp(2020,5,14,0,0) ? 12.5 : 6.25 // 2020 estimated
  103. btc_per_day = blocks_per_day*block_reward
  104. btc_per_day
  105.  
  106. // CALCULATIONS
  107.  
  108. miner_price = close + fees/btc_mined_per_day()
  109.  
  110. elec = float(na)
  111. elec := na(elec_consumption()) ? elec[1] : elec_consumption()
  112.  
  113. p = time < timestamp(2019,6,30,0,0) ? p_old : p_new
  114.  
  115. btc_elec_cost = float(na)
  116. btc_elec_cost := (elec/365.25)*pow(10,9) / btc_mined_per_day() * p //convert: --> days --> KwH --> Per BTC --> * Price/KwH
  117.  
  118. total_cost = btc_elec_cost/elec_pct
  119.  
  120. margin = ((miner_price/total_cost)-1.0)*100.0
  121. profit_margin = round(sma(margin,365))
  122. m = ''
  123. m := profit_margin > 0 ? "+" : ''
  124.  
  125. // PLOT
  126.  
  127. a = plot(plot_tc ? btc_elec_cost : na,color=color.red,linewidth=2,title=" Electricity")
  128. tc = plot(plot_tc ? total_cost : na,color=color.purple,linewidth=1,title=" Total")
  129. fill(a,tc,color=color.red,transp=70)
  130.  
  131. mp = plot(plot_mp ? miner_price : na,color=color.green,linewidth=2,title=" BTC Miner Price")
  132. clr = miner_price < total_cost ? color.red : na
  133. fill(mp,tc,color=clr,transp=20)
  134.  
  135.  
  136.  
  137. // LABELS
  138.  
  139. if labels and (barstate.islast or (dayofmonth ==1 and month ==1) and profit_margin)
  140. label.new(bar_index, btc_elec_cost, style=label.style_labelup,
  141. text="Margin (p.a.)\n" + m + tostring(profit_margin) +"%",
  142. textcolor=color.white,color=color.green)
Add Comment
Please, Sign In to add comment