Skip to content

Instantly share code, notes, and snippets.

@intrinio-gists
Created May 6, 2022 15:30
Show Gist options
  • Save intrinio-gists/f25626969303ab4ff9e310bf0190f695 to your computer and use it in GitHub Desktop.
Save intrinio-gists/f25626969303ab4ff9e310bf0190f695 to your computer and use it in GitHub Desktop.
ETF Allocations Dataset
def _etf_diversity_dataset(etf_tickers_and_allocations):
ETFs = []
for etf_ticker, allocation in etf_tickers_and_allocations.items():
etf_holdings_dataset = _etf_holdings_dataset(etf_ticker, allocation)
ETFs.append(etf_holdings_dataset)
etf_diversity_dataset = pd.concat(ETFs).groupby(by=["ticker", "sedol"]).sum()
etf_diversity_dataset = etf_diversity_dataset.sort_values(by="funds_allocation", ascending=False)
etf_diversity_dataset["funds_allocation"] = etf_diversity_dataset["funds_allocation"].round(3)
return etf_diversity_dataset
etf_tickers_and_allocations = {
"VDC": 20000,
"VCR": 20000,
"VGT": 20000,
"VOO": 20000,
"VUG": 20000,
}
etf_diversity_dataset = _etf_diversity_dataset(etf_tickers_and_allocations)
print(etf_diversity_dataset)
# ticker sedol funds_allocation
# AAPL 2046251 8506.425
# MSFT 2588173 6918.250
# AMZN 2000019 6523.805
# TSLA B616C79 4637.269
# PG 2704407 2835.639
# ... ...
# VRM BMFZYY5 0.157
# AUR BMF0P92 0.128
# LEN/B 2578293 0.125
# NWS BBGVT51 0.009
# HAYW BMFQC33 0.001
# [1153 rows x 1 columns]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment