Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 28.23 KB | None | 0 0
  1. //@version=4
  2. // Thanks to Harold Christopher Burger and the anonymous @100trillionUSD twitter handle
  3. // Power Law inspired by https://medium.com/coinmonks/bitcoins-natural-long-term-power-law-corridor-of-growth-649d0e9b3c94
  4. // Stock-to-Flow inspired by https://medium.com/@100trillionUSD/modeling-bitcoins-value-with-scarcity-91fa0fc03e25
  5. // Bitcoin Never Look Back by https://medium.com/@cane.island/why-bitcoin-is-never-looking-back-f06ab333742e
  6. // Public Domain code
  7. // --- History (please update if you publish a new version) ---
  8. // 2019-09-21: First version
  9. // 2019-10-23: Added Bitcoin Never Look Back Price (NLBP)
  10.  
  11. study(title="Bitcoin Power Law and stock to flow models", shorttitle="Power Law & Stock to Flow", overlay=true)
  12. showtop = input(title="Show Power Law top", type=input.bool, defval=true)
  13. showfit = input(title="Show Power Law regression fit", type=input.bool, defval=true)
  14. showbottom = input(title="Show Power Law bottom", type=input.bool, defval=true)
  15. showSF = input(title="Show Stock to Flow", type=input.bool, defval=true)
  16. shownlbp = input(title="Show Never Look Back Price", type=input.bool, defval=true)
  17.  
  18. // Power law
  19. // Top
  20. atop=-13.38
  21. btop=5.02927337
  22. // Middle
  23. afit=-17.01593313
  24. bfit=5.84509376
  25. // Bottom
  26. abottom=-17.457
  27. bbottom=5.84509376
  28.  
  29. // Some convenient constants
  30. blockperyear = 365.25*24*6
  31. blockperhalving = 365.25*24*6*4
  32.  
  33. // Workaround to plot future where the chart doesn't go
  34. // We will call this function several times with a shift to reach "uncharted" areas
  35. calculate_series(atime, ashift) =>
  36.    
  37.    currenttime = atime + ashift
  38.    
  39.    // Number of days since Bitcoin Ledger start
  40.    day = (currenttime-timestamp(2009, 01, 03, 00, 00))/(1000*3600*24)
  41.    
  42.    outtop = pow(10,atop+btop*log10(day))
  43.    outfit = pow(10,afit+bfit*log10(day))
  44.    outbottom = pow(10,abottom+bbottom*log10(day))
  45.    
  46.    // Number of days since NLBP model start
  47.    dayNLB = (currenttime-timestamp(2010, 07, 17, 00, 00))/(1000*3600*24)
  48.    // NLBP
  49.    outnlbp = 0.018265*exp(0.2178*sqrt(dayNLB))
  50.    
  51.    // Stock to flow
  52.    
  53.    // Calculate stock
  54.    stock = 0.0
  55.    
  56.    // Historical stock
  57.    // Get Bitcoin circulating supply from 2009-01 till 2019-09 (monthly data at the start of each month)
  58.    if currenttime >= timestamp(2009, 01, 01, 00, 00)
  59.         stock := 50.0
  60.    if currenttime >= timestamp(2009, 02, 01, 00, 00)
  61.         stock := 137700.0
  62.    if currenttime >= timestamp(2009, 03, 01, 00, 00)
  63.         stock := 300350.0
  64.    if currenttime >= timestamp(2009, 04, 01, 00, 00)
  65.         stock := 485350.0
  66.    if currenttime >= timestamp(2009, 05, 01, 00, 00)
  67.         stock := 658050.0
  68.    if currenttime >= timestamp(2009, 06, 01, 00, 00)
  69.         stock := 818500.0
  70.    if currenttime >= timestamp(2009, 07, 01, 00, 00)
  71.         stock := 929300.0
  72.    if currenttime >= timestamp(2009, 08, 01, 00, 00)
  73.         stock := 1019550.0
  74.    if currenttime >= timestamp(2009, 09, 01, 00, 00)
  75.         stock := 1106550.0
  76.    if currenttime >= timestamp(2009, 10, 01, 00, 00)
  77.         stock := 1214700.0
  78.    if currenttime >= timestamp(2009, 11, 01, 00, 00)
  79.         stock := 1313750.0
  80.    if currenttime >= timestamp(2009, 12, 01, 00, 00)
  81.         stock := 1429450.0
  82.    if currenttime >= timestamp(2010, 01, 01, 00, 00)
  83.         stock := 1629350.0
  84.    if currenttime >= timestamp(2010, 02, 01, 00, 00)
  85.         stock := 1901200.0
  86.    if currenttime >= timestamp(2010, 03, 01, 00, 00)
  87.         stock := 2171950.0
  88.    if currenttime >= timestamp(2010, 04, 01, 00, 00)
  89.         stock := 2421500.0
  90.    if currenttime >= timestamp(2010, 05, 01, 00, 00)
  91.         stock := 2700300.0
  92.    if currenttime >= timestamp(2010, 06, 01, 00, 00)
  93.         stock := 2960600.0
  94.    if currenttime >= timestamp(2010, 07, 01, 00, 00)
  95.         stock := 3204950.0
  96.    if currenttime >= timestamp(2010, 08, 01, 00, 00)
  97.         stock := 3592950.0
  98.    if currenttime >= timestamp(2010, 09, 01, 00, 00)
  99.         stock := 3879000.0
  100.    if currenttime >= timestamp(2010, 10, 01, 00, 00)
  101.         stock := 4155850.0
  102.    if currenttime >= timestamp(2010, 11, 01, 00, 00)
  103.         stock := 4470050.0
  104.    if currenttime >= timestamp(2010, 12, 01, 00, 00)
  105.         stock := 4766150.0
  106.    if currenttime >= timestamp(2011, 01, 01, 00, 00)
  107.         stock := 5036250.0
  108.    if currenttime >= timestamp(2011, 02, 01, 00, 00)
  109.         stock := 5284950.0
  110.    if currenttime >= timestamp(2011, 03, 01, 00, 00)
  111.         stock := 5579500.0
  112.    if currenttime >= timestamp(2011, 04, 01, 00, 00)
  113.         stock := 5817950.0
  114.    if currenttime >= timestamp(2011, 05, 01, 00, 00)
  115.         stock := 6072750.0
  116.    if currenttime >= timestamp(2011, 06, 01, 00, 00)
  117.         stock := 6400250.0
  118.    if currenttime >= timestamp(2011, 07, 01, 00, 00)
  119.         stock := 6712700.0
  120.    if currenttime >= timestamp(2011, 08, 01, 00, 00)
  121.         stock := 6973900.0
  122.    if currenttime >= timestamp(2011, 09, 01, 00, 00)
  123.         stock := 7183350.0
  124.    if currenttime >= timestamp(2011, 10, 01, 00, 00)
  125.         stock := 7390150.0
  126.    if currenttime >= timestamp(2011, 11, 01, 00, 00)
  127.         stock := 7571700.0
  128.    if currenttime >= timestamp(2011, 12, 01, 00, 00)
  129.         stock := 7779500.0
  130.    if currenttime >= timestamp(2012, 01, 01, 00, 00)
  131.         stock := 8023200.0
  132.    if currenttime >= timestamp(2012, 02, 01, 00, 00)
  133.         stock := 8252250.0
  134.    if currenttime >= timestamp(2012, 03, 01, 00, 00)
  135.         stock := 8475500.0
  136.    if currenttime >= timestamp(2012, 04, 01, 00, 00)
  137.         stock := 8701850.0
  138.    if currenttime >= timestamp(2012, 05, 01, 00, 00)
  139.         stock := 8914700.0
  140.    if currenttime >= timestamp(2012, 06, 01, 00, 00)
  141.         stock := 9127350.0
  142.    if currenttime >= timestamp(2012, 07, 01, 00, 00)
  143.         stock := 9353500.0
  144.    if currenttime >= timestamp(2012, 08, 01, 00, 00)
  145.         stock := 9608550.0
  146.    if currenttime >= timestamp(2012, 09, 01, 00, 00)
  147.         stock := 9844750.0
  148.    if currenttime >= timestamp(2012, 10, 01, 00, 00)
  149.         stock := 10077650.0
  150.    if currenttime >= timestamp(2012, 11, 01, 00, 00)
  151.         stock := 10300950.0
  152.    if currenttime >= timestamp(2012, 12, 01, 00, 00)
  153.         stock := 10511875.0
  154.    if currenttime >= timestamp(2013, 01, 01, 00, 00)
  155.         stock := 10625175.0
  156.    if currenttime >= timestamp(2013, 02, 01, 00, 00)
  157.         stock := 10731825.0
  158.    if currenttime >= timestamp(2013, 03, 01, 00, 00)
  159.         stock := 10844500.0
  160.    if currenttime >= timestamp(2013, 04, 01, 00, 00)
  161.         stock := 10988125.0
  162.    if currenttime >= timestamp(2013, 05, 01, 00, 00)
  163.         stock := 11109275.0
  164.    if currenttime >= timestamp(2013, 06, 01, 00, 00)
  165.         stock := 11232900.0
  166.    if currenttime >= timestamp(2013, 07, 01, 00, 00)
  167.         stock := 11360900.0
  168.    if currenttime >= timestamp(2013, 08, 01, 00, 00)
  169.         stock := 11491500.0
  170.    if currenttime >= timestamp(2013, 09, 01, 00, 00)
  171.         stock := 11648650.0
  172.    if currenttime >= timestamp(2013, 10, 01, 00, 00)
  173.         stock := 11788075.0
  174.    if currenttime >= timestamp(2013, 11, 01, 00, 00)
  175.         stock := 11938750.0
  176.    if currenttime >= timestamp(2013, 12, 01, 00, 00)
  177.         stock := 12067325.0
  178.    if currenttime >= timestamp(2014, 01, 01, 00, 00)
  179.         stock := 12203800.0
  180.    if currenttime >= timestamp(2014, 02, 01, 00, 00)
  181.         stock := 12349750.0
  182.    if currenttime >= timestamp(2014, 03, 01, 00, 00)
  183.         stock := 12465700.0
  184.    if currenttime >= timestamp(2014, 04, 01, 00, 00)
  185.         stock := 12590300.0
  186.    if currenttime >= timestamp(2014, 05, 01, 00, 00)
  187.         stock := 12716150.0
  188.    if currenttime >= timestamp(2014, 06, 01, 00, 00)
  189.         stock := 12851450.0
  190.    if currenttime >= timestamp(2014, 07, 01, 00, 00)
  191.         stock := 12976150.0
  192.    if currenttime >= timestamp(2014, 08, 01, 00, 00)
  193.         stock := 13092275.0
  194.    if currenttime >= timestamp(2014, 09, 01, 00, 00)
  195.         stock := 13215900.0
  196.    if currenttime >= timestamp(2014, 10, 01, 00, 00)
  197.         stock := 13334625.0
  198.    if currenttime >= timestamp(2014, 11, 01, 00, 00)
  199.         stock := 13459400.0
  200.    if currenttime >= timestamp(2014, 12, 01, 00, 00)
  201.         stock := 13568225.0
  202.    if currenttime >= timestamp(2015, 01, 01, 00, 00)
  203.         stock := 13678725.0
  204.    if currenttime >= timestamp(2015, 02, 01, 00, 00)
  205.         stock := 13787950.0
  206.    if currenttime >= timestamp(2015, 03, 01, 00, 00)
  207.         stock := 13900600.0
  208.    if currenttime >= timestamp(2015, 04, 01, 00, 00)
  209.         stock := 14010350.0
  210.    if currenttime >= timestamp(2015, 05, 01, 00, 00)
  211.         stock := 14116950.0
  212.    if currenttime >= timestamp(2015, 06, 01, 00, 00)
  213.         stock := 14224400.0
  214.    if currenttime >= timestamp(2015, 07, 01, 00, 00)
  215.         stock := 14334175.0
  216.    if currenttime >= timestamp(2015, 08, 01, 00, 00)
  217.         stock := 14456700.0
  218.    if currenttime >= timestamp(2015, 09, 01, 00, 00)
  219.         stock := 14567625.0
  220.    if currenttime >= timestamp(2015, 10, 01, 00, 00)
  221.         stock := 14678775.0
  222.    if currenttime >= timestamp(2015, 11, 01, 00, 00)
  223.         stock := 14789625.0
  224.    if currenttime >= timestamp(2015, 12, 01, 00, 00)
  225.         stock := 14906475.0
  226.    if currenttime >= timestamp(2016, 01, 01, 00, 00)
  227.         stock := 15039125.0
  228.    if currenttime >= timestamp(2016, 02, 01, 00, 00)
  229.         stock := 15158450.0
  230.    if currenttime >= timestamp(2016, 03, 01, 00, 00)
  231.         stock := 15274725.0
  232.    if currenttime >= timestamp(2016, 04, 01, 00, 00)
  233.         stock := 15385750.0
  234.    if currenttime >= timestamp(2016, 05, 01, 00, 00)
  235.         stock := 15498725.0
  236.    if currenttime >= timestamp(2016, 06, 01, 00, 00)
  237.         stock := 15610000.0
  238.    if currenttime >= timestamp(2016, 07, 01, 00, 00)
  239.         stock := 15721925.0
  240.    if currenttime >= timestamp(2016, 08, 01, 00, 00)
  241.         stock := 15794500.0
  242.    if currenttime >= timestamp(2016, 09, 01, 00, 00)
  243.         stock := 15850362.5
  244.    if currenttime >= timestamp(2016, 10, 01, 00, 00)
  245.         stock := 15907262.5
  246.    if currenttime >= timestamp(2016, 11, 01, 00, 00)
  247.         stock := 15962137.5
  248.    if currenttime >= timestamp(2016, 12, 01, 00, 00)
  249.         stock := 16018575.0
  250.    if currenttime >= timestamp(2017, 01, 01, 00, 00)
  251.         stock := 16081387.5
  252.    if currenttime >= timestamp(2017, 02, 01, 00, 00)
  253.         stock := 16141162.5
  254.    if currenttime >= timestamp(2017, 03, 01, 00, 00)
  255.         stock := 16191787.5
  256.    if currenttime >= timestamp(2017, 04, 01, 00, 00)
  257.         stock := 16253712.5
  258.    if currenttime >= timestamp(2017, 05, 01, 00, 00)
  259.         stock := 16308862.5
  260.    if currenttime >= timestamp(2017, 06, 01, 00, 00)
  261.         stock := 16367962.5
  262.    if currenttime >= timestamp(2017, 07, 01, 00, 00)
  263.         stock := 16424300.0
  264.    if currenttime >= timestamp(2017, 08, 01, 00, 00)
  265.         stock := 16482837.5
  266.    if currenttime >= timestamp(2017, 09, 01, 00, 00)
  267.         stock := 16542200.0
  268.    if currenttime >= timestamp(2017, 10, 01, 00, 00)
  269.         stock := 16602525.0
  270.    if currenttime >= timestamp(2017, 11, 01, 00, 00)
  271.         stock := 16660787.5
  272.    if currenttime >= timestamp(2017, 12, 01, 00, 00)
  273.         stock := 16715937.5
  274.    if currenttime >= timestamp(2018, 01, 01, 00, 00)
  275.         stock := 16776450.0
  276.    if currenttime >= timestamp(2018, 02, 01, 00, 00)
  277.         stock := 16843762.5
  278.    if currenttime >= timestamp(2018, 03, 01, 00, 00)
  279.         stock := 16896312.5
  280.    if currenttime >= timestamp(2018, 04, 01, 00, 00)
  281.         stock := 16952512.5
  282.    if currenttime >= timestamp(2018, 05, 01, 00, 00)
  283.         stock := 17010087.5
  284.    if currenttime >= timestamp(2018, 06, 01, 00, 00)
  285.         stock := 17073087.5
  286.    if currenttime >= timestamp(2018, 07, 01, 00, 00)
  287.         stock := 17129625.0
  288.    if currenttime >= timestamp(2018, 08, 01, 00, 00)
  289.         stock := 17186437.5
  290.    if currenttime >= timestamp(2018, 09, 01, 00, 00)
  291.         stock := 17244587.5
  292.    if currenttime >= timestamp(2018, 10, 01, 00, 00)
  293.         stock := 17299912.5
  294.    if currenttime >= timestamp(2018, 11, 01, 00, 00)
  295.         stock := 17358400.0
  296.    if currenttime >= timestamp(2018, 12, 01, 00, 00)
  297.         stock := 17405450.0
  298.    if currenttime >= timestamp(2019, 01, 01, 00, 00)
  299.         stock := 17459487.5
  300.    if currenttime >= timestamp(2019, 02, 01, 00, 00)
  301.         stock := 17514275.0
  302.    if currenttime >= timestamp(2019, 03, 01, 00, 00)
  303.         stock := 17569362.5
  304.    if currenttime >= timestamp(2019, 04, 01, 00, 00)
  305.         stock := 17624400.0
  306.    if currenttime >= timestamp(2019, 05, 01, 00, 00)
  307.         stock := 17679400.0
  308.    if currenttime >= timestamp(2019, 06, 01, 00, 00)
  309.         stock := 17735862.5
  310.    if currenttime >= timestamp(2019, 07, 01, 00, 00)
  311.         stock := 17792250.0
  312.    if currenttime >= timestamp(2019, 08, 01, 00, 00)
  313.         stock := 17856137.5
  314.    if currenttime >= timestamp(2019, 09, 01, 00, 00)
  315.         stock := 17912187.5
  316.    last_stock_data_time = timestamp(2019, 10, 01, 00, 00)
  317.    if currenttime > last_stock_data_time
  318.         stock := 17968263.0
  319.    
  320.    // Now get the higher boundary of the stock for interpolation (just for a smooth curve)
  321.    // ...and thanks so much to Pine Script to not support arrays. All this code should be just an easy table...
  322.    stock_h = 17968263.0
  323.    if currenttime <= timestamp(2019, 10, 01, 00, 00)
  324.         stock_h := 17968263.0
  325.    if currenttime <= timestamp(2019, 09, 01, 00, 00)
  326.         stock_h := 17912187.5
  327.    if currenttime <= timestamp(2019, 08, 01, 00, 00)
  328.         stock_h := 17856137.5
  329.    if currenttime <= timestamp(2019, 07, 01, 00, 00)
  330.         stock_h := 17792250
  331.    if currenttime <= timestamp(2019, 06, 01, 00, 00)
  332.         stock_h := 17735862.5
  333.    if currenttime <= timestamp(2019, 05, 01, 00, 00)
  334.         stock_h := 17679400
  335.    if currenttime <= timestamp(2019, 04, 01, 00, 00)
  336.         stock_h := 17624400
  337.    if currenttime <= timestamp(2019, 03, 01, 00, 00)
  338.         stock_h := 17569362.5
  339.    if currenttime <= timestamp(2019, 02, 01, 00, 00)
  340.         stock_h := 17514275
  341.    if currenttime <= timestamp(2019, 01, 01, 00, 00)
  342.         stock_h := 17459487.5
  343.    if currenttime <= timestamp(2018, 12, 01, 00, 00)
  344.         stock_h := 17405450
  345.    if currenttime <= timestamp(2018, 11, 01, 00, 00)
  346.         stock_h := 17358400
  347.    if currenttime <= timestamp(2018, 10, 01, 00, 00)
  348.         stock_h := 17299912.5
  349.    if currenttime <= timestamp(2018, 09, 01, 00, 00)
  350.         stock_h := 17244587.5
  351.    if currenttime <= timestamp(2018, 08, 01, 00, 00)
  352.         stock_h := 17186437.5
  353.    if currenttime <= timestamp(2018, 07, 01, 00, 00)
  354.         stock_h := 17129625
  355.    if currenttime <= timestamp(2018, 06, 01, 00, 00)
  356.         stock_h := 17073087.5
  357.    if currenttime <= timestamp(2018, 05, 01, 00, 00)
  358.         stock_h := 17010087.5
  359.    if currenttime <= timestamp(2018, 04, 01, 00, 00)
  360.         stock_h := 16952512.5
  361.    if currenttime <= timestamp(2018, 03, 01, 00, 00)
  362.         stock_h := 16896312.5
  363.    if currenttime <= timestamp(2018, 02, 01, 00, 00)
  364.         stock_h := 16843762.5
  365.    if currenttime <= timestamp(2018, 01, 01, 00, 00)
  366.         stock_h := 16776450
  367.    if currenttime <= timestamp(2017, 12, 01, 00, 00)
  368.         stock_h := 16715937.5
  369.    if currenttime <= timestamp(2017, 11, 01, 00, 00)
  370.         stock_h := 16660787.5
  371.    if currenttime <= timestamp(2017, 10, 01, 00, 00)
  372.         stock_h := 16602525
  373.    if currenttime <= timestamp(2017, 09, 01, 00, 00)
  374.         stock_h := 16542200
  375.    if currenttime <= timestamp(2017, 08, 01, 00, 00)
  376.         stock_h := 16482837.5
  377.    if currenttime <= timestamp(2017, 07, 01, 00, 00)
  378.         stock_h := 16424300
  379.    if currenttime <= timestamp(2017, 06, 01, 00, 00)
  380.         stock_h := 16367962.5
  381.    if currenttime <= timestamp(2017, 05, 01, 00, 00)
  382.         stock_h := 16308862.5
  383.    if currenttime <= timestamp(2017, 04, 01, 00, 00)
  384.         stock_h := 16253712.5
  385.    if currenttime <= timestamp(2017, 03, 01, 00, 00)
  386.         stock_h := 16191787.5
  387.    if currenttime <= timestamp(2017, 02, 01, 00, 00)
  388.         stock_h := 16141162.5
  389.    if currenttime <= timestamp(2017, 01, 01, 00, 00)
  390.         stock_h := 16081387.5
  391.    if currenttime <= timestamp(2016, 12, 01, 00, 00)
  392.         stock_h := 16018575
  393.    if currenttime <= timestamp(2016, 11, 01, 00, 00)
  394.         stock_h := 15962137.5
  395.    if currenttime <= timestamp(2016, 10, 01, 00, 00)
  396.         stock_h := 15907262.5
  397.    if currenttime <= timestamp(2016, 09, 01, 00, 00)
  398.         stock_h := 15850362.5
  399.    if currenttime <= timestamp(2016, 08, 01, 00, 00)
  400.         stock_h := 15794500
  401.    if currenttime <= timestamp(2016, 07, 01, 00, 00)
  402.         stock_h := 15721925
  403.    if currenttime <= timestamp(2016, 06, 01, 00, 00)
  404.         stock_h := 15610000
  405.    if currenttime <= timestamp(2016, 05, 01, 00, 00)
  406.         stock_h := 15498725
  407.    if currenttime <= timestamp(2016, 04, 01, 00, 00)
  408.         stock_h := 15385750
  409.    if currenttime <= timestamp(2016, 03, 01, 00, 00)
  410.         stock_h := 15274725
  411.    if currenttime <= timestamp(2016, 02, 01, 00, 00)
  412.         stock_h := 15158450
  413.    if currenttime <= timestamp(2016, 01, 01, 00, 00)
  414.         stock_h := 15039125
  415.    if currenttime <= timestamp(2015, 12, 01, 00, 00)
  416.         stock_h := 14906475
  417.    if currenttime <= timestamp(2015, 11, 01, 00, 00)
  418.         stock_h := 14789625
  419.    if currenttime <= timestamp(2015, 10, 01, 00, 00)
  420.         stock_h := 14678775
  421.    if currenttime <= timestamp(2015, 09, 01, 00, 00)
  422.         stock_h := 14567625
  423.    if currenttime <= timestamp(2015, 08, 01, 00, 00)
  424.         stock_h := 14456700
  425.    if currenttime <= timestamp(2015, 07, 01, 00, 00)
  426.         stock_h := 14334175
  427.    if currenttime <= timestamp(2015, 06, 01, 00, 00)
  428.         stock_h := 14224400
  429.    if currenttime <= timestamp(2015, 05, 01, 00, 00)
  430.         stock_h := 14116950
  431.    if currenttime <= timestamp(2015, 04, 01, 00, 00)
  432.         stock_h := 14010350
  433.    if currenttime <= timestamp(2015, 03, 01, 00, 00)
  434.         stock_h := 13900600
  435.    if currenttime <= timestamp(2015, 02, 01, 00, 00)
  436.         stock_h := 13787950
  437.    if currenttime <= timestamp(2015, 01, 01, 00, 00)
  438.         stock_h := 13678725
  439.    if currenttime <= timestamp(2014, 12, 01, 00, 00)
  440.         stock_h := 13568225
  441.    if currenttime <= timestamp(2014, 11, 01, 00, 00)
  442.         stock_h := 13459400
  443.    if currenttime <= timestamp(2014, 10, 01, 00, 00)
  444.         stock_h := 13334625
  445.    if currenttime <= timestamp(2014, 09, 01, 00, 00)
  446.         stock_h := 13215900
  447.    if currenttime <= timestamp(2014, 08, 01, 00, 00)
  448.         stock_h := 13092275
  449.    if currenttime <= timestamp(2014, 07, 01, 00, 00)
  450.         stock_h := 12976150
  451.    if currenttime <= timestamp(2014, 06, 01, 00, 00)
  452.         stock_h := 12851450
  453.    if currenttime <= timestamp(2014, 05, 01, 00, 00)
  454.         stock_h := 12716150
  455.    if currenttime <= timestamp(2014, 04, 01, 00, 00)
  456.         stock_h := 12590300
  457.    if currenttime <= timestamp(2014, 03, 01, 00, 00)
  458.         stock_h := 12465700
  459.    if currenttime <= timestamp(2014, 02, 01, 00, 00)
  460.         stock_h := 12349750
  461.    if currenttime <= timestamp(2014, 01, 01, 00, 00)
  462.         stock_h := 12203800
  463.    if currenttime <= timestamp(2013, 12, 01, 00, 00)
  464.         stock_h := 12067325
  465.    if currenttime <= timestamp(2013, 11, 01, 00, 00)
  466.         stock_h := 11938750
  467.    if currenttime <= timestamp(2013, 10, 01, 00, 00)
  468.         stock_h := 11788075
  469.    if currenttime <= timestamp(2013, 09, 01, 00, 00)
  470.         stock_h := 11648650
  471.    if currenttime <= timestamp(2013, 08, 01, 00, 00)
  472.         stock_h := 11491500
  473.    if currenttime <= timestamp(2013, 07, 01, 00, 00)
  474.         stock_h := 11360900
  475.    if currenttime <= timestamp(2013, 06, 01, 00, 00)
  476.         stock_h := 11232900
  477.    if currenttime <= timestamp(2013, 05, 01, 00, 00)
  478.         stock_h := 11109275
  479.    if currenttime <= timestamp(2013, 04, 01, 00, 00)
  480.         stock_h := 10988125
  481.    if currenttime <= timestamp(2013, 03, 01, 00, 00)
  482.         stock_h := 10844500
  483.    if currenttime <= timestamp(2013, 02, 01, 00, 00)
  484.         stock_h := 10731825
  485.    if currenttime <= timestamp(2013, 01, 01, 00, 00)
  486.         stock_h := 10625175
  487.    if currenttime <= timestamp(2012, 12, 01, 00, 00)
  488.         stock_h := 10511875
  489.    if currenttime <= timestamp(2012, 11, 01, 00, 00)
  490.         stock_h := 10300950
  491.    if currenttime <= timestamp(2012, 10, 01, 00, 00)
  492.         stock_h := 10077650
  493.    if currenttime <= timestamp(2012, 09, 01, 00, 00)
  494.         stock_h := 9844750
  495.    if currenttime <= timestamp(2012, 08, 01, 00, 00)
  496.         stock_h := 9608550
  497.    if currenttime <= timestamp(2012, 07, 01, 00, 00)
  498.         stock_h := 9353500
  499.    if currenttime <= timestamp(2012, 06, 01, 00, 00)
  500.         stock_h := 9127350
  501.    if currenttime <= timestamp(2012, 05, 01, 00, 00)
  502.         stock_h := 8914700
  503.    if currenttime <= timestamp(2012, 04, 01, 00, 00)
  504.         stock_h := 8701850
  505.    if currenttime <= timestamp(2012, 03, 01, 00, 00)
  506.         stock_h := 8475500
  507.    if currenttime <= timestamp(2012, 02, 01, 00, 00)
  508.         stock_h := 8252250
  509.    if currenttime <= timestamp(2012, 01, 01, 00, 00)
  510.         stock_h := 8023200
  511.    if currenttime <= timestamp(2011, 12, 01, 00, 00)
  512.         stock_h := 7779500
  513.    if currenttime <= timestamp(2011, 11, 01, 00, 00)
  514.         stock_h := 7571700
  515.    if currenttime <= timestamp(2011, 10, 01, 00, 00)
  516.         stock_h := 7390150
  517.    if currenttime <= timestamp(2011, 09, 01, 00, 00)
  518.         stock_h := 7183350
  519.    if currenttime <= timestamp(2011, 08, 01, 00, 00)
  520.         stock_h := 6973900
  521.    if currenttime <= timestamp(2011, 07, 01, 00, 00)
  522.         stock_h := 6712700
  523.    if currenttime <= timestamp(2011, 06, 01, 00, 00)
  524.         stock_h := 6400250
  525.    if currenttime <= timestamp(2011, 05, 01, 00, 00)
  526.         stock_h := 6072750
  527.    if currenttime <= timestamp(2011, 04, 01, 00, 00)
  528.         stock_h := 5817950
  529.    if currenttime <= timestamp(2011, 03, 01, 00, 00)
  530.         stock_h := 5579500
  531.    if currenttime <= timestamp(2011, 02, 01, 00, 00)
  532.         stock_h := 5284950
  533.    if currenttime <= timestamp(2011, 01, 01, 00, 00)
  534.         stock_h := 5036250
  535.    if currenttime <= timestamp(2010, 12, 01, 00, 00)
  536.         stock_h := 4766150
  537.    if currenttime <= timestamp(2010, 11, 01, 00, 00)
  538.         stock_h := 4470050
  539.    if currenttime <= timestamp(2010, 10, 01, 00, 00)
  540.         stock_h := 4155850
  541.    if currenttime <= timestamp(2010, 09, 01, 00, 00)
  542.         stock_h := 3879000
  543.    if currenttime <= timestamp(2010, 08, 01, 00, 00)
  544.         stock_h := 3592950
  545.    if currenttime <= timestamp(2010, 07, 01, 00, 00)
  546.         stock_h := 3204950
  547.    if currenttime <= timestamp(2010, 06, 01, 00, 00)
  548.         stock_h := 2960600
  549.    if currenttime <= timestamp(2010, 05, 01, 00, 00)
  550.         stock_h := 2700300
  551.    if currenttime <= timestamp(2010, 04, 01, 00, 00)
  552.         stock_h := 2421500
  553.    if currenttime <= timestamp(2010, 03, 01, 00, 00)
  554.         stock_h := 2171950
  555.    if currenttime <= timestamp(2010, 02, 01, 00, 00)
  556.         stock_h := 1901200
  557.    if currenttime <= timestamp(2010, 01, 01, 00, 00)
  558.         stock_h := 1629350
  559.    if currenttime <= timestamp(2009, 12, 01, 00, 00)
  560.         stock_h := 1429450
  561.    if currenttime <= timestamp(2009, 11, 01, 00, 00)
  562.         stock_h := 1313750
  563.    if currenttime <= timestamp(2009, 10, 01, 00, 00)
  564.         stock_h := 1214700
  565.    if currenttime <= timestamp(2009, 09, 01, 00, 00)
  566.         stock_h := 1106550
  567.    if currenttime <= timestamp(2009, 08, 01, 00, 00)
  568.         stock_h := 1019550
  569.    if currenttime <= timestamp(2009, 07, 01, 00, 00)
  570.         stock_h := 929300
  571.    if currenttime <= timestamp(2009, 06, 01, 00, 00)
  572.         stock_h := 818500
  573.    if currenttime <= timestamp(2009, 05, 01, 00, 00)
  574.         stock_h := 658050
  575.    if currenttime <= timestamp(2009, 04, 01, 00, 00)
  576.         stock_h := 485350
  577.    if currenttime <= timestamp(2009, 03, 01, 00, 00)
  578.         stock_h := 300350
  579.    if currenttime <= timestamp(2009, 02, 01, 00, 00)
  580.         stock_h := 137700
  581.    if currenttime <= timestamp(2009, 01, 01, 00, 00)
  582.         stock_h := 50
  583.    
  584.    interpolation = dayofmonth/30.5 // approximation
  585.    stock := stock_h*interpolation+stock*(1-interpolation)
  586.    
  587.    // Calculate current halving
  588.    // Get past halving from historical data, and approximate flow from past data
  589.    halving = 0.0
  590.    yearly_flow = 0.0
  591.    yearly_flow := 10500000.0/((timestamp(2012, 11, 28, 00, 00)-timestamp(2009, 01, 03, 00, 00))/((1000*3600*24*365.25)))
  592.    if currenttime > timestamp(2012, 11, 28, 00, 00)
  593.         halving := halving + 1
  594.        yearly_flow := 5250000.0/((timestamp(2016, 07, 09, 00, 00)-timestamp(2012, 11, 28, 00, 00))/((1000*3600*24*365.25)))
  595.    if currenttime > timestamp(2016, 07, 09, 00, 00)
  596.         halving := halving + 1
  597.        yearly_flow := (17968263.0-15750000)/((timestamp(2019, 10, 01, 00, 00)-timestamp(2016, 07, 09, 00, 00))/((1000*3600*24*365.25)))
  598.    last_halving_data_time = timestamp(2020, 05, 5, 00, 00) // Estimate
  599.    if currenttime > last_halving_data_time
  600.        // Number of days since last_halving_data_time
  601.        after_halving_day = (currenttime-last_halving_data_time)/(1000*3600*24)
  602.        yearfloat = after_halving_day/365.25
  603.         halving := halving + 1 + floor(yearfloat/4)
  604.         // yearly_flow calculated below
  605.  
  606.    blockflow = 50/pow(2, halving)
  607.    
  608.    // Calculate future flow
  609.    if currenttime > last_halving_data_time
  610.        yearly_flow := blockflow*blockperyear
  611.    
  612.    // Future stock (after historical data)
  613.    if currenttime > last_stock_data_time
  614.        days_after_data = (currenttime-last_stock_data_time)/(1000*3600*24)
  615.        stock := stock+blockperyear*(days_after_data/365.25)*blockflow
  616.        if halving >= 4
  617.            for i = 4 to halving
  618.                stock := stock+blockperhalving*50/pow(2, i-1)
  619.    
  620.    SF = stock/yearly_flow
  621.    outSF = exp(-1.84) * pow(SF, 3.36)
  622.    //outSF := ((timestamp(2012, 11, 28, 00, 00)-timestamp(2009, 01, 03, 00, 00))/((1000*3600*24*365.25))) // Debug
  623.    [outtop, outfit, outbottom, outSF, outnlbp]
  624.  
  625. // Finally plot for real
  626. [outtop, outfit, outbottom, outSF, outnlbp] = calculate_series(time("D"), 0)
  627. plottop = plot(showtop ? outtop:na, color=color.red, title="Power Law Top")
  628. plotfit = plot(showfit ? outfit:na, color=color.gray, title="Power Law Regression Fit")
  629. plotbottom = plot(showbottom ? outbottom:na, color=color.green, title="Power Law Bottom")
  630. fill(plottop, plotfit, color=color.red, transp=90, title="Upper Fill")
  631. fill(plotfit, plotbottom, color=color.green, transp=90, title="Lower Fill")
  632. plot(showSF ? outSF:na, title="Bitcoin Stock to Flow", color=color.blue, linewidth=2)
  633. plot(shownlbp ? outnlbp:na, color=color.yellow, title="Never Look Back")
  634.  
  635. //if timeframe.period == '60'
  636. //'D' - daily, 'W' - weekly, 'M' - monthly, '5D' - 5 days, '12M' - one year, '3M' - one quarter
  637.  
  638. [outtop2, outfit2, outbottom2, outSF2, outnlbp2] = calculate_series(time("D"), 1000*3600*24*208*7)
  639. plot(showtop ? outtop2:na, color=color.red, title="Power Law Top", offset=208)
  640. plot(showfit ? outfit2:na, color=color.gray, title="Power Law Regression Fit", offset=208)
  641. plot(showbottom ? outbottom2:na, color=color.green, title="Power Law Bottom", offset=208)
  642. plot(showSF ? outSF2:na, title="Bitcoin Stock to Flow", color=color.blue, linewidth=2, offset=208)
  643. plot(shownlbp ? outnlbp2:na, color=color.yellow, title="Never Look Back", offset=208)
  644.  
  645. [outtop3, outfit3, outbottom3, outSF3, outnlbp3] = calculate_series(time("D"), 1000*3600*24*208*7*2)
  646. plot(showtop ? outtop3:na, color=color.red, title="Power Law Top", offset=208*2)
  647. plot(showfit ? outfit3:na, color=color.gray, title="Power Law Regression Fit", offset=208*2)
  648. plot(showbottom ? outbottom3:na, color=color.green, title="Power Law Bottom", offset=208*2)
  649. plot(showSF ? outSF3:na, title="Bitcoin Stock to Flow", color=color.blue, linewidth=2, offset=208*2)
  650. plot(shownlbp ? outnlbp3:na, color=color.yellow, title="Never Look Back", offset=208*2)
  651.  
  652. //[outtop4, outfit4, outbottom4, outSF4] = calculate_series(time("D"), 1000*3600*24*208*7*3)
  653. //plot(showtop ? outtop4:na, color=color.red, title="Power Law Top", offset=208*3)
  654. //plot(showfit ? outfit4:na, color=color.gray, title="Power Law Regression Fit", offset=208*3)
  655. //plot(showbottom ? outbottom4:na, color=color.green, title="Power Law Bottom", offset=208*3)
  656. //plot(showSF ? outSF4:na, title="Bitcoin Stock to Flow", color=color.blue, linewidth=2, offset=208*3)
  657.  
  658. //[outtop5, outfit5, outbottom5, outSF5] = calculate_series(time("D"), 1000*3600*24*208*7*4)
  659. //plot(showtop ? outtop5:na, color=color.red, title="Power Law Top", offset=208*4)
  660. //plot(showfit ? outfit5:na, color=color.gray, title="Power Law Regression Fit", offset=208*4)
  661. //plot(showbottom ? outbottom5:na, color=color.green, title="Power Law Bottom", offset=208*4)
  662. //plot(showSF ? outSF5:na, title="Bitcoin Stock to Flow", color=color.blue, linewidth=2, offset=208*4)
  663.  
  664. //[outtop6, outfit6, outbottom6, outSF6] = calculate_series(time("D"), 1000*3600*24*208*7*5)
  665. //plot(showtop ? outtop6:na, color=color.red, title="Power Law Top", offset=208*5)
  666. //plot(showfit ? outfit6:na, color=color.gray, title="Power Law Regression Fit", offset=208*5)
  667. //plot(showbottom ? outbottom6:na, color=color.green, title="Power Law Bottom", offset=208*5)
  668. //plot(showSF ? outSF6:na, title="Bitcoin Stock to Flow", color=color.blue, linewidth=2, offset=208*5)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement