1

I downloaded a time series from Quandl, using the following command:

library(Quandl)
Quandl.auth("YOURSKEY")
mydata <- Quandl("TFGRAIN/SOYBEANS", authcode="YOURSKEY")

Now, I would like to use some functions from the quantmod package. However, I get an error message when I run the following code:

periodReturn(mydata, period="monthly")
# Error in try.xts(x) : 
#   Error in as.POSIXlt.character(x, tz, ...) :
#   character string is not in a standard unambiguous format

I assume this is from the conversion of mydata to an xts object. So, I try the following:

mydata_matrix <- as.matrix(mydata)
mydata_matrix_xts <- as.xts(mydata_matrix)
# Error in as.xts.matrix(mydata_matrix) : 
#   order.by must be either 'rownames()' or otherwise specified
rownames(mydata_matrix) <- mydata_matrix[,1]
mydata_matrix_xts <- as.xts(mydata_matrix)
# Error in as.POSIXlt.character(x, tz, ...) : 
#   character string is not in a standard unambiguous format

...but I still get errors. Any suggestions?

jrouquie
  • 4,315
  • 4
  • 27
  • 43
unmark1
  • 322
  • 3
  • 13

1 Answers1

1

The easiest solution is to explicitly create an xts object to pass to periodReturn:

mydata_xts <- xts(mydata[,-1], mydata[,1])
monthly_return <- periodReturn(mydata_xts[,"Cash Price"], period="monthly")
Joshua Ulrich
  • 173,410
  • 32
  • 338
  • 418