I am a newbie in R and have difficulties converting daily stock series into monthly ones in xts class.
I have a stock data about the ticker IOO downloaded into a .csv (Comma delimited) file from Yahoo!Finance looking like this:
I have written the following in R in order to read it, convert it to xts and convert daily to monthly:
library(tseries) library(xts) library(PerformanceAnalytics) IOO <- read.csv(file = "IOO.csv", header = TRUE, sep = ",") IOO <- subset(IOO[, c(1,2,3,4,6)]) colnames(IOO) <- c("Date", "Open", "High", "Low", "Close") IOO[,"Date"] <- as.Date(IOO[,"Date"], format = "%m / %d / %Y") IOO <- as.xts(IOO, order.by = as.Date(rownames(IOO), "%Y-%m-%d"), dateFormat = "POSIXct", frequency = NULL, .RECLASS = FALSE) IOO_monthly <- to.monthly(IOO, indexAt='yearmon', drop.time = TRUE, name = NULL)
Error in to.period(x, "months", indexAt = indexAt, name = name, ...) : unsupported type IOO_monthly <- to.period(IOO, period = "months", indexAt='yearmon', name = NULL) Error in to.period(IOO, period = "months", indexAt = "yearmon", name = NULL) : unsupported type IOO_monthly <- to.period(IOO, period = "months", indexAt= NULL, name = NULL) Error in to.period(IOO, period = "months", indexAt = NULL, name = NULL) : unsupported type
I have tried many other combinations of arguments in to.period and to.monthly, but it did not work out.
Thank you in advance for your help.