download_open_source.download_data_constituents()
Download constituent data for a given stock index.
Usage
download_open_source.download_data_constituents(
index=None,
path=None,
)Downloads and processes the constituent data for a specified financial index. The data is fetched from a remote CSV file, filtered, and cleaned to provide relevant information about constituents. The function retrieves the URL of the CSV file for the specified index from ETF sites, sends an HTTP GET request to download the file, and processes the CSV to extract equity constituents.
Parameters
index: str = None-
Name of the financial index for which to download constituent data. Must be one of the supported indexes listed by ‘list_supported_indexes’. Optional when ‘path’ is given.
path: str or os.PathLike = None- Path to a local iShares or BlackRock holdings CSV, as saved from the fund’s web page, to read instead of downloading. ‘index’ is optional in this case; when given, rows whose name contains the index name are dropped.
Returns
pl.DataFrame-
A data frame with five columns:
- ‘symbol’: the ticker symbol of the equity constituent.
- ‘name’: the name of the equity constituent.
- ‘location’: the location where the company is based.
- ‘exchange’: the exchange where the equity is traded.
- ‘currency’: the currency in which the equity is traded, derived from the exchange.
Examples
from tidyfinance import download_data
download_data('Index Constituents', index='DAX')
download_data('Index Constituents', path='DAXEX_holdings.csv')