movstd

Moving standard deviation over a sliding window.

Category: Data Import and Analysis > Descriptive Statistics

Syntax

S = movstd(A, wlen)

Standard deviation over a window of wlen elements centered on each element.

S = movstd(A, [nb na])

Window of nb elements before and na after the current one, plus the element itself.

Description

movstd computes std inside each window, normalized by the number of elements minus one, so a window that holds a single element gives 0. It shows how the variability of a signal changes in time, which makes it a simple volatility measure.

Windows shrink at the ends of the data. movvar returns the square of the same quantity.

Input arguments

A
Vector or matrix; operates along the first non-singleton dimension.
wlen
Window length.

Output arguments

S
Array of the same size as A.

Example

Rolling volatility

x = [1 2 4 8];
movstd(x, 2)
movstd([3 1 4 1 5 9 2 6 5 3], 3)
Output
ans = 1×4

         0    0.7071    1.4142    2.8284
ans = 1×10

    1.4142    1.5275    1.7321    2.0817    4.0000    3.5119    3.5119    2.0817    1.5275    1.4142

See also

movvar std movmean movmad