How can I use a zoo
object with the PerformanceAnalytics
package?
It says that I need a timeseries but I can convert it properly.
thanks
How can I use a zoo
object with the PerformanceAnalytics
package?
It says that I need a timeseries but I can convert it properly.
thanks
PerformanceAnalytics
関数を使用した次のコード例Return.annualized
は、
PerformanceAnalytics
オブジェクトで動作しzoo
ます(実際、manager
マニュアルで例として使用されているデータセットはオブジェクトであることが判明しましたzoo
)zoo
オブジェクトをオブジェクトに変換しts
て同じ結果を得ることができるはずですそれでも問題がある場合は、それをより詳細に説明する必要があります
> 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