Stock Market Data And Analysis In Python – Part V


Visit: QuantInsti

See Part I for instructions on how to get pandas_datareader or yfinance module to retrieve the data, and Part II to learn how to get stock market data for different geographies. In Part III and Part IV, review the tutorial on how to analyse the stock market data for all the stocks which make up the S&P 500.

Using Quandl to get Stock Market Data (Optional)

Quandl has many data sources to get different types of stock market data. However, some are free and some are paid. Wiki is the free data source of Quandl to get the data of the end of the day prices of 3000+ US equities. It is curated by Quandl community and also provides information about the dividends and split.

Quandl also provides paid data source of minute and lower frequencies.

To get the stock market data, you need to first install the quandl module if it is not already installed using the pip command as shown below.

!pip install quandl
Install hosted with ❤ by GitHub

You need to get your own API Key from quandl to get the stock market data using the below code.

After you get your key, assign the variable QUANDL_API_KEY with that key. Then set the start date, end date and the ticker of the asset whose stock market data you want to fetch.

The quandl get method takes this stock market data as input and returns the open, high, low, close, volume, adjusted values and other information.

# Import quandl package
import quandl

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

# This is to prompt you to change the Quandl Key
    raise Exception("Please provide a valid Quandl API key!")
# Set the start and end date
start_date = '1990-01-01'
end_date = '2018-03-01'

# Set the ticker name
ticker = 'AMZN'

# Feth the data
data = quandl.get('WIKI/'+ticker, 

# Print the first 5 rows of the dataframe
data.head() hosted with ❤ by GitHub
DateOpenHighLowCloseVolumeEx-DividendSplit RatioAdj. OpenAdj. HighAdj. LowAdj. CloseAdj. Volume

To learn more about how you can use Quandl, check out this article:

Stay tuned for next installment in which Ishan Shah will demonstrate in details how to use yfinance to get fundamental data.

See for additional insight on this topic.

Past performance is not indicative of future results.

Any stock, options or futures symbols displayed are for illustrative purposes only and are not intended to portray recommendations.

Disclosure: Interactive Brokers

Information posted on IBKR Traders’ Insight that is provided by third-parties and not by Interactive Brokers does NOT constitute a recommendation by Interactive Brokers that you should contract for the services of that third party. Third-party participants who contribute to IBKR Traders’ Insight are independent of Interactive Brokers and Interactive Brokers does not make any representations or warranties concerning the services offered, their past or future performance, or the accuracy of the information provided by the third party. Past performance is no guarantee of future results.

This material is from QuantInsti and is being posted with permission from QuantInsti. The views expressed in this material are solely those of the author and/or QuantInsti and IBKR is not endorsing or recommending any investment or trading discussed in the material. This material is not and should not be construed as an offer to sell or the solicitation of an offer to buy any security. To the extent that this material discusses general market activity, industry or sector trends or other broad based economic or political conditions, it should not be construed as research or investment advice. To the extent that it includes references to specific securities, commodities, currencies, or other instruments, those references do not constitute a recommendation to buy, sell or hold such security. This material does not and is not intended to take into account the particular financial conditions, investment objectives or requirements of individual customers. Before acting on this material, you should consider whether it is suitable for your particular circumstances and, as necessary, seek professional advice.

In accordance with EU regulation: The statements in this document shall not be considered as an objective or independent explanation of the matters. Please note that this document (a) has not been prepared in accordance with legal requirements designed to promote the independence of investment research, and (b) is not subject to any prohibition on dealing ahead of the dissemination or publication of investment research.

Any trading symbols displayed are for illustrative purposes only and are not intended to portray recommendations.