ranaroussi / yfinance

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

Fetch MarketCap historically #1008

Closed dvirginz closed 7 months ago

dvirginz commented 2 years ago

Using the provided code we can fetch one of the following data points

1) The current MarketCap 2) Historical data of Open High Low Close and Volume

msft = yf.Ticker("MSFT")
msft.info['marketCap']
msft.history()

Can we somehow can historical information of the marketcap?

Thanks.

ProgrammingDao commented 2 years ago

The MarketCap history doesn't seem to be available on yahoo finance and if you wanted to build the MarketCap history from the history of the stock prices, you would also need the history of outstanding shares. You can maybe assume constant number of outstanding shares over a short recent period and multiply it by your stock price history to get your market cap numbers.

dvirginz commented 2 years ago

Yes, unfortunately, as you know, this is not a fair assumption

On Sun, Jul 3, 2022, 13:22 AntoineV @.***> wrote:

The MarketCap history doesn't seem to be available on yahoo finance and if you wanted to build the MarketCap history from the history of the stock prices, you would also need the history of outstanding shares. You can maybe assume constant number of outstanding shares over a short recent period and multiply it by your stock price history to get your market cap numbers.

— Reply to this email directly, view it on GitHub https://github.com/ranaroussi/yfinance/issues/1008#issuecomment-1173054135, or unsubscribe https://github.com/notifications/unsubscribe-auth/AHM4A75CTVXLO4K6HR2UWC3VSFSWVANCNFSM5XDMUT3A . You are receiving this because you authored the thread.Message ID: @.***>

ValueRaider commented 2 years ago

I'm reopening this because I have a solution: branch feature/share-count will provide you a few years of share count. It's a weird mix of daily, weekly and monthly. Combine with price for MarketCap.

If you want to try now and give feedback, this discussion explains how to download. Use property shares_full

ValueRaider commented 7 months ago

Ticker.get_shares_full() is your friend.

liuxj2016 commented 5 months ago

Ticker.get_shares_full() is your friend

It seems that sometimes get_shares_full() give wrong results. For example, get_shares_full() outputs two different shares of MSFT on 20240501

ValueRaider commented 5 months ago

I don't understand the data oddities in that API call, I discovered it by accident.