Search code examples
rxtsquantmod

Why is xts or quantmod coding each monday as 1?


Is it quantmod::getSymbols that's returning weird weekdays, or is it xts::.indexwday that's messing things up?

library(quantmod)
symbols <- c("SPY", "QQQ")
dfs <- lapply(1:length(symbols), 
             function(i) 
               getSymbols(symbols[i], env = NULL, auto.assign=F))
table(xts::.indexwday(dfs[[1]]))

This is only returning things from 0 to 4. Why does it encode a Monday as a 0?


Solution

  • xts::.indexwday follows the C99/POSIX standard to be consistent with the POSIXlt structure. See the Details section of ?POSIXlt for the possible values, which says:

    'wday' 0-6 day of the week, starting on Sunday.

    That doesn't explain why you see Monday = 0. It would help if your example were fully reproducible, and we had the output from sessionInfo().