Вы находитесь на странице: 1из 4

5/11/2016

Quant Master Academy: Download NSE Intraday Data


2

More

Next Blog

prat4u@gmail.com

Dashboard

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.
http://cran.r-project.org/bin/windows/base/
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

GauravB
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("http://www.google.com/finance/getprices?q=",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"))

http://quantmasteracademy.blogspot.in/2012/11/download-nse-intraday-data.html

1/4

5/11/2016

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=as.data.frame(data)
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)
write.csv(finalData,file=fileName,row.names=FALSE)

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

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

27 June 2013 at 11:37

I TRIED NOTHING HAPPENED


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

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

http://quantmasteracademy.blogspot.in/2012/11/download-nse-intraday-data.html

2/4

5/11/2016

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?
Reply
Replies
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 ?
Reply

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....
Reply

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,11............how to convert these in to actual dates.
Pls if anyone can help
jaypeek
Reply

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.
Reply

Inderjit singh 2 October 2015 at 04:12


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

CHANAKYA 29 April 2016 at 00:12


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

CHANAKYA 29 April 2016 at 00:14


friends,
Please provide me intra day data for 28-04-16 nifty put option 7900 strike price.at
somnathdada@yahoo.co.in
Reply

Enter your comment...

Comment as:

Publish

pratik (Google)

Preview

http://quantmasteracademy.blogspot.in/2012/11/download-nse-intraday-data.html

Sign out

Notify me

3/4

5/11/2016

Quant Master Academy: Download NSE Intraday Data

Newer Post

Home

Subscribe to: Post Comments (Atom)

Simple template. Powered by Blogger.

http://quantmasteracademy.blogspot.in/2012/11/download-nse-intraday-data.html

4/4

Вам также может понравиться