How to compute the rolling trimmed variance/standard deviation?

Viewed 193

I would like to compute the standard deviation (preferably) or the variance of a rolling trimmed mean. More precisely, I would like to have a rolling window, remove the bottom and top percentiles and compute the standard deviation.

So far I have succeeded only by using a for loop that integrates over many consecutive windows but it is too slow. I would like to have a line that does something like this for the mean:

window_length = 10
percentile = 0.1
df.rolling(window_length).apply(lambda x: trim_mean(x, percentile))
0 Answers
Related