Hello,
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:
Date | Open | High | Low | Close | Adjusted Close | Volume |
---|---|---|---|---|---|---|
12/31/2012 | 63 | 63.959999 | 63 | 63.959999 | 56.11607 | 87900 |
1/2/2013 | 64.940002 | 65.199997 | 64.620003 | 65.080002 | 57.098713 | 77900 |
1/3/2013 | 64.949997 | 64.980003 | 64.639999 | 64.68 | 56.747776 | 36000 |
1/4/2013 | 64.709999 | 65.139999 | 64.639999 | 65.120003 | 57.133812 | 49400 |
1/7/2013 | 64.830002 | 64.919998 | 64.610001 | 64.889999 | 56.932018 | 102000 |
1/8/2013 | 64.650002 | 64.769997 | 64.379997 | 64.580002 | 56.660034 | 31600 |
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.