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?
maxdrawdownreturns a list but we just want themaxdrawdowncomponent of that list so try this: