[R] help needed on quantmod....

akshay kulkarni akshay_e4 at hotmail.com
Sun Jan 7 13:29:41 CET 2018


dear members,

                            I am using quantmod to work with stock prices...


I am trying to append the data got from getQuote to the one got by getSymbols. The function is named "apnd".  The code is as  follows:


function(x){
              if ((class(x) == "xts") || (class(x) == "zoo")){
                sym <- deparse(substitute(x))
                y <- getQuote(sym)
             # convert to xts
                y1 <- y[,-c(3,4)]
                y2 <- y1[,c("Trade Time","Open","High","Low","Last","Volume")]
             yxts <- xts(y2[, -1], as.Date(y2[, 1]))
             yxts$Adjusted <- yxts[, 'Last']
           return(rbind(x, yxts))

}
              if(class(x) == "list"){
                 for(j in 1:length(x)){
                    sym <- deparse(substitute(x[[j]]))
                y <- getQuote(sym)
             # convert to xts
                y1 <- y[,-c(3,4)]
                y2 <- y1[,c("Trade Time","Open","High","Low","Last","Volume")]
             yxts[[j]] <- xts(y2[, -1], as.Date(y2[, 1]))
             yxts[[j]]$Adjusted <- yxts[[j]][, 'Last']
             yxts[[j]] <- rbind(x[[j]], yxts[[j]])
                                       }
             return(yxts)
}
}

the part with class == xts or zoo is working fine. However, the part with class == list is not working. The point is, instead of running apnd for each stock, I create the list of stock names and run apnd with a for loop. However it is not working.


Any help will be highly appreciated

Very many thanks for your precious time..


yours sincerely,

AKSHAY M KULKARNI


	[[alternative HTML version deleted]]



More information about the R-help mailing list