Python: I Have Tested Quandl API and How to Get Real Estates & Economics Data in One Line of Code. | by Sajid Lhessani | Towards Data Science

In this article, you will learn how to request and download a wide range of data, such as economics, real estates or even market data for free—using a free Python package without calling an expensive API. I have tested it for you. Does that work? Let’s see.
If you are keen to hack it yourselves now, you can get the full Python code at the end of this article.
Now let’s go guys !!!! & Merry Christmas :)
First, let’s start by defining Quandl API.
Quandl delivers market data from hundreds of sources (officials such as Bank of England/India etc or independent providers) via an API key. These data can be requested through different languages such as Python, R or Excel.
The types of data which can be requested through Quandl are broad; you can ask end of the day US Market data, economic indicator from Bank of Brazil, Federal Reserve Economic Data(growth, employment, inflation, labour, manufacturing and many more US financial data), official GDP per country, or even company hiring activities and many others.
And during this test, we are going to focus on three types of data:
US Stock exchange market data.
Federal Reserve Economic Data for the commodity price, which is a trendy investment at the moment.
Zillow Real Estate and Rental Market Place Data — This dataset is the leading real estate and rental marketplace.
Now that we have introduced Quandl, let’s start with the tests.
First of all, if you want to track my progress and before to start, you will need to have installed on your machine a Python 3 version and the following packages:
Pandas
NumPy
Quandl
Plotly (Not mandatory, but useful for plotting)
If any of these packages are not already installed, you can use the pip command, as shown below.
pip install quandlpip install plotly
Once you have ensured that the following packages are installed, we can start.
If you already have experience with Python, you can jump to the second step. The first step will consist of importing data.
The first step will consist of importing the necessary packages.
You will start by importing your packages previously installed by using the following lines of code:
Once we are set up, let’s pursue the next step.
As explained above, if you are an investor, you must be aware that in 2020 & 2021, one of the trendiest commodity is Gold.
Indeed, Gold is correlated negatively to economic growth, and in time of the pandemic, that has been a lucrative investment for multiple investors.
Now, the question is, how to get robust and trustful Gold price data for a specific local currency (either if you are American, Canadian, Indian, British ... )?
Let’s analyze now how you can hack it using Quandl.
Quandl API is working using a tick code & an API key, which can be accessed for free. (All explanations in the tutorial videos in the last part, plus a gift). The user will need to insert the following 3 arguments (tick code, start & end date) and type the following code structure in order to request data:
quandl.get(tick code, start_date, end_date)
Now that we got the structure, the first step will consist of researching “Gold Price”, in the research bar at the top left corner.
Once the research has been performed, we will select a free dataset of our choice.
I am going to use the dataset provided by the London Bullion Market Association for the test. According to Quandl, LBMA is an international trade association in the London gold and silver market, consisting of central banks, private investors, producers, refiners, and other agents & an official data provider.
The tick code associated is “LBMA/GOLD”. So, let’s type the following line of code:
And here is the output:
Now if you want to plot your data:
You can have the full code explanation in the video tutorial(Part III, minute 8:25 to 11:20).
Overall, the data looks accurate (less than 1$ difference) if you compare it to Bloomberg.
The first test is positive.
The second test, how can we upload and request US stock exchange data for investment and algorithmic trading?
If you want to learn how to start with algorithmic trading with Python and impress your colleague at work or university. I highly recommend the following course, most of the code has been taken from this source:
www.udemy.com
Similarly to the request above, we are going to start by searching for market data.
We will choose wiki continuous future as a data source and request to get data for GOOGLE. The ticker for this request is “WIKI/GOOG”. So, let’s type the following line of code:
Once we have executed the line of code above, here is the output:
Boom! We got the data, plus extra information regarding split ratio, volume & dividends.
The possibility to download market data through Quandl API is not the most efficient. I have tested a couple of other API in the past, such as Yahoo Finance or Bloomberg, and the difference is important. You can find the full test below and see by yourselves the difference:
towardsdatascience.com.
However, I like the fact that Quandl is providing the possibility to get dividends day and the amount. As an investor and algorithmic trader that an excellent point to add to our model.
Now, that we have tested the market data import, let’s jump to the last test.
Did you ever ask yourselves if your monthly rent is over or underpriced? Or based on your area, if your one-bedroom apartment bought was overpriced?
In this section, we are going to explore how to download local real estates data using Quandl.
Similarly to what we have done previously, you will need your ticker code. To find it we are going to search “Zillow New York” in the search bar at the top left corner.
Once you have chosen the New-York’s borough data that you want, you should type the tick code and execute the following line of code:
In the line above we are requesting the data for a one-bedroom apartment in Harlem vs Manhattan midtown. (Full explanation in the video below. Minute 12:20 to 17:50)
And here is the final output of the price of a 1 bedroom apartment of 2 New York borough over-time:
I hope you enjoyed this test; I took a lot of fun to decorticate this API. You can go further using Quandl API and test it yourselves.
Overall, Quandl has a lot of strength and disadvantage. The aim behind this article was to propose you to discover an API which you will be able to use in the future.
I am teaching data science to my son sometimes, and I like using Quandl because you can get a clean and official dataset in one line of code. Suppose you want to test your Artificial Intelligence and Machine Learning models. In that case, it can be an excellent way to have the necessary randomized data (mainly for a neural network which require a massive input dataset).
Furthermore, the types of data are wide. If you are working in medical, you can request plenty of data concerning healthcare, or if you are a statistician, you can explore data provided by the government on this platform to enhance your analysis.
If you want to know more about API’s test and how to code an algorithm for trading, I recommend the following youtube channel:
https://www.youtube.com/channel/UCZorZ8KWmTON7aO84JJBwlQ?
Thank you for your attention
Happy coding
Learn algorithmic trading in one day (Full training):
www.udemy.com
Live Trading Test:
medium.com
YahooFinance API Test: