You are correct in wanting time to be in POSIXct format. Quantstrat uses xts
objects, which you'll need to create. You didn't provide an easily reproducible so the first bit of code here generates your data:
library(xts)
data <- "
1 2016-09-27 02:00:00 165.50 165.58 165.46 165.47 2001
2 2016-09-27 03:00:00 165.47 165.65 165.46 165.63 1345
3 2016-09-27 04:00:00 165.64 165.92 165.59 165.91 1241
4 2016-09-27 05:00:00 165.91 166.13 165.91 165.97 880
5 2016-09-27 06:00:00 165.98 165.98 165.76 165.78 748"
dat <- read.table(text = data,
col.names = c("num", "date", "time", "Open" , "High", "Low", "Last", "Volume"))
dat <- cbind("Timestamp" = paste(dat$date, dat$time), dat)
# Make dat look just like your example when loaded in R:
dat[, c("num", "date", "time")] <- NULL
# Now have your object, which would be a data.frame:
dat
# Timestamp Open High Low Last Volume
# 1 2016-09-27 02:00:00 165.50 165.58 165.46 165.47 2001
# 2 2016-09-27 03:00:00 165.47 165.65 165.46 165.63 1345
# 3 2016-09-27 04:00:00 165.64 165.92 165.59 165.91 1241
# 4 2016-09-27 05:00:00 165.91 166.13 165.91 165.97 880
# 5 2016-09-27 06:00:00 165.98 165.98 165.76 165.78 748
posix_times <- as.POSIXct(dat[, 1])
x_dat <- xts(x = dat[, 2:NCOL(dat)], order.by = posix_times)
> x_dat
# Open High Low Last Volume
# 2016-09-27 02:00:00 165.50 165.58 165.46 165.47 2001
# 2016-09-27 03:00:00 165.47 165.65 165.46 165.63 1345
# 2016-09-27 04:00:00 165.64 165.92 165.59 165.91 1241
# 2016-09-27 05:00:00 165.91 166.13 165.91 165.97 880
# 2016-09-27 06:00:00 165.98 165.98 165.76 165.78 748
> class(x_dat)
#[1] "xts" "zoo"
x_dat
is what you can use in quantstrat
.
PS:
You may find your learning process with quantstrat
will be a lot faster if you follow a good resource like http://www.r-programming.org/papers
or the (not free =( ) quantstrat course at datacamp: https://www.datacamp.com/courses/financial-trading-in-r