3
$\begingroup$

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?

$\endgroup$
5
$\begingroup$

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

$\endgroup$
3
$\begingroup$

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

$\endgroup$
0
$\begingroup$

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:

  1. Yahoo finance
  2. Quandl
  3. IEX Finance

Yahoo Finance

import matplotlib.pyplot as plt
import fix_yahoo_finance as yf  

data = yf.download('AAPL','2016-01-01','2018-01-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.

IEX Finance

from iexfinance import get_historical_data
from datetime import datetime

start_date='2016-01-01'
end_date='2017-01-01'

start_date = pd.to_datetime(start_date)
end_date = pd.to_datetime(end_date)

data = get_historical_data(ticker, start=start_date, end=end_date, output_format='pandas')

data.close.plot()
plt.show()

You can also get fundamental data using IEX finance.

Balance sheet

from iexfinance.stocks import Stock
aapl = Stock("AAPL")
aapl.get_balance_sheet()

Income Statement

aapl.get_income_statement()

Source: https://pypi.org/project/iexfinance/

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