I tried to download the stock price and compute the standard deviation in rolling window. I found the library PerformanceAnalytics
but they only have the rollin
Try this:
library(zoo)
rollapplyr(1:10, 3, sd, fill = NA)
## [1] NA NA 1 1 1 1 1 1 1 1
See ?rollapply
for more info.
For who is looking for this nowdays, use roll_sd
of roll
package (rdrr.io link).
expr min lq mean median uq max neval
rollapply(STK, width = 5, sd) 34703.2817 37535.3761 40422.77272 38005.02 38357.489 53512.7018 5
roll_sd(STK, 5) 18.9334 18.9973 23.90904 19.14 30.608 31.8665 5