Vectorized implementation of exponentially weighted moving standard deviation using R?
问题 I am trying to implement a vectorized exponentially weighted moving standard deviation using R. Is this the correct approach? ewma <- function (x, alpha) { c(stats::filter(x * ratio, 1 - ratio, "recursive", init = x[1])) } ewmsd <- function(x, alpha) { sqerror <- na.omit((x - lag(ewma(x, ratio)))^2) ewmvar <- c(stats::filter(sqerror * ratio, 1 - ratio, "recursive", init = 0)) c(NA, sqrt(ewmvar)) } I'm guessing it's not, since its output is different from Python's pandas.Series.ewm.std()