A simple Python script that evaluates share overlap within ETFs and calculates % similarity for each ETF comparison based on the number of common shares.
pip install
the following:
Scrapes InvestEngine and/or Cbonds for ETF holdings and looks for common shares.
The more shares in common the higher the % similarity. See comparison.xlsx
for details.
Go to https://investengine.com/etfs. Search for your etf and open it. Copy the {broker}/{etf-symbol}
part of the URL following https://investengine.com/etfs/.
E.g. for
- https://investengine.com/etfs/vanguard/vhvg/?back=%2Fetfs%2Fcollections%2Fleading-global-indices%2F%3Fback%3D%252Fetfs%252F you want to use
vanguard/vhvg
- https://investengine.com/etfs/vanguard/vuag/?back=%2Fetfs%2Fcollections%2Fleading-global-indices%2F%3Fback%3D%252Fetfs%252F you want to use
vanguard/vuag
- https://investengine.com/etfs/invesco/spxp/?back=%2Fetfs%2Fcollections%2Fleading-global-indices%2F%3Fback%3D%252Fetfs%252F you want to use
invesco/spxp
Then run the script with the symbols as arguments. E.g.
python3 etf_diversification_calc.py --investengine_symbols vanguard/vhvg vanguard/vuag invesco/spxp
and you get a comparison.xlsx file with the results.
A sheet for each 1-to-1 comparison.
Go to https://cbonds.com/etf/. Search for your etf and open it. MAKE SURE THE ETF PAGE HAS A STRUCTURE TABLE WITH HOLDINGS OTHERWISE THIS WON'T WORK Copy the {etf_id}
part of the URL following https://cbonds.com/etf/.
E.g. for https://cbonds.com/etf/3971/ you want to use 3971
Then run the script with the symbols as arguments. E.g.
python3 etf_diversification_calc.py --cbonds_symbols 3971 9417
and you get a comparison.xlsx file with the results.
A sheet for each 1-to-1 comparison.
You can also use both sources at the same time. E.g.
python3 etf_diversification_calc.py --investengine_symbols vanguard/vhvg vanguard/vuag invesco/spxp --cbonds_symbols 3971
and the comparison should be somwhat accurate. (It's more accurate if you use one source only, as they have different names for the same holding)
All data comes from InvestEngine and/or Cbonds via Selenium
- Alex Pascal (https://github.com/alexpascal27)
https://github.com/PiperBatey/holdings_dl
MIT License (see LICENSE file)