4

I am using the yfinance API and would like to retrieve more data from ETFs, in specific the sector weightings (%) of a specific ETF, found in the tab Holdings on the Yahoo website: https://finance.yahoo.com/quote/IWDA.AS/holdings?p=IWDA.AS

Is this possible in the current API? If not, does someone know how I could add this to the API? I'm guessing it would be in base.py, but I'm not sure where. All help is welcome!

Pieter-Jan
  • 492
  • 4
  • 15

1 Answers1

3

While I don't have an answer for you related to yfinance, you can use a package called yahooquery to retrieve that data. Disclaimer: I am the author of the package.

from yahooquery import Ticker

t = Ticker('IWDA.AS')

# sector weightings, returns pandas DataFrame
t.fund_sector_weightings
                        IWDA.AS
0
realestate               0.0303
consumer_cyclical        0.1036
basic_materials          0.0411
consumer_defensive       0.0857
technology               0.1920
communication_services   0.0917
financial_services       0.1453
utilities                0.0329
industrials              0.1013
energy                   0.0331
healthcare               0.1430
t.fund_holding_info

Or retrieve most of the data from that entire page:

t.fund_holding_info
{
    'IWDA.AS': {
        'maxAge': 1,
        'stockPosition': 0.9959,
        'bondPosition': 0.0,
        'holdings': [{
            'symbol': 'AAPL',
            'holdingName': 'Apple Inc',
            'holdingPercent': 0.038
        }, {
            'symbol': 'MSFT',
            'holdingName': 'Microsoft Corp',
            'holdingPercent': 0.035099998
        }, {
            'symbol': 'AMZN',
            'holdingName': 'Amazon.com Inc',
            'holdingPercent': 0.0278
        }, {
            'symbol': 'FB',
            'holdingName': 'Facebook Inc A',
            'holdingPercent': 0.012999999
        }, {
            'symbol': 'GOOG',
            'holdingName': 'Alphabet Inc Class C',
            'holdingPercent': 0.010299999
        }, {
            'symbol': 'GOOGL',
            'holdingName': 'Alphabet Inc A',
            'holdingPercent': 0.0101
        }, {
            'symbol': 'JNJ',
            'holdingName': 'Johnson & Johnson',
            'holdingPercent': 0.0088
        }, {
            'symbol': 'V',
            'holdingName': 'Visa Inc Class A',
            'holdingPercent': 0.007900001
        }, {
            'symbol': 'NESN',
            'holdingName': 'Nestle SA',
            'holdingPercent': 0.0078
        }, {
            'symbol': 'PG',
            'holdingName': 'Procter & Gamble Co',
            'holdingPercent': 0.0070999996
        }],
        'equityHoldings': {
            'priceToEarnings': 20.47,
            'priceToBook': 2.34,
            'priceToSales': 1.62,
            'priceToCashflow': 11.82
        },
        'bondHoldings': {},
        'bondRatings': [{
            'bb': 0.0
        }, {
            'aa': 0.0
        }, {
            'aaa': 0.0
        }, {
            'a': 0.0
        }, {
            'other': 0.0
        }, {
            'b': 0.0
        }, {
            'bbb': 0.0
        }, {
            'below_b': 0.0
        }, {
            'us_government': 0.0
        }],
        'sectorWeightings': [{
            'realestate': 0.030299999
        }, {
            'consumer_cyclical': 0.103599995
        }, {
            'basic_materials': 0.041100003
        }, {
            'consumer_defensive': 0.0857
        }, {
            'technology': 0.192
        }, {
            'communication_services': 0.0917
        }, {
            'financial_services': 0.1453
        }, {
            'utilities': 0.032899998
        }, {
            'industrials': 0.1013
        }, {
            'energy': 0.033099998
        }, {
            'healthcare': 0.143
        }]
    }
}

You can find additional data accessors through the documentation.

putty
  • 744
  • 1
  • 6
  • 14