Created
October 20, 2022 16:44
-
-
Save 84adam/328b098ece01aa12006e189f6a8c07aa to your computer and use it in GitHub Desktop.
Calculate future bitcoin supply and inflation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# bitcoin-inflation.py | |
# based on: https://github.com/ndsvw/Bitcoin-Supply-Calculator/blob/master/btcsupply.py | |
def btc_supply_at_block(b): | |
max_supply = 20999999.9769 | |
if b >= 33 * 210000: | |
return max_supply, 1.0 | |
else: | |
reward = 50e8 | |
supply = 0 | |
y = 210000 # halving every y blocks | |
while b > y - 1: | |
supply = supply + y * reward | |
reward = int(reward / 2.0) | |
b = b - y | |
supply = supply + b * reward | |
supply = (supply + reward) / 1e8 | |
pct_of_max = (supply / max_supply) | |
return supply, pct_of_max | |
if __name__ == '__main__': | |
year = 2009 | |
inflation = 1 | |
for i in range(0, 50): | |
epoch = i | |
blocks = epoch * 210000 | |
if epoch == 0: | |
year = 2009 | |
inflation = 1 | |
elif epoch == 1: | |
year = 2012 | |
inflation = 1 | |
else: | |
year += 4 | |
old_supply, _ = btc_supply_at_block(blocks-210000) | |
new_supply, _ = btc_supply_at_block(blocks) | |
inflation = round((((new_supply/old_supply)-1)/4), 8) | |
supply, pct_of_max = btc_supply_at_block(blocks) | |
print(f"EPOCH #{epoch+1:>2}: {blocks:>8} BLOCKS - {supply:>17.8f} BTC - {pct_of_max*100:>12.8f}% - YEAR {year} - {inflation*100:>10.6f}% INFLATION/YEAR") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
example output: