5
$\begingroup$

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.

$\endgroup$
  • $\begingroup$ Are you serious ? I think what I said it's quite clear taking in consideration that this is quant forum ( I don't need to write pages about what market caps ... ) if you can't help don't react ... $\endgroup$ – habdie May 11 '20 at 17:27
  • 1
    $\begingroup$ Tell us, which market caps- companies or indices? What time frame are you looking for? Edit your question to give us guidance so that we can help you. $\endgroup$ – Hamish Gibson May 11 '20 at 17:35
  • $\begingroup$ I'm looking for US stocks market caps for example 'Facebook' I know how to get the daily MarketCap from yahoo using the API but I want the historical Market Cap data and can't see how to do that and I have looked into it didn't find a solution ... $\endgroup$ – habdie May 11 '20 at 17:38
  • $\begingroup$ Check out the answer here: datascience.stackexchange.com/questions/587/…. $\endgroup$ – Hamish Gibson May 11 '20 at 17:42
  • $\begingroup$ Already had and it's not working old solution .... $\endgroup$ – habdie May 11 '20 at 17:46
2
$\begingroup$

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&note=&title=&source=false&units=false&quoteLegend=true&partner=&quotes=&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.

$\endgroup$
  • $\begingroup$ Thank you for your help. in Ycharts we can get directly the market cap daily (ycharts.com/companies/FB/market_cap) but don't know how to get it using the link request, can you explain how did you do that ? $\endgroup$ – habdie May 11 '20 at 19:29
  • $\begingroup$ @habdie Yes, you can do it that way if your goal is to retrieve market caps by hand for each stock. You asked for a way to get market caps in Python which is what my answer does if you make the substitutions I layout in the last paragraph. You can literally copy and paste my code into a python console and it will return the data. If you want another symbol or list of symbols, you will need to adjust the code. I assume you know basic programming. $\endgroup$ – amdopt May 11 '20 at 19:54
  • $\begingroup$ can you please explain to me how did you get the link for the requests ? I want to play with it but don't know how did you do it ? $\endgroup$ – habdie May 29 '20 at 14:01
  • $\begingroup$ @habdie Right-click the table in one of the ycharts links and inspect the element. Within the console, you can see the URL of the API that is called. That URL is the one in my example above. Alternatively, you could scrape the page using python modules like scrapy or beautifulsoup $\endgroup$ – amdopt May 29 '20 at 14:42
  • $\begingroup$ This was very helpful, I managed to get some data but when I try to get the max data it doesn't work always return the 5year data here's my link ;ycharts.com/charts/… $\endgroup$ – habdie May 29 '20 at 16:55
0
$\begingroup$

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.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.