ranaroussi / yfinance

Download market data from Yahoo! Finance's API
https://aroussi.com/post/python-yahoo-finance
Apache License 2.0
14.89k stars 2.44k forks source link

implement support for funds data #2041

Closed ericpien closed 2 months ago

ericpien commented 2 months ago

Changes:

Resolves:

Sample Code:

import yfinance as yf
spy_ticker = yf.Ticker('SPY')
spy_funds_data = spy_ticker.funds_data

spy_funds_data.description
spy_funds_data.fund_overview
spy_funds_data.fund_operations
spy_funds_data.asset_classes
spy_funds_data.top_holdings
spy_funds_data.equity_holdings
spy_funds_data.bond_holdings
spy_funds_data.bond_ratings
spy_funds_data.sector_weightings

Credits to https://github.com/ranaroussi/yfinance/pull/1784 for the idea

ValueRaider commented 2 months ago

Update readme

ericpien commented 2 months ago

Update readme

Done. Thanks for reviewing.

ValueRaider commented 2 months ago

Set df indexes. And some might be better as simple dict.

ericpien commented 2 months ago

Set df indexes. And some might be better as simple dict.

I converted data with just 2 columns to dicts and kept the others as DF with the indices set.

ericpien commented 2 months ago

hey @ValueRaider not sure if you've been busy or just missed it so pinging again. thanks.

ValueRaider commented 2 months ago

Looks good for SPY. I'm just thinking about the exception experience.

I would rephrase this:

raise YFDataException("Failed to parse quote type. No Fund data found.") to raise YFDataException("No Fund data found.")

Then with:

        except IndexError:
            raise YFDataException("Failed to parse fund json data.")

don't discard the original exception. See how base.py handles exceptions.

ericpien commented 2 months ago

Thanks for reviewing @ValueRaider. I interpreted the part about "don't discard the original exception" as meaning to log the base exception so implemented as such.