Anda di halaman 1dari 4


Quant Master Academy: Download NSE Intraday Data



Next Blog


Sign Out

Quant Master Academy

Wednesday, 28 Novem ber 2012

Download NSE Intraday Data

Many retail traders or wanna be traders hit the road block on how to get the
intraday data for NSE stocks. There are many paid services/databases available
which can be subscribed to get the data. However if you are just starting to test
your strategy and do not want to spend on getting the historical data, then here's
the alternative. This post will explain you the R code using which you shall be able to
download intraday 1 min, 5 min ... data from google finance for free. You need not to
be a technical person to use this.
First of all you will need to download R software which is free. Here's the link to
download R for windows OS.
Once downloaded and installed R, you shall see a R icon on your desktop like below.
Double click to open R.

It will open RGui. Go to File --> New Script.

Blog Archive

2013 (4)
2012 (2)
December (1)
November (1)
Download NSE Intraday Data

About Me

View my complete profile

Copy paste the R code below in the new script window.

symbol = "CIPLA"
noDays = 1
interval = 60 #Seconds
dirPath = "D:/Gaurav/Data/"
fileName = paste(dirPath,symbol,".csv",sep="")

download.file(paste("",symbol,"&x=NSE&i=",interval,"&p=",noDays,"d&f=d,o,h,l,c,v,t",sep=""), fileName)
unix2POSIXct <- function (time) structure(time, class = c("POSIXt", "POSIXct"))



Quant Master Academy: Download NSE Intraday Data

data = read.table(fileName,sep=",",col.names=c("DATE1","CLOSE","HIGH","LOW","OPEN","VOLUME"),fill=TRUE)
data$DATE = 0
data$TIME = 0
for (i in 8:nrow(data))
if(i==8 || substr(as.vector((data$DATE1[i])),1,1) == "a")
tempDate = unix2POSIXct(as.numeric(substr(as.vector((data$DATE1[i])),2,nchar(as.vector((data$DATE1[i]))))))
data$DATE[i] = as.numeric(format(tempDate,format="%Y%m%d"))
data$TIME[i] = as.numeric(format(tempDate,format="%H%M"))
} else {
tempDate1 = tempDate + as.numeric(as.vector(data$DATE1[i]))*interval
data$DATE[i] = as.numeric(format(tempDate1,format="%Y%m%d"))
data$TIME[i] = as.numeric(format(tempDate1,format="%H%M"))
data1=(data1[data1$TIME>915 & data1$TIME<=1530,])

finalData = data.frame(DATE=as.vector(data1$DATE),TIME=as.vector(data1$TIME),CLOSE=as.vector(data1$CLOSE),HIGH=as.vector(data1$HIGH),LOW=as.vect
finalData = data.frame(DATE=data1$DATE,TIME=data1$TIME,CLOSE=data1$CLOSE,HIGH=data1$HIGH,LOW=data1$LOW,OPEN=data1$OPEN,VOLUME=data1$VOLUME)

In the above code, change the first four lines shown below.
symbol = "CIPLA"
noDays = 1
interval = 60 #Seconds
dirPath = "D:/Gaurav/Data/"

1. The first line is the symbol name.

2. Second line sets the number of days for which data is to be downloaded. Note
that, longer history data is not available.
3. Third line sets the time interval/frequency of data. It's in seconds.
4. Fourth line sets the folder where data is to be stored.
Once done, select all lines and press F5 to run the code. And data will be stored in
the specified directory with symbol name.
Now, enjoy downloading data. Later on I will explain how to create an automated job
in windows to download daily data automatically.
Posted by GauravB at 02:19

+2 Recommend this on Google

Labels: Algo Trading, Backtesting, NSE Intraday Data, Quant Trading

Parikshit Bhinde 14 March 2013 at 20:08
Very informative post! Thanks for sharing the method.

27 June 2013 at 11:37


Gaurav 23 August 2013 at 03:49
Can you tell me what exactly you tried? And if any error are you facing?

Sachin Gupta 28 October 2013 at 03:15

Hey man, Your code is pretty useful! I am doing my project for which i require tick by tick data. I
used your script to get the minute by minute data(i think that is the best interval size i can get



Quant Master Academy: Download NSE Intraday Data

using google finance). But I couldn't get the minute-by-minute data beyond the last 1 month. Do
you have any clue?
Sachin Gupta 30 October 2013 at 05:15
Hey, never min I figured that out! google and even yahoo finance provide minute by
minute data for the last 15-30 days only. Thank you anyway for this great post.

neeraj kumar 20 October 2015 at 07:59

Hey, how you were able to download the past minute to minute data ?? Which part of
the code need to be changed ?

Sean Fallon 19 January 2014 at 22:46

Try using quantmod package in R, gives you better charts as well. Only problem is, the charts
are not interactive....

Dr Jee 21 January 2014 at 11:32

Hello All,
I am getting the price & volume but instead of date iam getting TIMEZONE_OFFSET=330
a1388547480 ---8,9,10, to convert these in to actual dates.
Pls if anyone can help

Shankar pandala 6 April 2015 at 01:09

Thanks a lot!!
Can u please give R code for converting data and time in this data to R Date and time format.

Inderjit singh 2 October 2015 at 04:12

its showing
> write.csv(finalData,file=fileName,row.names=FALSE)
Error in : object 'finalData' not found
what to do ????

CHANAKYA 29 April 2016 at 00:12

Please provide me intra day data for 28-04-16 nifty put option 7900 strike price.

CHANAKYA 29 April 2016 at 00:14

Please provide me intra day data for 28-04-16 nifty put option 7900 strike

Enter your comment...

Comment as:


pratik (Google)


Sign out

Notify me



Quant Master Academy: Download NSE Intraday Data

Newer Post


Subscribe to: Post Comments (Atom)

Simple template. Powered by Blogger.