How can I use a zoo
object with the Perfor开发者_开发问答manceAnalytics
package?
It says that I need a timeseries but I can convert it properly.
thanks
The following code example using the PerformanceAnalytics
function Return.annualized
suggests that
PerformanceAnalytics
does work withzoo
objects (in fact themanager
dataset used as an example in the manual turns out to be azoo
object)- It should be possible to convert a
zoo
object into ats
object and get the same results
So if you still have a problem, you will need to illustrate it in more detail
> library(PerformanceAnalytics)
> library(zoo)
>
> set.seed(1)
> x.date <- as.Date(paste(2003, 2, c(1, 3, 7, 9, 14), sep = "-"))
> xzoo <- zoo(runif(5), x.date)
> xzoo
2003-02-01 2003-02-03 2003-02-07 2003-02-09 2003-02-14
0.2655087 0.3721239 0.5728534 0.9082078 0.2016819
> is.ts(xzoo)
[1] FALSE
> is.zoo(xzoo)
[1] TRUE
> Return.annualized(xzoo)
[,1]
Annualized Return 193340828
>
> xts <- as.ts(xzoo)
> xts
Time Series:
Start = 12084
End = 12097
Frequency = 1
[1] 0.2655087 NA 0.3721239 NA NA NA 0.5728534 NA 0.9082078
[10] NA NA NA NA 0.2016819
> is.ts(xts)
[1] TRUE
> is.zoo(xts)
[1] FALSE
> Return.annualized(xts)
[,1]
Annualized Return 193340828
精彩评论