# Disalignment between global standard deviation and mean of rolling standard deviation

Ciao,

I am working on proprerties of time series. I was trying to deduce an estimate of standard deviation of a process from the series of rolling standard deviation but I've got some issues when I deal with Leavy Process.

I report here a dummy code in Python I am using for this test:

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

def computeRollingStdMean(df, n, column):
return df[column].rolling(n).std().mean()

N = 100
df = pd.DataFrame({ "noise": ( np.random.rand(N)*2-1)*0.1 })
df["StockA"] = ( [20]*(N/2)+[10]*(N/2) ) +df.noise
df["StockB"] = [15]*N + df.noise
df["StdRollingA"] = df.StockA.rolling(50).std()
df["StdRollingB"] = df.StockB.rolling(50).std()

result = pd.DataFrame({"Window" : [ 2, 5, 10, 20, 30, 40, 50, 100 ]})
result["sigmaTargetA"] = df.StockA.std()
result["sigmaTargetB"] = df.StockB.std()
result["sigmaMeanrollingA"] = [ computeRollingStdMean(df, x, column = "StockA") for x in result.Window ]
result["sigmaMeanrollingB"] = [ computeRollingStdMean(df, x, column = "StockB") for x in result.Window ]


From the result table you can see I have an issue with Stock A, that with jump.

In particular my guess would that the mean of the rolling standard deviation would be close to the global standard deviation. Infact this happen for Stock B where there are not jumps.

Of course my statement should depends on the rolling window and it is trivially true when the window has the same dimension of the time series $$N$$ (since there is no rolling process at the end in this case ).

By plotting rolling std time series I am not surprise of the plot of StockA. At the end rolling operator is like a convolution so that I would expect a "hill-like" plot when the rolling window hits the spyke.

But I also thought that, taking the mean, it would not change so much the std estimation.

Can you give a qualitative (or quantitative) meaning to this phenomena?

I am studying rolling standard deviation since I want to deduce other informations such as quantiles, and distriubtion behaviour in time but I must be sure that the std process I've build is coherent.