Skip to content
All library documents

Finding Historical Stock and Company Data Through APIs

Article Quant Q&A · Author: CharlesM

Summary

The document addresses how to obtain historical company information such as market capitalization, dividend yield, and financial statements with Python. Its central practical advice is to use data-provider APIs or libraries instead of scraping websites. It names Quandl and Intrinio as sources for historical fundamentals and describes querying a company metric over a date range. Yahoo Finance and Quandl are also mentioned for retrieving historical stock prices.

The examples are pointers to services and packages, rather than a systematic comparison of coverage, reliability, licensing, or cost. Availability may depend on provider access, account credentials, and the dataset. The discussion also notes that minute-level prices and detailed fundamentals may require different sources. It offers no evidence about data quality or survivorship and point-in-time availability, so researchers should check whether a source supports the historical fields and dates their analysis requires.

Key ideas

  • Historical market capitalization, dividend yield, and statements can be requested from provider APIs.
  • Quandl and Intrinio are named as possible sources for historical fundamentals.
  • Historical prices can be obtained through data packages or services such as Yahoo Finance and Quandl.
  • Provider coverage, access requirements, and suitability for a specific historical dataset are not compared.

Tags

Full text
# Python code to download historical firm data


# Python code to download historical firm data












I am looking for a Python code that scraps a website to download historical firm data such as market capitalization, dividend-yield, and so on. I have a code that downloads the current firm data from Yahoo but I am looking for historical data. Any suggestions?

## Answer by Kyle Balkissoon (score 6, accepted)

https://quant.stackexchange.com/a/15878

Quandl has a python api: https://www.quandl.com/help/api

and free stock fundamentals (some)

https://www.quandl.com/help/api-for-stock-data

## Answer by Andrew Carpenter (score 4)

https://quant.stackexchange.com/a/34470

You don't have to scrape that data to get it via Python if you work with Intrinio's API. Here is a Python SDKs that will make it easy for you:

Historical financial statements and dividend yield, marketcap, etc: https://github.com/nhedlund/intrinio

Specifically, you can make a curl request for historical marketcap like this:

```
curl "https://api.intrinio.com/historical_data?identifier=AAPL&item=marketcap&start_date=2014-01-01&end_date=2015-01-01" -u "USERNAME:PASSWORD"
```

That would give you the marketcap for Apple over the specified dates. You can just swap out the marketcap tag for dividendyield and get the data you want. Here is a full tutorial:

https://intrinio.com/tutorial/web_api

## Answer by Ishan Shah (score 4)

https://quant.stackexchange.com/a/45829

You can get stock price data using the following packages. Generally, scraping is not legal and using the API is the best and faster way to get the data.

I have shown below three ways to get the stock price data:

- Yahoo finance

- Quandl

Yahoo Finance

```
import matplotlib.pyplot as plt
import fix_yahoo_finance as yf  

data = yf.download('AAPL','2016-01-01','2019-08-01')
data.Close.plot()

plt.show()
```

Quandl

```
import matplotlib.pyplot as plt
import quandl

data = quandl.get("WIKI/KO", start_date="2016-01-01", end_date="2018-01-01", api_key=<Your_API_Key>)
data.Close.plot()

plt.show()
```

Note: To get your API key, sign up for a free Quandl account. Then, you can find your API key on Quandl account settings page.

If you are looking to get minute level data or fundamental data such as earnings or cash flow statement then this page should be helpful.

Shown in full with attribution under the source's licence. Licence: CC BY-SA 4.0 (Stack Exchange)

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.