Quandl

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.

Note

Refer to Quandl Jupyter Notebook for more details.

Table of Contents

Installation

Install with pip:

pip install quandl

Usage

Note

Before working with this API, you will need to obtain a key from Nasdaq Data Link

Quandl is the library used for accessing the Nasdaq Data Link database, so all of the queries below follow a similar pattern that can be reproduced with any of the ID codes from the database.

Import all necessary libraries:

import quandl
import pandas as pd
import numpy as np
from datetime import datetime
from matplotlib import pyplot as plt
import seaborn as sns
# To get your API key, sign up for a free Quandl account.
# Then, you can find your API key on Quandl account settings page.
QUANDL_API_KEY = 'REPLACE-THIS-TEXT-WITH-A-REAL-API-KEY'


# This is to prompt you to change the Quandl Key
if QUANDL_API_KEY == 'REPLACE-THIS-TEXT-WITH-A-REAL-API-KEY':
    raise Exception("Please provide a valid Quandl API key!")
quandl.ApiConfig.api_key = QUANDL_API_KEY

Historical Price and Volume for 1 Stock

Outputs the OHLCV, as well as dividend data and adjusted OHLCV for the given ticker.

# Set the start and end date
start_date = '1990-01-01'
end_date = '2018-03-01'

# Set the ticker name
ticker = 'AMZN'
data = quandl.get('WIKI/'+ticker)

Adding Time Periods

Uses start and end to denote a time period for the query.

data = quandl.get('WIKI/'+ticker,
          start_date=start,
          end_date=end)
data.head()

Dividends

Outputs the Dividend and Read Dividend.

sp = quandl.get('YALE/SPCOMP', start_date='2015-04-01', end_date='2021-10-01')
sp[['Dividend', 'Real Dividend']]

Cryptocurrencies

Outputs the date and price of bitcoin.

# bitcoin price
btc = quandl.get('BCHAIN/MKPRU', start_date='2020-12-29', end_date='2021-12-29')
btc

Mutual Funds

Plots the mutual fund assests to GDP from the start_date to the end_date.

# Mutual Fund Assets to GDP for World
mf = quandl.get('FRED/DDDI071WA156NWDB', start_date='1980-04-01', end_date='2020-10-01')
mf.plot(title = 'Mutual Fund Assets to GDP', figsize=(20, 6))

Treasury Rates

Plots the real long-term treasury rates from the start_date to the end_date.

mf = quandl.get('USTREASURY/REALLONGTERM', start_date='2000-04-01', end_date='2020-10-01')
mf.plot(title = 'Treasury Real Long-Term Rates', figsize=(20, 6))

Stock Fundamentals

Outputs earnings, CPI, price, long interest rate, and PE ratio.

sp = quandl.get('YALE/SPCOMP', start_date='2015-04-01', end_date='2021-10-01')
sp

Futures and Options

Outputs various long, short, and spread data.

fo = quandl.get('CFTC/1170E1_FO_ALL', start_date='2015-04-01', end_date='2021-10-01')
fo