开发者

R, zoo with performance analytics

开发者 https://www.devze.com 2023-01-15 04:58 出处:网络
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.

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

  1. PerformanceAnalytics does work with zoo objects (in fact the manager dataset used as an example in the manual turns out to be a zoo object)
  2. It should be possible to convert a zoo object into a ts 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
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号