我试图通过使用一次 BDH 拉取来获得每日回报,但我似乎无法让它发挥作用。我考虑使用 quantmod 的 periodreturn 函数,但无济于事。我想填充 PctChg 列,非常感谢任何帮助。
GetReturns <- function(ticker, calctype, voldays) {
check.numeric <- function(N){
!length(grep("[^[:digit:]]", as.character(N)))}
isnumber <- function(x) is.numeric(x) & !is.na(x)
startdate <- Sys.Date()-20
enddate <- Sys.Date()
###############
GetData <- BBGPull <- bdh(paste(ticker," US EQUITY"), c("Open","High","Low","PX_Last"), startdate, enddate,
include.non.trading.days = FALSE, options = NULL, overrides = NULL,
verbose = FALSE, identity = NULL, con = defaultConnection())
##Clean Up Columns and Remove Ticker
colnames(GetData) <- c("Date","Open","High","Low","Close")
GetData[,"PctChg"] <- "RETURN" ##Hoping to populate this column with returns
GetData
}
我不同意使用 quantmod 的想法,甚至会使用 LN(T/T-1) 但我只是不确定如何添加包含这些数据的列。谢谢 !