The data set at investment.tar lists the following quantities, in US dollars over time: (a) the price of gold; (b) the S&P 500 US stock market index; and (c) the price of the cryptocurrency Bitcoin. Compare the performance of these indexes over the period 2010–2020 with respect to the regular investment of $100 per month.
Should have bought Bitcoin back in 2010:
Gold investment: USD 17,433.58
S&P investment: USD 21,739.46
BTC investment: USD 529,701,861.66
The code:
import pandas as pd
gold = pd.read_csv('gold.txt', delim_whitespace=True, index_col=0,
usecols=[0, 1], parse_dates=True)
snp = pd.read_csv('SNP.csv', parse_dates=True, index_col=0)
btc = pd.read_csv('BTC.csv', parse_dates=True, index_col=0)
gold['holding'] = 100 / gold['Price']
snp['holding'] = 100 / snp['Open']
btc['holding'] = 100 / btc['BTC-USD']
final_date = '2020-07-01'
total_btc = btc['holding'][:final_date].sum()
total_gold = gold['holding'][:final_date].sum()
total_snp = snp['holding'][:final_date].sum()
print('Gold investment: USD {:,.2f}'
.format(total_gold * gold.loc[final_date]['Price']))
print('S&P investment: USD {:,.2f}'
.format(total_snp * snp.loc[final_date]['Open']))
print('BTC investment: USD {:,.2f}'
.format(total_btc * btc.loc[final_date]['BTC-USD']))