Quant from Scratch by QuantWright

Introduction to Quant Finance · Lesson 8

Volatility

How wide is luck? One number for how far returns typically land from their average, how to work it out by hand, and how to turn a daily figure into a yearly one.

Know the basics? Read the lesson notes

Same average, different ride

A daily return is how much a price moved from one day's close to the next, in percent (lesson A7). Here are two simulated assets, A and B, over the same 20 days. Play the days.

Two assets, 20 days (simulated)

Each bar is one day's return: up for a gain, down for a loss. Dashed: each asset's average day so far.

Days played0
A's average day–
B's average day–

Both average +0.10% a day (they were made that way). Yet A never moved more than 0.92% in a day, while B moved as much as 4.11%. The average can't tell them apart. You need a second number: how far the days typically land from their average.

Distances cancel out

Take five made-up days: +2%, −2%, +4%, 0% and +1%. Their average is (2 − 2 + 4 + 0 + 1) ÷ 5 = 5 ÷ 5 = +1%.

Each day's distance from the average is that day minus 1%: +1, −3, +3, −1 and 0. A first idea for the typical distance is to average those five. What do you get?

1.6 is what you get after dropping the minus signs (8 ÷ 5). With the signs kept, +1 − 3 + 3 − 1 + 0 = 0, and 0 ÷ 5 = 0.
The average keeps every distance with its sign: +1 − 3 + 3 − 1 + 0 = 0, and 0 ÷ 5 = 0.
+1 − 3 + 3 − 1 + 0 = 0. The distances above the average always cancel the ones below it exactly. That's what makes it the average.
So the minus signs have to go. The standard way is to square each distance: a minus times a minus is a plus. Squaring also makes a distance of 4 count far more than a distance of 1 (16 against 1), so one wild day shows up in the number.

Square, average, square root

Square each distance, then average the squares. That average is called the variance. Its unit is "percent squared", which nobody can picture, so take its square root to get back to percent. The result is the standard deviation: the typical distance from the average, as in the last lesson.

For the five days: the squares are 1, 9, 9, 1 and 0. They add up to 20, so the variance is 20 ÷ 5 = 4, and the standard deviation is √4 = 2%. Dropping the signs instead and averaging would give 8 ÷ 5 = 1.6%. The standard deviation, the root of the average square, is never smaller than that plain average distance, and usually a little bigger, because the squares weigh the far days more.

Now drag the days left and right, and watch the numbers follow. Get the standard deviation below 1%, then above 3%.

Five days you can move (made-up)

Each row is one day. The line from the dashed average to the dot is that day's distance. On the right, a square with that distance as its side: its area is the distance squared. Orange bar: the average ± one standard deviation.

Average day–
Variance (average square)–
Standard deviation–

Pulling the days in toward the average shrinks it. One day far out raises it fast, because its distance is squared: one day 4% from the average adds 16 to the sum of squares, while four days 1% away add only 4 between them.

Match the volatility

In trading, the standard deviation of an asset's returns has its own name: volatility. Daily volatility is the standard deviation of its daily returns.

Here are three simulated assets over one year: 252 trading days, about as many days as markets open in a year. Their daily volatilities are 0.53%, 0.93% and 1.91%. Pick one for each asset, then check.

Three assets, one year each (simulated)

Each line is a price starting at 100. After you check, each day's return appears underneath as a thin bar.

Asset X

Asset Y

Asset Z

Matched right–

Z rose from 100 to 133.29 with the smallest daily moves, 0.53%. X fell to 70.75 with the biggest, 1.91%. Volatility measures how big the moves are, not which way they go. It is built from squared distances, so up days and down days count the same.

68 in 100 within how far?

The last lesson's 68–95–99.7 rule: on a bell curve, about 68 results in 100 land within one standard deviation of the average, and about 95 within two.

Take asset Y. Its daily volatility is 0.93%, and its average day was almost exactly 0%. About 68 of every 100 of its days should land within how far of that average?

One standard deviation for Y is 0.93%, so about 68 days in 100 should land within ±0.93% of its average.
0.47% is half a standard deviation, and fewer days land that close. One standard deviation, ±0.93%, should hold about 68 in 100.
±1.86% is two standard deviations (2 × 0.93), which should hold about 95 in 100. One, ±0.93%, holds about 68.
On the next screen you count Y's days.

Count Y's days

Here are all 252 of Y's daily returns, sorted by size into bars. Switch between one and two standard deviations and count the days inside.

Asset Y: 252 daily returns (simulated)

Each bar counts the days whose return fell in one 0.25%-wide slice. Orange: the days inside the band around the average. A bar cut by a band edge is split: its orange part is the days inside.

Band
Band–
Days inside–

Within ±0.93%: 168 of 252 days (66.7%). Within ±1.86%: 241 (95.6%), which leaves 11 days beyond. Close to 68 and 95 in 100.

So daily volatility tells you how wide an ordinary day is. On about two days in three, Y moved less than 0.93% from its average.

Theory

Variance and standard deviation

The variance is the average squared distance from the mean, which is the textbook word for the average. The standard deviation is its square root. In formulas, σ is read "sigma" and μ "mu".

σ² = [(x1 − μ)² + (x2 − μ)² + … + (xn − μ)²] ÷ n
σ = √σ²
s = √( same sum of squares ÷ (n − 1) )
x1 … xn
the numbers, for example daily returns; n is how many there are
μ
"mu", their mean (average): add them up, divide by n
σ²
the variance, in squared units
σ
"sigma", the standard deviation, in the numbers' own unit
s
the sample standard deviation (below)

When the numbers are a sample, a few days standing in for many more, they sit a little closer to their own average than to the true one, so the squares come out slightly small. Dividing by n − 1 instead of n makes up for it. That gives s, the sample standard deviation. Use ÷n when you have every case there is; use ÷(n − 1) when a handful stands in for more, as in most backtests. Y's 0.93% earlier was an s, dividing by 251; with 252 days, the two barely differ.

Worked example: your five days

μ = (2 − 2 + 4 + 0 + 1) ÷ 5 = 1. Distances: +1, −3, +3, −1, 0. Squares: 1, 9, 9, 1, 0, which add up to 20. Variance: σ² = 20 ÷ 5 = 4, so σ = √4 = 2%. As a sample: 20 ÷ 4 = 5, so s = √5 ≈ 2.24%.

Holds when
  • you want the typical size of a distance, in the numbers' own unit;
  • reading it with the 68–95–99.7 rule: the numbers spread out roughly like a bell.
Breaks when

One extreme day moves it a lot, because its distance is squared, and real returns have more extreme days than a bell (lesson A6, Fat tails).

For the precise: why square, not just drop the signs?Dropping the signs and averaging gives the mean absolute deviation: 8 ÷ 5 = 1.6 for the five days. It is a fine measure too. Squares are the standard because variances of independent days add up, which is where the √n rule of the last lesson comes from.

Try it on new numbers. Three days: 0%, +3% and +6%. Treat them as a sample. What is s, in percent?

μ = 9 ÷ 3 = 3. Distances: −3, 0, +3. Squares: 9, 0, 9, which add up to 18. 18 ÷ (3 − 1) = 9, and √9 = 3%.
μ = 9 ÷ 3 = 3. Distances: −3, 0, +3. Squares: 9, 0, 9, which add up to 18. 18 ÷ (3 − 1) = 9, and √9 = 3%. If you got 2.45, you divided by n: √(18 ÷ 3) = √6 ≈ 2.45.
Theory

From daily to yearly volatility

Volatility is usually quoted per year: the annualised volatility. Log returns, the unit from lesson A7 that adds up over time, make a year's return the total of its 252 daily ones. The last lesson showed how the spread of a total grows: with the square root of how many are added up, because up days and down days partly cancel. This is the square-root-of-time rule:

σyear = σday × √252
σday
the daily volatility
252
trading days in a year, the count most people agree to use; √252 ≈ 15.87
σyear
the yearly (annualised) volatility

For daily moves of a percent or two, percent and log returns are nearly equal (lesson A7), so the rule is used with either.

Worked example: asset Y

σday = 0.93%, so σyear = 0.93% × 15.87 = 14.76%, ≈ 15% a year. A year like Y's would land within about 15% of its average about two years in three.

Holds when
  • each day's move doesn't change the next one's (the days are independent);
  • the volatility stays the same all year.
Breaks when

Calm and wild stretches come in runs (lesson C2, Volatility clustering), and prices that keep trending or snapping back from day to day spread differently (lesson C1, Time series basics).

For the precise: the rule checked by simulationThe script simulated 2,000 more years of 252 independent days, each with a daily volatility of 1%. The standard deviation of the 2,000 yearly totals was 15.77%, against 1% × √252 = 15.87%.

An asset's daily volatility is 1.5%. About what is its yearly volatility?

378% is 1.5 × 252, as if every day moved the same way. Up and down days partly cancel, so it's 1.5 × √252 = 1.5 × 15.87 ≈ 23.8%.
1.5 × √252 = 1.5 × 15.87 ≈ 23.8%.
A year adds up 252 days, so it swings more than one day does: 1.5 × √252 = 1.5 × 15.87 ≈ 23.8%.

What this means for your backtest

A backtest runs a trading rule over past prices to see what it would have made. Its daily results have a volatility too. Turn over three points, one at a time.

  1. Volatility is the size of the moves, not their direction.

    A rising account line can be calm or wild, like Z and X. Check its volatility, not just where it ends.

Practice 1 of 3

Four days, by hand

The situationYour backtest's last four daily returns were +2%, −1%, +4% and −1%. You want their sample standard deviation, worked out by hand.

What is s, in percent? The last step is a square root: any phone calculator has a √ key.

Hint: the average first, (2 − 1 + 4 − 1) ÷ 4. Then each day's distance from it, the squares, their sum ÷ (4 − 1), and the square root.

Average: 4 ÷ 4 = 1%. Distances: +1, −2, +3, −2. Squares: 1, 4, 9, 4, which add up to 18. 18 ÷ 3 = 6, and √6 ≈ 2.45%.
Average: 4 ÷ 4 = 1%. Distances: +1, −2, +3, −2. Squares: 1, 4, 9, 4, which add up to 18. 18 ÷ 3 = 6, and √6 ≈ 2.45%. If you got 2.12, you divided by 4 instead of 3: √(18 ÷ 4) ≈ 2.12.
Practice 2 of 3

A daily figure on a factsheet

The situationA made-up fund's factsheet (its one-page summary) gives its daily volatility: 0.8%. You want to compare it with another fund that quotes a yearly figure.

What is 0.8% a day as a yearly volatility, in percent?

Hint: multiply the daily volatility by √252 ≈ 15.87.

0.8 × √252 = 0.8 × 15.87 ≈ 12.7% a year.
0.8 × √252 = 0.8 × 15.87 ≈ 12.7% a year. Multiplying by 252 (201.6%) would treat every day as moving the same way.
Practice 3 of 3

Two rules, the same +10%

The situationTwo made-up rules each made +10% in a one-year backtest. Rule A's yearly volatility was 5%; Rule B's was 25%. Picture both with no edge at all.

Which +10% would be harder for luck alone to produce?

Bigger swings make +10% easier for luck. For B it is 10 ÷ 25 = 0.4 standard deviations, everyday luck. For A it is 10 ÷ 5 = 2, which luck passes about 2 or 3 times in 100 (the 5 in 100 outside ±2, split between up and down).
The same +10% sits at a different distance in each rule's own spread: 10 ÷ 5 = 2 standard deviations for A, 10 ÷ 25 = 0.4 for B.
For A, 10 ÷ 5 = 2 standard deviations, which luck passes about 2 or 3 times in 100 (the 5 in 100 outside ±2, split between up and down). For B, 10 ÷ 25 = 0.4, everyday luck.
Harder for luck isn't proof of an edge: one year is a small test, and the costs of trading (fees and the like) would pull both down.
✓

Lesson done

Volatility is the standard deviation of returns: square each return's distance from the average, average the squares (the variance), then take the square root. It measures how big the moves are, not which way they go. A year adds up 252 days, so yearly volatility is daily volatility × √252, and it tells you how wide luck is.

Key ideas

Variance (σ²)
the average squared distance from the mean
Standard deviation (σ)
the square root of the variance: the typical distance from the mean
Sample standard deviation (s)
the same, dividing by n − 1, for a few numbers standing in for many
Volatility
the standard deviation of returns; daily volatility uses daily returns
Annualised volatility
volatility per year: daily volatility × √252

Formulas

σ² = sum of (x − μ)² ÷ n  ·  σ = √σ²  ·  s = √(sum of (x − μ)² ÷ (n − 1))

σyear = σday × √252  (√252 ≈ 15.87)

Lesson notes

Volatility is the standard deviation of returns: how far they typically land from their average. It measures how big the moves are, not which way they go. Daily volatility × √252 gives yearly volatility, which tells you how wide luck is.

The average isn't enough

Two simulated assets, A and B, both averaged +0.10% a day over 20 days. A never moved more than 0.92% in a day, while B moved as much as 4.11%. You need a second number: how far the days typically land from their average.

Square, average, square root

Average the days' distances from the average and you always get 0: those above it cancel those below. So the minus signs have to go, and the standard way is to square each distance. The average of the squares is the variance. Its square root, back in percent, is the standard deviation: the typical distance from the average.

Size, not direction

The standard deviation of an asset's returns is called its volatility. Over one simulated year, asset Z rose from 100 to 133.29 with a daily volatility of 0.53%, and asset X fell to 70.75 with 1.91%. Squared distances count up days and down days the same.

One standard deviation

On a bell curve, about 68 results in 100 land within one standard deviation of the average and about 95 within two (lesson A5). Asset Y's daily volatility was 0.93%: 168 of its 252 days landed within ±0.93% of its average, and 241 within ±1.86%.

From a day to a year

Volatility is usually quoted per year: the annualised volatility. A year's log return is the total of its 252 daily ones, and the spread of a total grows with the square root of how many are added up, because up days and down days partly cancel.

How wide luck is

With no edge (no advantage, so nothing made on average), a year's result lands within one yearly volatility of 0 about two years in three. So +10% in a year is everyday luck at a yearly volatility of 25% (10 ÷ 25 = 0.4 standard deviations), but two standard deviations out at 5% (10 ÷ 5 = 2): harder for luck. Harder for luck isn't proof of an edge: one year is a small test, and the costs of trading would pull the result down.

Formula: variance and standard deviation

σ² = [(x1 − μ)² + (x2 − μ)² + … + (xn − μ)²] ÷ n
σ = √σ²
s = √( same sum of squares ÷ (n − 1) )
x1 … xn
the numbers, for example daily returns; n is how many there are
μ
"mu", their mean (average): add them up, divide by n
σ²
the variance, in squared units
σ
"sigma", the standard deviation, in the numbers' own unit
s
the sample standard deviation, for a sample: a few days standing in for many, as in most backtests
Worked example: five made-up days

The days: +2%, −2%, +4%, 0% and +1%. μ = (2 − 2 + 4 + 0 + 1) ÷ 5 = 1. Distances: +1, −3, +3, −1, 0. Squares: 1, 9, 9, 1, 0, which add up to 20. Variance: σ² = 20 ÷ 5 = 4, so σ = √4 = 2%. As a sample: 20 ÷ 4 = 5, so s = √5 ≈ 2.24%.

Holds whenBreaks when

One extreme day moves it a lot, because its distance is squared, and real returns have more extreme days than a bell (lesson A6, Fat tails).

Formula: the square-root-of-time rule

σyear = σday × √252
σday
the daily volatility
252
trading days in a year, the count most people agree to use; √252 ≈ 15.87
σyear
the yearly (annualised) volatility
Worked example: asset Y

σday = 0.93%, so σyear = 0.93% × 15.87 = 14.76%, ≈ 15% a year. A year like Y's would land within about 15% of its average about two years in three.

Holds whenBreaks when

Calm and wild stretches come in runs (lesson C2, Volatility clustering), and prices that keep trending or snapping back from day to day spread differently (lesson C1, Time series basics).

One more worked example

Made-up round numbers

Five days, a sample: +7%, −1%, +1%, +1% and +2%.

Average: (7 − 1 + 1 + 1 + 2) ÷ 5 = 10 ÷ 5 = 2%.

Distances (day − 2): +5, −3, −1, −1, 0.

Squares: 25, 9, 1, 1, 0. Sum: 25 + 9 + 1 + 1 + 0 = 36.

Divide by n − 1: 36 ÷ (5 − 1) = 36 ÷ 4 = 9.

Square root: s = √9 = 3% a day.

Yearly: 3% × 15.87 = 47.61%, ≈ 47.6% a year.

Common mistakes

Check yourself

  1. Four daily returns: +2%, −1%, +4% and −1%. What is their sample standard deviation?
    Answer

    Average: 4 ÷ 4 = 1%. Distances: +1, −2, +3, −2. Squares: 1, 4, 9, 4, which add up to 18. 18 ÷ 3 = 6, and √6 ≈ 2.45%.

  2. A rule with no edge made +8% in a year. How unusual is that at a yearly volatility of 32%? Of 4%?
    Answer

    8 ÷ 32 = 0.25 standard deviations: everyday luck. 8 ÷ 4 = 2 standard deviations out.

  3. From lesson A7: which returns add up over time, percent or log?
    Answer

    Log returns add up; percents multiply.

Try it yourself

Run the script. Every return and number in this lesson comes from one Python script with a fixed random seed (below). Change an asset's daily volatility or its drift and see what moves.

By hand, in a spreadsheet. Type a few daily returns down column A. =AVERAGE(A1:A5) gives the mean. In B1 put =(A1-AVERAGE($A$1:$A$5))^2 and copy it down: the squared distances. =AVERAGE(B1:B5) is the variance, and =SQRT(…) of it is the standard deviation. Check it against =STDEV.P(A1:A5) (dividing by n) and =STDEV.S(A1:A5) (dividing by n − 1). Multiply by SQRT(252) for a yearly figure.

The code behind every number (Python, seed 2026110910)
Loading…

Going further: why n − 1, measured

The theory step said that a sample's squared distances come out slightly small when you measure them from the sample's own average. You can see it by simulation. The script drew 100,000 samples of 5 days each from returns whose true variance is exactly 1. Averaged over all 100,000 samples, the variance dividing by 5 came out at 0.800: too small by a fifth. Dividing by 4 gave 1.000.

The shortfall is (n − 1) ÷ n: 4 ÷ 5 = 0.8 here. The sample's own average is pulled toward its own days, so it sits closer to them than the true average does. Dividing by n − 1 scales the result back up. For 252 days the factor is 251 ÷ 252, under half a percent, which is why it rarely matters for a year of daily returns and matters a lot for five.

For the preciseSeed 2026110910, one numpy Generator, draws in this order. Assets A and B: 20 standard normal draws each, rescaled to mean 0 and standard deviation 1 (dividing by n), then 0.10 + 0.50z and 0.10 + 2.00z percent, rounded to 2 decimals; measured means +0.10% and +0.10%, standard deviations 0.50% and 2.00% (dividing by n). Assets X, Y, Z: 252 daily log returns each, normal with mean 0, −0.03 and +0.12 and standard deviation 2.0, 1.0 and 0.5 percent, rounded to 3 decimals; prices 100 × exp(cumulative sum ÷ 100). Measured from the rounded returns (dividing by 251): X 1.9133%, Y 0.9267%, Z 0.5304%; average days −0.1373%, −0.0016% and +0.1140%; last prices 70.75, 99.61 and 133.29. Y's band is centred on its own average and uses s as the page shows it, 0.93%: 168 days within ±0.93%, 241 within ±1.86% (the same counts as with the unrounded 0.9267%). Then 2,000 years × 252 days of normal(0, 1%) draws, and 100,000 samples of 5 normal(0, 1) draws. √252 = 15.8745…; the lesson rounds it to 15.87.

Honest notes

Where this comes from