I'm about to show non-constant volatility for a time series. To do so, I was thinking about making different plots containing different amount of data to show that the volatility vary in the different plots. But I have to define a function that takes n consecutive data points and produces one output variable. The function obviously has to with the standard deviation formula, but I do not know how to construct such a loop that satisfies my criteria.
Picture of what my function has to do
In the picture n = 5. Thanks.
Edit: I will try to clarify from an example, note I have 2700 observations. My function has to take five data points and look at the discrete standard deviation of these five data points. That will be the first output variable. The next output variable will take the next five consecutive data points and look at the discrete standard deviation and return the value. Then the third output variable will take the next five consecutive data points and so on... Though, instead of five it should be able to look at some random number of consecutive data points.