# How to calculate historical intraday volatility?

Sorry for what must be a beginner question, but when I went to write code I realized I didn't understand exactly how historical volatility, or statistical volatility, is defined. Wikipedia tells me "volatility is the standard deviation of the instrument's logarithmic returns", and logarithmic return is defined as $\ln\left(\frac{V_f}{V_i}\right)$, where $V_f$ is closing price and $V_i$ is opening price.

If I want to calculate the volatility of a minute bar, from the raw ticks, do I just use the first and last tick in that minute? If I use first and last ticks in the minute (i.e. bar open/close), I will have a single logarithmic return, so s.d. of that one value will be 0. In an answer to this question, the intraday volatility chart is described as U-shaped. Exactly what sums do I need to do to generate that intraday volatility chart from the day's ticks?

In R terms, is logarithmic return:

#x is xts object containing ticks
r = na.omit( lag(x)/x )
lnr = log(r)


Background: I have a stream of ticks, and as I turn them into minute (and higher period) bars (using R's xts module) I also calculate the mean and s.d. Is the standard financial measure of volatility different from standard deviation? If not, can one be derived from the other?

If the above definition of volatility is correct, my answer (based on eyeballing the plots, and on running cor) seems to be that they are really quite different; I'm still chewing over how that gels with the answers here.

-
I've cleaned this up a bit by editing your comments into your question and posting my comments as an answer. –  Tal Fishman Dec 16 '11 at 3:01
@TalFishman Thanks for the edits Tal; I also moved my comment over to your answer. –  Darren Cook Dec 18 '11 at 2:16

The expression you have is fine. But more generally, for the intraday volatility, I don't think there "the correct definition". More like, whatever works in the given context. I found the following notes by Almgren pretty useful:

http://cims.nyu.edu/~almgren/timeseries/notes7.pdf

-
Thanks @LazyCat Knowing that all the sources I've seen are being deliberately vague on implementation details, not just being brief, was the thing I needed to know. My eyes glazed over on parts of that PDF, but the comment at the top of p.10 (people generally use "ad hoc" sampling) and the suggestion at the end to compute across a range of parameters and not trust a result that varies a lot, was very helpful. –  Darren Cook Dec 16 '11 at 1:19

The main issue measuring intraday volatility is called "signature plot": when you zoom in, the volatility measure (i.e. empirical quadratic variations) explode.

Similarly you have the "Epps effect" for correlations: when you zoom in, the correlations collapse (it is at least a mechanical effect).

For the volatility a lot of models can correct this: - first a multiscale filter (use wavelets for instance) - then an additive noise model (the ZAM estimator, see Almgren's note) - or a random time observation (i.e. liquidity/tick based one) like this: http://papers.ssrn.com/sol3/papers.cfm?abstract_id=1989281 - an Hawks model is also a nice solution if you like point processes, see for instance: http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.187.1605

But the most important is what do you want to do with your volatility model?, which market dynamics do you want to capture? If it is market risk, it will not be the same if it is to compute the probability to cross a price barrier, or to compute a price interval for the price during the closing fixing.

-

Statistical volatility is the standard deviation of a window of log returns. For example, 30-day statistical volatility is the standard deviation of 30, one-day log returns. The log return comes from the assumption that log stock returns are normally distributed.

Statistical volatility differs from implied volatility which is the volatility input to some options pricing model (read: Black-Scholes) which sets the model price equal to the market, or observed price.

Statistical and implied volatility are used for different purposes.

Variance of course is the standard deviation of a random variable squared. Variance is has useful properties in the normal distribution (e.g. variance is additive while standard deviation is not) which is used extensively in modeling the dynamics of equity prices.

In measuring central tendencies of returns in the financial context, variance doesn't really make sense because variance is not in standardized units like standard deviation. Unless you're dealing with variance swaps or stochastic volatility models, you'll probably be dealing exclusively in standard deviation.

So to answer your question in short, calculate lag-number of log returns, take the standard deviation and that's the lag-period statistical volatility of your returns.

With all that said, this is a fairly basic question for this group and I'm not sure it will last...

-
Thanks for the answer. Cutting to your short answer, does "calculate lag-number of log returns" mean the same as the R code I've written? Or do I have it wrong? –  Darren Cook Dec 14 '11 at 8:20
More questions, sorry. It is statistical, not implied, volatility I'm interested in. You are contrasting it with variance, not s.d.; does that mean the only difference between stastical volatility and variance is the square. I.e. stastical volatility and standard deviation are the same? Because the standard deviation of log returns in a time period and the standard deviation of actual prices in the same period appear to be quite different (i.e. peaks on the two charts are in different places). –  Darren Cook Dec 14 '11 at 8:26
@DarrenCook it doesn't really make sense to take SD of price. Vol is always something along the lines of SD of returns. –  Tal Fishman Dec 14 '11 at 12:18
@DarrenCook The code appears correct but I don't know R. Tal is right, we don't take the SD of raw prices because it doesn't make sense in a financial context. Yes, statistical volatility and the standard deviation of log returns are the same. And yes, variance is the square of SD. You have to think outside of strict statistics here and think within the context of financial markets and data. –  strimp099 Dec 14 '11 at 14:41

Your code for volatility seems correct, if you want minute volatility, but is that really what you want? See this recent question on annualizing volatility from intraday data. Also, using first and last tick is what is generally done, but over very short time intervals such as a minute, you will have microstructure issues. Another question here deals with the state of the art in volatility estimation and forecasting. It doesn't really make sense to take SD of price. Vol is always something along the lines of SD of returns.

Regarding your comment that there is only a single open/close observation for a given interval (e.g., bar), you must plot an entire days worth of minute open/close squared returns as a function of time to see the U-shape. The volatility is the mean of squared returns. Historical volatility is defined by two parameters, the interval over which you take returns and the lookback period over which you average those squared returns. In your case, you may also sum rather than average all the squared returns for one day to obtain the "daily volatility measured over minute intervals."

Note I have assumed that returns have a mean of zero in the above. This is a very reasonable assumption for returns over such a short horizon.

-
Thanks for "Historical volatility is defined by two parameters"; now it becomes clear. When someone asks me for a volatility measure I now know I need to ask them two questions, not just one. –  Darren Cook Dec 18 '11 at 2:16

On a theoretical level and for low frequency data (e.g. daily), your formula seems right. However, since you are talking about one minute bars, things may get a little messy. There is a vast literature on this, and empirically, things are complicated due to market micro-structure noise. Namely, you need to do consider jumps, errors, periods of low volume, high volume periods (e.g. market opening of US markets when you look at European markets), and many other things. A nice overview on the topic with some references to literature is here: http://economics.ouls.ox.ac.uk/13045/1/2008OMI11.pdf

-