What is Quandl?
It is a website that host data from hundreds of publishers. This site specializes in data that is collected over time and so far has data categorized as “financial, economic and social,” such as stock and commodity prices, unemployment rates, crime rates and populations.
How we can fetch data from Quandl?
A signup is required on this website that is absolutely free. In the account on the wesite we can get an Auth Token: XXX-XXXXXXXXXXXXXXXX which we will be using in R to extract data.
Why to extract data from Quandl?
For portfolio optimization, we require closing stock prices and it is the best place to get historical data of our preferred stock for any period of time. Like I have extracted the data from 1st apr 2014 to 30th oct 2014.
Now R code to do so,
- We require 2 packages to be installed in R before running this code: 1. Quandl and 2. plyr
- Quandl authorization :
- I have chosen 5 tyre brands as my companies: MRF APOLLO JK-TYRES CEAT and GOODYEAR, you can choose any company as per your choice.
- Use below command, and pass Quandl code for all companies to extract data between specified time frame:
- We will get something like this for all companies:
But we need only, date and closing price. To do so:
- Now, merging closing price of all 5 companies in a single file:
- Exporting this to a csv file, so that it can be used further: