# Identify different periods of variance in a time series

I have a time series $x_t$ which may go through different phases of volatility. One example might be some stock that has high variance from 9 AM to 11 AM, low variance from 11 AM to 2 PM, and then high variance again afterwards. Is there a way to identify these different periods of variance?

I am thinking of taking a sliding window of length $L$, computing the variance in that window and running change point detection on that, but I think this requires me to know the distribution of the estimated variance. Another idea I had was to take the variance of the windows and try to fit a Markov chain to it, but I don't know beforehand how many states there should be.

Sorry, the motivating example is not just in finance. I would like to have a way to model "risk" in a time series, which might be risk associated with a financial asset. Another example is in wind energy production - energy produced from wind turbines is highly volatile and unpredictable, but it would be nice to have a learning algorithm that could identify what days of the month is variance of wind energy production high and when is it low

• You can fit a Markov Regime-switching model and test for the number of states. I have also heard good things about autoregressive conditional duration, but am not that familiar with the ins and outs of high frequency analysis. This question would also be appropriate at quant.stackexchange.com. – John Sep 18 '12 at 4:23
• One quick dirty fix would be to square centered time series and then test for changes in mean. – mpiktas Sep 18 '12 at 6:12
• I like mpiktas' suggestion which I think should be an answer. +! for an interesting question. It does seem that you are looking for changes in variance that make the series non-stationary. As you point out formal hypothesis testing requires knowledge of the null distribution for the estimated variance. This would seem to apply to mpiktas' approach too. – Michael R. Chernick Sep 18 '12 at 10:39
• @mpiktas sorry what do you mean by square centering a time series? And would I test for changes in mean using a change point detection? – JCWong Sep 18 '12 at 23:37

There is a lot of literature for testing the change in mean. If it is known that mean does not change, and you need to test the variance, you can convert the problem of testing for change in variance to the one of testing for change in mean with simple transformation.

Suppose your initial data is $X_i$, then define $Y_i=(X_i-\mu)^2$, where $\mu$ is the mean. Then the change in mean of $Y_i$, $EY_i=E(X_i-\mu)^2=Var(X_i)$ will be a change of variance in $X_i$.

The changepoint package in R has a cpt.var function that can calculate changes in variance. There are two tests in that function one for data that can be assumed to be Normal distributed (default option dist="Normal") and one for nonparametric testing (option dist="CSS"). The CSS approach is Cumulative Sum of Squares and is detailed in Inclan & Tiao (1994) paper - further details in ?cpt.var.

Whilst you could square your data (as mpiktas points out in an answer) this can actually inhibit detection of changepoints where the change is small. Think of it, if you square a value that is greater than 1 it gets bigger but if it is smaller than 1 it gets smaller.

Variance change in a time series is discussed in http://www.unc.edu/~jbhill/tsay.pdf . This feature has been added to software available from http:..www.autobox.com. I am involved in the development/incorporation of this very important feature which has neen apparently ignored by SAS,SPSS and others.

You can do this using the mcp package, provided you know the number of segments in advance:

model = list(
price ~ 1 + sigma(1),  # Intercept and variance
~ 0 + sigma(1),  # Change in variance, but not in mean
~ 0 + sigma(1)  # same
)

library(mcp)
fit = mcp(model, df, par_x = "time")


You can infer the time at which these changes take place on top of slopes etc. as well. See more in the mcp article on modeling variance.