Founded in 2013, Quandl has become a respected data provider. They now boast over 250,000 users from individuals to large hedge funds and investment banks. Here In this guide, we’ll discuss how to import free stock data using quandl python.
Quandl provides a wide-ranging dataset across two main categories:
Core Financial Data: coverage of securities and market data across all asset classes.
Alternative Data: a vast collection of data sources from outside of the normal or regulatory data companies or markets.
What is alternative data?
Alternative data is any form of data that can be used by market participants to evaluate a company or market where that data is from outside the normal data sources.
Normal data sources can include financial statements, regulatory reports, press releases, corporate meetings, and presentations, etc.
With the exponential growth in both our potential to generate data points and the ability to consume and understand it, the rise of ‘Big Data’ and ‘Data Science’ has been meteoric in recent years.
Quandl covers much of the core financial data you are used to and provides both free and premium options. As you’d expect most of the more popular sources require a subscription.
It is in the second class of data where Quandl are seeing the most growth and they are now in fact seen as leading providers of alternative data. Let’s take a closer look at what exactly alternative data is.
Examples of the types of data that coupled with data science and big data techniques can be used to inform investment decisions are:
- Credit and debit card transactions
- Satellite imagery and GPS
- Air/Rail/sea traﬃc
- Social media
- Internet traﬃc and trends
- New car registrations
In a crowded and eﬃcient investment landscape, the race one of these none traditional data sources as a possible ‘edge’ is inevitable.
Up until recently, it was rather diﬃcult and expensive to obtain consistent futures data across exchanges in a frequently updated manner.
That has all changed recently with the release of Quandl. It’s a fantastic source of free financial data. They have a substantial library of daily futures prices in some cases going back to the 1950s!
Not only is the service a robust library of data but their API allows export in CSV, HTML, JSON and XML. In addition, there are bindings for Python, R, Excel, MATLAB, Stata, C++, Java and many other languages/packages.
Without understatement this has made obtaining a wide range of daily financial data incredibly straightforward. In this article we are going to make use of Python (predominantly NumPy and pandas) to obtain futures data from Quandl and store it to disk.
Signing Up For Quandl
The first thing we are going to do is sign up for Quandl so that we can increase our daily allowance of calls to their API. Sign-up grants you 500 calls per day, rather than the default 50. Let’s begin by visiting the site at www.quandl.com:
The first step to begin to investigate Quandl is to sign up for an account here:
Quandl Sign up
- Enter your name
Select Personal (for the purposes of this demo)
Enter Quandl email
2.Enter your email address
3. Enter a secure password
4. Press ‘Create Account’
You will receive an email verification that you must select to activate the account
On login to your new Quandl account, you will see your Dashboard view. The dashboard provides you with easy access to all available data whether free or paid.
Now that we have a Quandl account we will look at how we can use the platform to provide trading data. The first step in that process is to generate the appropriate API key.
Quandl API Key
To work with any version of the Quandl APIs you must first ensure that you have a Quandl API client key. Go to the Account Settings page in your Quandl account:
Your API key which is a long string of random characters will now be displayed. At any point in the future, you can regenerate the key if required here.
Having now obtained your Quandl API key we will investigate the Python API oﬀerings.
The second approach for data integra on we will look at is via the python client provided by Quandl. This method takes a li le more work but can provide much more flexibility when needed.
Installing the Quandl Python Library
After installing python we’ll need to make the Quandl library available before trying to get some data. Recent versions of python (including the latest 2.7.15) come with a tool called pip that makes installation very simple.
Simply run “pip install quandl” on your command line and after a few moments the installation will be complete:
Let’s proceed with an example. I am going to import the Stock data of BSE(Bombay Stock Exchange).To do that, just type BSE in the search bar present in the top of the main page of quandl.com
Now, after getting the search results, move to the le side of the page Filter Section where you can select the free financial data.
Open the red marked BSE result. This will show you the whole Data, Documentation and Usage of the result.
Now click on the Expand op on present at the right side of the page.
This will land you to the page where you can find many options to export the data into libraries, present on the rightmost part of the page. As we are looking for exporting the data into python library, choose the Python option.
On choosing the Python option, you will get a pop-up window showing the code of BSE data along with its authorized token. Just copy that code.
Note: You should have installed the Quandl Python Package
Now, open any IDE of your choice and run the following codes:
This will import the Quandl package into your IDE. Once, it is imported run the following code:
data=quandl.get ("BSE/BOM500180", authtoken="r1ZB4iCyz5tzhgj5Mcis1x4")
Remember, I was talking earlier you to copy the code from the pop-up window opened after clicking on Python library option, that code is used in the above code.
You can also provide start_date and end_date to have filters on the data. This will help you to get the exact range of data on which you want to perform the analysis.
import datetime as dt start_date=dt. datetime (2015,1,1) end_date=dt. datetime (2020,1,1) data=quandl.get ("BSE/BOM500180", authtoken="r1ZB4iCyghyz5tz5Mcis1x4”, start_date, end_date)
You can also write this data to csv, using Pandas:
import pandas as pd data.to_csv("name.csv")
After following through the steps, you now have a good understanding of the service oﬀered by Quandl. The company continues to grow its access to datasets, particularly alternative data, that can support your trading and investing.
If and when you are ready to become a little more advanced in how you retrieve and use datasets the Quandl python API becomes a great op on.
Python comes with first-class native support for working with data, numbers, and statistics. Additionally, many of the most commonly used financial and quant libraries are python based.
However, you decide to source and manage your trading data I hope this overview of Quandl will be of benefit to you.
Want to scrap twitter data with python: Twitterscraper: Scraping Twitter Data with Python