[R-SIG-Finance] ?returns not applicable to zoo objects anymore???

Yohan Chalabi chalabi at phys.ethz.ch
Mon Oct 27 12:52:39 CET 2008

>>>> "BO" == Bastian Offermann <bastian2507hk at yahoo.co.uk>
>>>> on Mon, 27 Oct 2008 06:15:20 +0100

   BO> hello,
   BO> does anybody know by any chance why the function ?returns in package 
   BO> timeSeries (formerly fSeries) cannot be applied to zoo objects? And 
   BO> converting zoo objects into class timeSeries does not seem to work as well.
   BO> E.g.
   BO> ticker <- c("^GSPC", "MSFT", "MMM", "DAI", "GS")
   BO> from <- "1970-10-19"              # of type "YYYY-MM-DD"
   BO> till <- "2007-12-31"
   BO> freque <- c("d", "w", "m", "y")
   BO> fq <- 3                           # input 1 for "d", 2 for "w" etc.
   BO> sp500 <- get.hist.quote(ticker[1], start = from, end = till, 
   BO> compression=freque[fq], quote="Close")
   BO> rsp500 <- returns(get.hist.quote(ticker[1], start = from, end = till, 
   BO> compression=freque[fq], quote="Close"))
   BO> above code returns error msg.:
   BO> Error in .classEnv(thisClass) :
   BO>   unable to find an environment containing class "zoo"
   BO> I upgraded my version from 2.7.1 to 2.8.0 and found that the package 
   BO> fSeries has been changed to timeSeries. ?returns always worked fine as 
   BO> coded above and suddenly caused errors as the one above after I had 
   BO> installed 2.8.0. I am now using 2.7.1 again, but the error remains. 
   BO> operating system is windows vista.
   BO> thanks in advance.
   BO> regards

Hi Bastian,

most of the function in timeSeries have been turned to S4 methods.

If you chekc the code of 'returns' methods for 'ANY' class you will see
that we used the the function as(x, "matrix").

But it seems that some time series packages do not support it. I will
change it to as.matrix. This should solve your problem.

I hope to commit today the fixed package to CRAN.


PhD student
Swiss Federal Institute of Technology


More information about the R-SIG-Finance mailing list