Advertisement
Guest User

ActiveMining model

a guest
Nov 26th, 2013
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 10.50 KB | None | 0 0
  1. % Calculate ActiveMining income and value
  2. clear
  3. clc
  4. format compact
  5.  
  6. % User inputs %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  7.  
  8. % Print interval
  9. % Options: day, week
  10.     printInterval = 'week';
  11. % Amount of shares owned by user:
  12.     amountShares = 114425;
  13. % Total dividend paid (btc):
  14.     dividendPaid = 660;
  15. % Current bitcoin price:
  16.     btcStartPrice = 1000;
  17. % Expect bitcoin price [YEARS, PRICE]:
  18.     btcFuturePrice = [2,100000];
  19. % Current bitcoin mining difficulty:
  20.     startDiff = 609482679.89;
  21. % Current bitcoin block height:
  22.     blockHeightStart = 271267;
  23. % Blocks to run simulation:
  24.     run = blockHeightStart + 24 * 6 * 7 * 4 * 12 * 2;
  25. % Estimated difficulty increase next target: (%)
  26.     percentIncreaseBegin = 25;
  27. % Estimated difficulty increase in [BLOCKS_RETARGET, PERCENT]:
  28. % (make this higher than current increase if you think the network will be
  29. % increasing even faster today, and less if you think the network would
  30. % have plateaued)
  31.     percentIncreaseFuture = [24*2,25];
  32. % Expected return on investment for calculating share price: (months)
  33.     ROIMonth = 18;
  34. % Pool fee in percent
  35.     poolPercent = 3;
  36. % Percent of mining income reinvested in the business:
  37.     reinvestment = 80;
  38. % Dividend payment time: (days)
  39.     dividendPeriod = 7;
  40. % Starting fiat reserves
  41.     fiatReserves = 1000000;
  42. % Current cost of a TH/s:
  43. % (I divide the 24th/s miner by 148,000)
  44.     THsPriceStart = 6200;
  45. % Price of a TH/s [YEARS, USD]
  46. % (If you expect the price per TH/s to drop)
  47.     THsFuturePrice = [2,2000];
  48. % Time to buy chips with reinvested money (weeks):
  49.     reinvestTime = 4;
  50. % Print out parameters
  51.     printOutSwitch = [...
  52.             true,...% Week (DO NOT MODIFY)
  53.             false,...% Block number
  54.             true,...% Next percentage increase
  55.             false,...% Average block time
  56.             true,...% Hashrate
  57.             false,...% Block reward
  58.             true,...% Bitcoin price
  59.             false,...% Day of the week (DO NOT MODIFY)
  60.             true,...% ActiveMining hashrate!
  61.             true,...% All time dividend earnings
  62.             true,...% Share earnings this period
  63.             ];
  64.         % If day is true from print out at the top
  65.         % then force printOutSwitch to print days
  66.         if strcmp(printInterval,'day') == 1
  67.             printOutSwitch(8) = true;
  68.         elseif strcmp(printInterval,'week') == 1
  69.             printOutSwitch(1) = true;
  70.         end
  71.  
  72. % Do not edit below this line %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  73. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  74.  
  75. % Constant variables %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  76. % Bitcoin variables
  77. retargetBlock = 2016;
  78. rewardHalving = 210000;
  79. btcReward = 50;
  80. adjustTime = 10; % minutes
  81.  
  82. % ActiveMining variables
  83. amountSharesTotal = 25000000;
  84. specialDividendShares = 10000000;
  85. specialDividendExpire = 0.0025;
  86. hasSpecialDividendBeenPaid = false;
  87.  
  88. % Program %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  89.  
  90. % Setup beginning conditions:
  91. % Network hashrate:
  92. hashrate = simpleHashrateCalc(5,startDiff,(adjustTime - adjustTime/100*percentIncreaseBegin));
  93.  
  94. % Get amount of TH/s ActiveMining can buy:
  95. activeTHs = fiatReserves/THsPriceStart;
  96. fiatReserves = 0;
  97. % Set up TH/s variables
  98. logTHsRatio = log(THsFuturePrice(2)/THsPriceStart);
  99. THsPriceDays = (THsFuturePrice(1) * 365);
  100. THsPrice = THsPriceStart;
  101.  
  102. % Starting week
  103. week = 0;
  104. % Starting day
  105. day = 0;
  106. % Amount of minutes in one week
  107. weekMinutes = 60 * 24 * 7;
  108. % Amount of minutes in one day
  109. dayMinutes = 60 * 24;
  110.  
  111. % ActiveMining shares
  112. shareDividendAllTime = 0;
  113. perShareThisPeriod = 0;
  114.  
  115. % The difference in percentage for each difficulty retarget
  116. differencePercentChange = (percentIncreaseBegin - percentIncreaseFuture(2))/percentIncreaseFuture(1);
  117.  
  118. % Starting percentage increase
  119. percentIncrease = percentIncreaseBegin;
  120.  
  121. % Initialize minutes variables
  122. amountMinutesWeek = 0;
  123. amountMinutesDay = 0;
  124. ActiveMiningMinutes = 0;
  125. minuteLength = (100 - percentIncrease)/100 * 10;
  126.  
  127. printOut = false; % Initialize printing variable
  128.  
  129. currentDifficulty = startDiff;
  130.  
  131. % Bitcoin price variables
  132. logPriceRatio = log(btcFuturePrice(2)/btcStartPrice);
  133. btcPriceYears = btcFuturePrice(1);
  134. btcPriceDays = btcPriceYears * 365;
  135. btcPrice = btcStartPrice;
  136.  
  137. % Bitcoins mined at beginning of simulation
  138. dividendAccumalation = dividendPaid;
  139.  
  140. % Quickly get the block reward up to speed
  141. for blockHeight = 1:(blockHeightStart - 1)
  142.     if mod(blockHeight, rewardHalving) == 0
  143.         btcReward = btcReward / 2;
  144.     end
  145. end
  146.  
  147. % Primary loop (Run for each and everyblock on the network
  148. for blockHeight = blockHeightStart : run
  149.    
  150.     % If it's time for a retarget change the difficulty increase
  151.     if mod(blockHeight,retargetBlock) == 0
  152.         if percentIncrease > (percentIncreaseFuture(2) + differencePercentChange)
  153.             percentIncrease = percentIncrease - differencePercentChange;
  154.         else
  155.             percentIncrease = percentIncreaseFuture(2);
  156.         end
  157.         currentDifficulty = currentDifficulty + ( currentDifficulty / 100 * percentIncrease );
  158.         hashrate = simpleHashrateCalc(5,currentDifficulty,(adjustTime - adjustTime/100*percentIncrease));
  159.         minuteLength = (100 - percentIncrease)/100 * 10;
  160.     end
  161.    
  162.     % Work out how many minutes so far
  163.     amountMinutesWeek = amountMinutesWeek + minuteLength;
  164.     amountMinutesDay = amountMinutesDay + minuteLength;
  165.    
  166.     % ActiveMining has it's own minute ticker because we want to be able to
  167.     % adjust dividend and other timings if needed
  168.     ActiveMiningMinutes = ActiveMiningMinutes + minuteLength;
  169.    
  170.     if amountMinutesDay >= dayMinutes
  171.         % Reset the amount of minutes
  172.         amountMinutesDay = 0;
  173.         % Increment the day
  174.         day = day + 1;
  175.          % Print out if needed
  176.         if strcmp(printInterval,'day') == 1
  177.             printOut = true;
  178.         end
  179.         % Change the bitcoin price
  180.         btcPrice = btcStartPrice * exp(day / btcPriceDays * logPriceRatio);
  181.         % Change the TH/s purchase price
  182.         THsPrice = THsPriceStart * exp(day / THsPriceDays * logTHsRatio);
  183.        
  184.         % Pay dividend per the dividend period
  185.         if mod(day, dividendPeriod) == 0
  186.             if shareDividendAllTime >= specialDividendExpire && hasSpecialDividendBeenPaid == false
  187.                 hasSpecialDividendBeenPaid = true;
  188.             end
  189.            
  190.             if hasSpecialDividendBeenPaid == false
  191.                
  192.                 perShareThisPeriod = dividendAccumalation / specialDividendShares;
  193.             elseif hasSpecialDividendBeenPaid == true
  194.                 perShareThisPeriod = dividendAccumalation / amountSharesTotal;
  195.             end
  196.             shareDividendAllTime = shareDividendAllTime + perShareThisPeriod;
  197.             dividendAccumalation = 0;
  198.         end
  199.        
  200.     end
  201.    
  202.     if amountMinutesWeek >= weekMinutes
  203.         % Reset the amount of minutes
  204.         amountMinutesWeek = 0;
  205.         % Increment the week
  206.         week = week + 1;
  207.         % Print out if needed
  208.         if strcmp(printInterval,'week') == 1
  209.             printOut = true;
  210.         end
  211.        
  212.         % Calculate reinvestment of TH/s
  213.         if mod(week, reinvestTime) == 0
  214.            activeTHs = activeTHs + ( fiatReserves / THsPrice );
  215.            fiatReserves = 0;
  216.         end
  217.     end
  218.    
  219.     % Block reward
  220.     if mod(blockHeight, rewardHalving) == 0
  221.         btcReward = btcReward / 2;
  222.     end
  223.    
  224.     % ActiveMining %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  225.    
  226.     % Get our percentage of Bitcoins mined
  227.     ourShare = (activeTHs / hashrate) * btcReward;
  228.     ourShare = ourShare - ( ourShare / 100 ) * poolPercent;
  229.    
  230.     % Accumalation of shareholders dividend
  231.     thisAccumalation = ourShare - (ourShare / (100 / reinvestment));
  232.    
  233.     % Turn the reinvestment amount into fiat
  234.     reinvestedCoins = ourShare - thisAccumalation;
  235.     fiatReserves = fiatReserves + (reinvestedCoins * btcPrice);
  236.     reinvestedCoins = 0;
  237.    
  238.     dividendAccumalation = dividendAccumalation + thisAccumalation;
  239.    
  240.     % At this point we now know:
  241.     % activeTHs = Our hashrate
  242.     % shareDividendAllTime = How much each share has earned
  243.     % perShareThisPeriod = this current period earnings
  244.  
  245.     % purchase, special dividend, per share accumalation
  246.     % instantaneous share value, actual share value (trend of 52 week)
  247.     % multiply instant, actual, per share, for entire holdings
  248.     %
  249.    
  250.    
  251.     % END OF ACTIVEMINING %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  252.    
  253.     % Print out information
  254.     if printOut == true
  255.         % Turn off print out until it's selected again
  256.         printOut = false;
  257.         if printOutSwitch(1) == true
  258.             fprintf('Week %3i: -----\n',week)
  259.         end
  260.         if printOutSwitch(2) == true
  261.             fprintf('    Block No. %2i \n',blockHeight)
  262.         end
  263.         if printOutSwitch(3) == true
  264.             fprintf('    Next percent increase: %4.2f \n',percentIncrease)
  265.         end
  266.         if printOutSwitch(4) == true
  267.             fprintf('    Block time avg. %4.2f \n',minuteLength)
  268.         end
  269.         if printOutSwitch(5) == true
  270.             fprintf('    Hashrate: %8.0f TH/s \n', hashrate)
  271.         end
  272.         if printOutSwitch(6) == true
  273.             fprintf('    Block reward: %4.2f btc \n', btcReward)
  274.         end
  275.         if printOutSwitch(7) == true
  276.             fprintf('    Bitcoin price: %4.2f usd \n', btcPrice)
  277.         end
  278.         if printOutSwitch(8) == true
  279.             fprintf('    Day: %2i \n', day)
  280.         end
  281.         if printOutSwitch(9) == true
  282.             fprintf('    ActM Hashrate: %6.0f & Percent: %3.0f \n', activeTHs, (activeTHs/hashrate)*100)
  283.         end
  284.         if printOutSwitch(10) == true
  285.             fprintf('    Dividend Earned in Total:  Share: %12.8f($%6.2f), Holdings: %12.8f($%6.2f) \n',...
  286.                 shareDividendAllTime,...
  287.                 shareDividendAllTime * btcPrice,...
  288.                 shareDividendAllTime * amountShares,...
  289.                 shareDividendAllTime * amountShares * btcPrice)
  290.         end
  291.         if printOutSwitch(11) == true
  292.             fprintf('    Dividend Earn this Period: Share: %12.8f($%6.2f), Holdings: %12.8f($%6.2f) \n',...
  293.                 perShareThisPeriod,...
  294.                 perShareThisPeriod * btcPrice,...
  295.                 perShareThisPeriod * amountShares,...
  296.                 perShareThisPeriod * amountShares * btcPrice)
  297.         end
  298.        
  299.         fprintf('\n')
  300.     end
  301.  
  302.    
  303.    
  304. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement