I have also include sample code that downloads indices level from the National Stock Exchange
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#### For OS x libcurl may not work### | |
# This code work without quantmode# | |
NSEIndex = "^NSEI" | |
# Risk free interest rate fixed at 7.5% | |
# Source NSE Mibor | |
riskfree = 0.075 | |
#Specify date | |
dates = c("12/28/2015") | |
tdata <- as.Date(dates, format = "%m/%d/%Y") | |
# Find URL link at NSE website for the bhavcopy of the day | |
urllink = paste("http://www.nseindia.com/content/historical/DERIVATIVES/",(format(tdata, "%Y")),"/",toupper(format(tdata, "%b")),"/fo",toupper(format(tdata, "%d%b%Y")),"bhav.csv.zip", sep="") | |
tempzip = paste(toupper(format(tdata, "%d%b%Y")),"bhav.csv.zip", sep="") | |
tempfilename = paste("fo",toupper(format(tdata, "%d%b%Y")), "bhav.csv", sep="") | |
# download the compressed file and extract | |
download.file(urllink,tempzip, mode="wb" , method = "libcurl") | |
unzip(tempzip, tempfilename, overwrite = T) | |
optiondf <- read.table(tempfilename, sep=",", header=T) | |
print("Downloaded derivative market data for the day") | |
print(head(optiondf)) | |
# Download or read indices' close price | |
indexlnk = paste("http://www.nseindia.com/content/indices/ind_close_all_", toupper(format(tdata, "%d%m%Y")),".csv", sep="") | |
tempindexzip = paste(toupper(format(tdata, "%d%m%Y")),"index.csv", sep="") | |
download.file(indexlnk,tempindexzip, mode="wb" , method = "libcurl") | |
indexdf <- read.table(tempindexzip, sep=",", header=T) | |
print("Downloaded market index data for the day") | |
print(head(indexdf)) |
No comments:
Post a Comment