Stock market analysis | Quandl and Tidyverse in R

Share on facebook
Share on twitter
Share on linkedin
Share on telegram
Share on whatsapp

Contents

Introduction to comparative analysis

Create the dataset

We will use Quandl, an online repository for financial statistics, macroeconomics and central forex. Quandl has a vast collection of free and open data collected from a range of institutions: central banks, governments, multinational institutions and more. You can use it without payment and with few restrictions.

Both free and premium data are available. Authenticated free users have a limit of 300 calls by 10 seconds, 2,000 calls by 10 minutes and a limit of 50,000 calls per day. Subscribers of premium data have a limit of 5,000 calls by 10 minutes and a limit of 720,000 calls per day.

We will use this online repository to get our data using the package “Quandl” directly from R Console. The Quandl package interacts directly with the Quandl API to provide data in various formats usable in R, download a zip file with all the data from a Quandl database and the ability to search.

For more information on the Quandl package, visits is page.

To get started with Quandl, create an account and get the quandl API key. Please click here to create an account. Then click on the Login button located in the upper right corner of the screen. Once registration is complete, click on here to get the API key.

In our analysis, we have selected the following banks

  • ICICI
  • BETO
  • CANARA
  • AXIS
  • or
  • GNP

We have selected these banks because they are in the price band of 200 a 500 rupees. We will use the following codes to enter the data in the R console.

Quandl(Code=“NSE/—”,collapse=“—”,start_date=“—-”,type=“…”)

The parameters we use are the following:

  • Code Dataset code in Quandl specified as a string or an array of strings.
  • collapse Data.Eg collapse frequency; “Daily”, “monthly”, “weekly”, “annual”.
  • start date Desired start date
  • writes Return data type specified as string. It can be ‘raw’, ‘ts’, ‘zoo’, ‘xts’ o ‘timeSeries’

Now we will download the data, we will add a column “Stock” for stock identifier, and later we will paste the respective stock name in the downloaded dataset. Subsequently, we will consolidate all stock data into a master data frame for analysis.



Quandl.api_key("<Your-API-Key>")


ICICI = Quandl("NSE/ICICIBANK",collapse="daily",start_date="2016-09-01",type="raw")
PNB= Quandl("NSE/PNB",collapse="daily",start_date="2016-09-01",type="raw")
Axis=Quandl("NSE/AXISBANK",collapse="daily",start_date="2016-09-01",type="raw")
Canara=Quandl("NSE/CANBK",collapse="daily",start_date="2016-09-01",type="raw")
BOB=Quandl("NSE/BANKBARODA",collapse="daily",start_date="2016-09-01",type="raw")
SBI=Quandl("NSE/SBIN",collapse="daily",start_date="2016-09-01",type="raw")



ICICI<-cbind(ICICI,Stock="")
PNB<-cbind(PNB,Stock="")
Axis<-cbind(Axis,Stock="")
SBI<-cbind(SBI,Stock="")
Canara<-cbind(Canara,Stock="")
BOB<-cbind(BOB,Stock="")



ICICI$Stock<-paste(ICICI$Stock,"ICICI",sep="")
PNB$Stock<-paste(PNB$Stock,"PNB",sep="")
Axis$Stock<-paste(Axis$Stock,"Axis",sep="")
SBI$Stock<-paste(SBI$Stock,"SBI",sep="")
Canara$Stock<-paste(Canara$Stock,"Canara",sep="")
BOB$Stock<-paste(BOB$Stock,"BOB",sep="")



Master_Data<-rbind(ICICI,PNB,Axis,SBI,Canara,BOB)

Monthly price display

Let's look at the monthly and daily price pattern of stocks using the ggplot package. For this, we will need to group the master data frame according to Stock.

We have heavily manipulated the ggplot theme section to get the desired plot. More information about the plot is provided. here.

Subscribe to our Newsletter

We will not send you SPAM mail. We hate it as much as you.