Rolling standard deviation measures the variability within a sliding window of a time series. It is widely used in finance (Bollinger Bands), anomaly detection, and signal processing to quantify local volatility. A rising rolling standard deviation indicates increasing instability, while a falling one signals convergence.
Given a list of values and a window size, compute the population standard deviation for each sliding window position.
For each window starting at position i with size k:
μ=k1j=0∑k−1x[i+j]σ=k1j=0∑k−1(x[i+j]−μ)2The output has length n - k + 1.
Input:
values = [1, 2, 3, 4, 5], window_size = 3
Output:
[0.8165, 0.8165, 0.8165]
Window [1,2,3]: mean=2, variance=((1-2)^2+(2-2)^2+(3-2)^2)/3=2/3, std=sqrt(2/3)=0.8165. Each consecutive window of 3 has the same spread.
Input:
values = [5, 5, 5, 5], window_size = 2
Output:
[0.0, 0.0, 0.0]
All values are identical, so every window has zero variance and zero standard deviation.
For each window of size k, first compute the mean, then compute the average of squared deviations from the mean, and finally take the square root. Use math.sqrt or ** 0.5.
Remember to use population variance (divide by k, not k-1). The output length is len(values) - window_size + 1, same as a moving average.
Sign in to take notes on this problem
Accepts: array
Accepts: number
Rolling standard deviation measures the variability within a sliding window of a time series. It is widely used in finance (Bollinger Bands), anomaly detection, and signal processing to quantify local volatility. A rising rolling standard deviation indicates increasing instability, while a falling one signals convergence.
Given a list of values and a window size, compute the population standard deviation for each sliding window position.
For each window starting at position i with size k:
μ=k1j=0∑k−1x[i+j]σ=k1j=0∑k−1(x[i+j]−μ)2The output has length n - k + 1.
Input:
values = [1, 2, 3, 4, 5], window_size = 3
Output:
[0.8165, 0.8165, 0.8165]
Window [1,2,3]: mean=2, variance=((1-2)^2+(2-2)^2+(3-2)^2)/3=2/3, std=sqrt(2/3)=0.8165. Each consecutive window of 3 has the same spread.
Input:
values = [5, 5, 5, 5], window_size = 2
Output:
[0.0, 0.0, 0.0]
All values are identical, so every window has zero variance and zero standard deviation.
For each window of size k, first compute the mean, then compute the average of squared deviations from the mean, and finally take the square root. Use math.sqrt or ** 0.5.
Remember to use population variance (divide by k, not k-1). The output length is len(values) - window_size + 1, same as a moving average.
Sign in to take notes on this problem
Accepts: array
Accepts: number