I have some question about realized variance(RV) and I have some sample prices below to work with. You can run the R code below to build a vector of log returns. Three are 78 5-minute buckets in a trading day (from open to close) so the log returns vector has length(logreturns) = 78.
The calculation for RV is the sum of the squared log returns. Where X is the log PRICE and n is the number of buckets in a day RV equals:
$$
RV = \sum\limits_{i=1}^{n} (X_{t_{i+1}} - X_{t_{i}})^2
$$
So below I calculate RV, then get the volatility by take square root, then annualize it. .
RV = sum(logreturns^2)
RV
[1] 2.509554e-05
daily_volatility = sqrt(RV)
daily_volatility
[1] 0.005009545 # i.e. open to close volatility = .49%
annualized_volatility = sqrt(260)*volatility
annualized_volatility
[1] 0.08033328 # on an annualized basis that is 8.03%
Question 0: My price time series was built using the last tick in each 5-minute bucket. Would it be better to use the VWAP in each bucket instead of the last tick in each bucket? VWAP would be defined as the product of the PRICEs of all the tick (P) and VOLUME of all the ticks (V) in a 5-minute bucket divided by the sum of the volume of all the ticks in a bucket 5 minute bucket. ie.VWAP = (P*V)/sum(V)
Question 1: Can it then be interpreted that the volatility for this day was .5%? or 8.03% on an annualized basis?
Now I am measuring RV so that I can use it in post-trade regressions looking at trade costs. I will be measuring volatility from the time the market opens to the time time a trade takes place. For example if a trade takes place in the 16th minute there will be 3 5-minute buckets used in the RV calculation. If another trade takes place in the 76th minute there will be 15 5-minute buckets used. I believe I need to scale the RVs to a daily RV before I can use them in a regression. This is because, using the example above, if the 16th minute RV and the 76th minute RV are the same that would be misleading because the 16th minute RV is not on the same time scale. So...
Question 2: How should one properly scale RVs calculated from different number of buckets? For example using the logreturns vector lets say a trade takes place in the 21 minute so I will use the first 4 5-minute buckets to calculate an RV:
RV = sum(logreturns[1:4]^2) # HERE ONLY USE 1st 4 BUCKETS
daily_volatility = sqrt(RV)
daily_volatility
[1] 0.001503846 # here the volatility using the first 4 buckets is .15%
How should this 0.001503846 be scaled so that it can be used in post trade regressions with different RVs.
I was thinking scaling by the number of buckets used to get:
scaled_volatility = daily_volatility * sqrt(78/4)
[1] 0.006640803 #daily volatility would be .66%
scaled_volatility_annualized = daily_volatility * sqrt(78/4)*sqrt(260)
[1] 0.1070797 # annualized volatility would be 10.7%
Would that be correct?
Question 3: Does it even make sense to check the annualized RV number against a close-to-close volatility number? Should there be any expectation that they are similar or different?
# R code to build price vector
prices= c(69.354346196)
prices= rbind(prices,69.290432)
prices= rbind(prices,69.300752759)
prices= rbind(prices,69.219979108)
prices= rbind(prices,69.208148518)
prices= rbind(prices,69.246598516)
prices= rbind(prices,69.316969994)
prices= rbind(prices,69.382236297)
prices= rbind(prices,69.439047295)
prices= rbind(prices,69.303030426)
prices= rbind(prices,69.215724903)
prices= rbind(prices,69.235499743)
prices= rbind(prices,69.228075019)
prices= rbind(prices,69.226522461)
prices= rbind(prices,69.278545753)
prices= rbind(prices,69.279946134)
prices= rbind(prices,69.294667184)
prices= rbind(prices,69.325204623)
prices= rbind(prices,69.296794394)
prices= rbind(prices,69.271009358)
prices= rbind(prices,69.258763087)
prices= rbind(prices,69.230728678)
prices= rbind(prices,69.250976948)
prices= rbind(prices,69.275912906)
prices= rbind(prices,69.266953813)
prices= rbind(prices,69.275524358)
prices= rbind(prices,69.257009203)
prices= rbind(prices,69.248320494)
prices= rbind(prices,69.239413345)
prices= rbind(prices,69.169838829)
prices= rbind(prices,69.15291089)
prices= rbind(prices,69.181671655)
prices= rbind(prices,69.171275889)
prices= rbind(prices,69.149855396)
prices= rbind(prices,69.181647188)
prices= rbind(prices,69.116412877)
prices= rbind(prices,69.169805719)
prices= rbind(prices,69.17149549)
prices= rbind(prices,69.171311493)
prices= rbind(prices,69.150704259)
prices= rbind(prices,69.168990869)
prices= rbind(prices,69.167502639)
prices= rbind(prices,69.169828509)
prices= rbind(prices,69.136281414)
prices= rbind(prices,69.137206043)
prices= rbind(prices,69.108438269)
prices= rbind(prices,69.10342004)
prices= rbind(prices,69.165636224)
prices= rbind(prices,69.193646811)
prices= rbind(prices,69.2072143)
prices= rbind(prices,69.232462739)
prices= rbind(prices,69.255101895)
prices= rbind(prices,69.278061272)
prices= rbind(prices,69.33507867)
prices= rbind(prices,69.378308505)
prices= rbind(prices,69.373578935)
prices= rbind(prices,69.42822269)
prices= rbind(prices,69.433781902)
prices= rbind(prices,69.448787913)
prices= rbind(prices,69.441731914)
prices= rbind(prices,69.444092485)
prices= rbind(prices,69.440302981)
prices= rbind(prices,69.379244744)
prices= rbind(prices,69.430264889)
prices= rbind(prices,69.441485395)
prices= rbind(prices,69.492248013)
prices= rbind(prices,69.513478661)
prices= rbind(prices,69.567990492)
prices= rbind(prices,69.580500697)
prices= rbind(prices,69.51972368)
prices= rbind(prices,69.561692927)
prices= rbind(prices,69.563459496)
prices= rbind(prices,69.538617278)
prices= rbind(prices,69.58494135)
prices= rbind(prices,69.564894664)
prices= rbind(prices,69.548091511)
prices= rbind(prices,69.604420178)
prices= rbind(prices,69.574414993)
prices= rbind(prices,69.632808692)
head(prices)
logreturns = diff(log(prices))#log returns
head(logreturns)