I am trying to use rollapply
from zoo package with function maxdrawdown
from tseries package:
library(zoo)
library(tseries)
x <- c(1,2,4,6,7,10,8,6,5,4,6,7,8)
y <- zoo(x)
z <- rollapply(y,3,maxdrawdown,fill=NA,align="right")
However I get this error message:
Error in zoo(rval, index(x)[i]) :
“x” : attempt to define invalid zoo object
Does that mean I cannot use rollapply
on function maxdrawdown
? Is there alternative solution to work this out?
maxdrawdown
返回一个列表,但我们只想要该列表的maxdrawdown
组件,所以试试这个:
rollapplyr(y, 3, function(x) maxdrawdown(x)$maxdrawdown, fill = NA)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.