I'm looking for a way of getting free historical daily market caps ? I can get todays Market cap from yahoo but need old market caps also.. thanks for the help.
ps: I don't have Bloomberg and school doesn't provide us with any data provider access.
Quantitative Finance Stack Exchange is a question and answer site for finance professionals and academics. It only takes a minute to sign up.
Sign up to join this communityI'm looking for a way of getting free historical daily market caps ? I can get todays Market cap from yahoo but need old market caps also.. thanks for the help.
ps: I don't have Bloomberg and school doesn't provide us with any data provider access.
Tiingo.com has fundamental data available through an API you can access using Python. I'm not sure if you have to pay for it or if it's included with a free account. Either way, the outstanding shares are on the balance sheet within the fundamental data you can get through their REST API.
YCharts has this data on a monthly basis too. See example here. From looking through the page, using Python requests
you can get the data easily in JSON format and using the json
package and use it how you like from there.
I just threw this code together as an example. The output is a list in [unix_time, shares_outstanding] format.
import requests
import json
response = requests.get('https://ycharts.com/charts/fund_data.json?securities=include%3Atrue%2Cid%3AMSFT%2C%2C&calcs=include%3Atrue%2Cid%3Ashares_outstanding%2C%2C&correlations=&format=real&recessions=false&zoom=5&startDate=&endDate=&chartView=&splitType=single&scaleType=linear¬e=&title=&source=false&units=false"eLegend=true&partner="es=&legendOnChart=true&securitylistSecurityId=&clientGroupLogoUrl=&displayTicker=false&ychartsLogo=&useEstimates=false&maxPoints=880')
json_data = {}
json_data['MSFT'] = json.loads(response.text)
You can access the data by doing something like this to get the most recent data:
json_data['MSFT']['chart_data'][0][0]['raw_data'][-1]
Resulting in: [1587686400000, 7583.4402]
After that just grab prices and multiply by shares outstanding and you have market caps. You may have to assume that outstanding shares are only updated once per month unless you want to dig through EDGAR filings.
The above code is only an exmaple of grabbing data for one stock. It would need to be altered a bit to make is usable for a list of stocks or list of dates, etc. To get market cap directly instead of the outstanding shares just replace shares_outstanding
with market_cap
in the requests.get()
call string. The output would be daily market caps in the same [unix, data] format.
I have found a source for Apple's historical market cap here. Whilst this source doesn't have a hollistic view of all companies listed, I'm sure they're available just by searching and it appears to go quite far back in time too. I hope this helps.