# source: https://bitcointalk.org/index.php?topic=345065.0
# source: https://jlopp.github.io/bitcoin-savings-plan/
from tabulate import tabulate as tb
initial_investment = 10
initial_exchange_rate = 1
rake = 10
number_of_cycles = 20
cycle_multiplier = 2
table = [['BTC/FIAT', 'BTC Total', 'FIAT Value', 'BTC Sold', 'FIAT Bought', 'FIAT Total', 'BTC Invested %']]
btc_fiat = initial_exchange_rate
btc_total = initial_investment
fiat_value = initial_exchange_rate * btc_total
btc_sold = .0
fiat_bought = .0
fiat_total = .0
table.append([btc_fiat, btc_total, fiat_value, btc_sold, fiat_bought, fiat_total, 100])
for i in range(number_of_cycles):
btc_fiat = btc_fiat * cycle_multiplier
btc_sold = btc_total * (rake / 100)
btc_total = btc_total * ((100 - rake) / 100)
fiat_value = btc_fiat * btc_total
fiat_bought = btc_fiat * btc_sold
fiat_total += fiat_bought
btc_invested = fiat_value / (fiat_value + fiat_total) * 100
table.append([
float('{:.2f}'.format(btc_fiat)),
float('{:.8f}'.format(btc_total)),
float('{:.2f}'.format(fiat_value)),
float('{:.8f}'.format(btc_sold)),
float('{:.2f}'.format(fiat_bought)),
float('{:.2f}'.format(fiat_total)),
float('{:.2f}'.format(btc_invested)),
])
table.append(table[0])
print (tb(table, headers='firstrow', tablefmt='grid', showindex='always'))