Explanation 1
The live starter code is self-contained and uses only runner-compatible functions.
Loading
Lesson 17 of 22
Advanced Topic – Optional. Compare rolling, annualized, realized, and range-based measures with explicit units and sampling choices.
Advanced Topic – Optional
This chapter extends the core pathway. Complete Chapters 1–14 first, then use this material when your question and data justify the added model complexity.
Motivation
Volatility is latent, so every estimate embeds a window, grid, annualization factor, or model.
Why this matters
Compare rolling, annualized, realized, and range-based measures with explicit units and sampling choices.
Packages and data
Base R; zoo, xts, highfrequency, and TTR are optional.
Explanation 1
The live starter code is self-contained and uses only runner-compatible functions.
Explanation 2
Book-only outputs are labelled when the separate source dataset or advanced package was not supplied.
Explanation 3
R code, paths, function names, and formulas remain left-to-right in every locale.
Terminology
Windowed standard deviation using recent returns.
Responsive but backward-looking
Sum of squared intraday log returns.
Variance units, not volatility
Bid-ask bounce, discreteness, and asynchronous trading distort fine grids.
Finer is not always better
Notation and formulas
annualized volatility = sqrt(k) × sd(returns); realized variance = sum(r_j^2)
Variance scales by k under the conventional independent-increment approximation, so standard deviation scales by sqrt(k).
Worked example
Scenario
How does sampling aggregation alter realized volatility in a clean simulation?
R check
set.seed(1717)
r <- rnorm(390,sd=.012/sqrt(390))
intervals <- c(1,5,15,30,65)
rv <- sapply(intervals,function(k){g<-ceiling(seq_along(r)/k); a<-as.numeric(rowsum(r,g)); sqrt(sum(a^2))})
print(data.frame(minutes=intervals,realized_vol_percent=100*rv))Without microstructure noise, the exercise isolates sampling variation rather than real tick-data bias. Limitation: Real high-frequency data add market microstructure, gaps, and timestamp issues; this simulation does not.
Visual
Realized-volatility estimates vary across aggregation intervals.
R connection
Run the self-contained starter code in the protected STATLAB R runner. The code prints an auditable result and avoids network or unrestricted file access.
Live R Lab
Run a self-contained example, verify its output, and explain one limitation for measuring volatility and realized variation.
Ready to run
Common mistake
Do not annualize a standard deviation by multiplying by periods; use the square root.
STATLAB Tip
Put the unit in object names such as annualized_vol_percent.
Guided practice
Scenario
Compare 6-, 12-, and 24-period rolling windows for responsiveness and missing early estimates.
Compare your result with the definition, units, and model assumptions—not only with a target number.
Exercises
Complete these without looking at the selected solutions. More than one defensible program may exist.
Explanation 1
Show realized variance units.
Explanation 2
Add alternating bid-ask noise.
Explanation 3
Compute Parkinson variance.
Selected solutions
These are compact solution routes. Confirm dimensions, units, and any changed modelling choices.
Explanation 1
Squared log returns sum to squared-return units.
Explanation 2
Perturb alternating observed prices and compare sampling grids.
Explanation 3
mean(log(high/low)^2)/(4*log(2))
Chapter summary
Compare rolling, annualized, realized, and range-based measures with explicit units and sampling choices.
Explanation 1
Window length affects rolling estimates.
Explanation 2
Realized variance sums squares.
Explanation 3
Fine grids face noise bias.
Explanation 4
Range measures add information under assumptions.
Terminology
rolling window
Use in Measuring Volatility and Realized Variation.
annualize
Use in Measuring Volatility and Realized Variation.
realized variance
Use in Measuring Volatility and Realized Variation.
aggregate intraday returns
Use in Measuring Volatility and Realized Variation.
References and provenance
Safavi (2026), Chapter 17. Student notes: Mohammad Safavi, Ph.D., STATLAB Academy, Version 1.0.
Resource
The authoritative 125-page English PDF accompanies this native lesson.
DownloadReflection
Name the assumption, evidence you would seek, and how the recommendation might change.
Exit check
Reach 70% to complete the chapter. Explanations appear after submission.
Checkpoint
Question 1 of 2. Answered 0/2. Passing score: 70%.