1
$\begingroup$

I am trying to find an API which will return the current market cap of US stocks for a financial data visualization project, and I haven't had much luck finding anything. Preferably, I'd like to have market cap data for all S&P 500 stocks, though I realize that something like this might not be available and that I may just need to create that list myself with other data.

Has anyone had luck getting market cap data from an API, or is there a relatively simple way that I could calculate the market caps?

I've checked out this old post where someone suggested Yahoo finance and YQL, but the links are unfortunately dead and it appears as though this service is no longer offered.

Thanks for any insight/advice!

$\endgroup$
  • $\begingroup$ are you still looking for an answer? $\endgroup$ – amdopt Nov 20 at 13:30
1
$\begingroup$

If you are looking for a quick and easy solution, I have found a combination of Google Sheets + Yahoo Finance URLs to be relatively easy to implement.

Here's an example you could try yourself. Let's say you have a stock ticker, "AAPL" in cell A1.

=INDEX(IMPORTHTML( CONCATENATE("https://finance.yahoo.com/quote/", A2,"?p=",A2,"&.tsrc=fin-srch")  ,"table",2),1,2)

Basically, the importhtml function I've specified above will go to Yahoo Finance, then look for this table, splitting it out into 2 columns illustrated in yellow and only pull in the observation found in the first row, second column (hence the 1, 2 in the function parameters):

enter image description here

This approach could effortlessly be extended for all S&P500 companies - you would just put their corresponding ticker in cell A3 onward.

In order to pull in a list of all S&P500 constituents, you could go to this wiki to get a list using a similar formula. Be warned that if you intend to do any historical analysis, companies get listed/delisted all the time and your analysis could reflect suvivorship bias.

$\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.