#' Download Historical Price Data From Wikifolio
#'
#' @param wiki_symbol a character vector specifying the wikifolio
#' symbol to be loaded
#' @param acc_statement if TRUE will download account statement; default FALSE
#'
#' @return returns an xts object containing historical price data of the wikifolio
#' @import zoo
#' @import xts
#' @importFrom lubridate dmy_hms
#' @export
#'
#' @examples getWiki("WF0AAABEST")
#'
getWiki <- function(wiki_symbol, acc_statement = FALSE) {
yesterday <- paste0(
strsplit(as.character(Sys.Date() - 1), "-")[[1]][3], ".",
strsplit(as.character(Sys.Date() - 1), "-")[[1]][2], ".",
strsplit(as.character(Sys.Date() - 1), "-")[[1]][1]
)
if (isTRUE(acc_statement)) {
wiki_url <- paste0(
"https://www.wikifolio.com/dynamic/de/de/invest/download?type=account-statement&name=",
wiki_symbol, "&dateFrom=01.01.2010&dateTo=", yesterday
)}
wiki_url <- paste0(
"https://www.wikifolio.com/dynamic/de/de/invest/download?type=daily&name=",
wiki_symbol, "&dateFrom=01.01.2010&dateTo=", yesterday
)
wiki_historic <- NULL
while (is.null(wiki_historic)) {
try({
tmp <- tempfile()
download.file(wiki_url, destfile = tmp, method = "libcurl")
wiki_historic <- read.csv2(tmp,
fileEncoding = c("UCS-4-INTERNAL"),
skip = 5,
sep = ";",
col.names = c("Date", "Interval", "Open", "Close", "High", "Low"),
allowEscapes = TRUE
)
unlink(tmp)
})
}
wiki_historic$Date <- as.Date(as.POSIXct(
lubridate::dmy_hms(wiki_historic$Date, tz = "UTC")
), tz = "UTC")
wiki_historic <- wiki_historic[, -2]
wiki_historic <- wiki_historic[, c("Date", "Open", "High", "Low", "Close")]
wiki_historic <- as.xts(wiki_historic[, -1], order.by = wiki_historic[, 1])
wiki_historic <- wiki_historic[!(weekdays(index(wiki_historic)) %in%
c("Saturday", "Sunday")), ]
message(paste0("Symbol: ", wiki_symbol))
return(wiki_historic)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.