#' Fetch XU100 Index
#'
#' Fetches XU100 index data from historical data service
#'
#' @param startDate A character object "MM-DD-YYYY".When argument is NULL function fetches all dates.
#' @param endDate A character object "MM-DD-YYYY". When stardDate is NULL, endDate should be NULL.
#'
#' @export
fBIST <- function(startDate=NULL,endDate=NULL) {
## setup local time according os before set xts.
if (Sys.info()[['sysname']]== "Windows") {
Sys.setlocale("LC_TIME", "English")
}
else
Sys.setlocale("LC_TIME", "en_US.UTF-8") ## to set up xts.
#################################################
if(is.null(startDate)) {
src <- paste0("https://www.google.com/finance/historical?q=INDEXIST%3AXU100&output=csv")
if(!is.null(endDate)) {
stop(paste0("When starDate argument is null, endDate have to null."))
}
}
else {
src <-paste0("https://www.google.com/finance/historical?q=INDEXIST%3AXU100
&startdate=",startDate,"&enddate=",endDate,"&output=csv")
}
delta <- read.csv(src, sep=",")
delta <- delta[,-6]
bar <- strptime(delta[,1], format = "%d-%b-%y","GMT") # set time to xts
delta[[1]] <- bar
delta<- xts(delta[,-1], order.by=delta[,1]) # convert data.frame to xts.
delta
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.