Sub topic 2
Measuring volatility: returns, standard deviation and annualizing
This chapter turns "crypto is volatile" into a number you can compute and compare. It assumes you can read basic Python, understand percentages and averages, and know that a price series is a list of prices at regular intervals. This is educational material and not financial advice.
Why measure at all
Volatility is how much an asset's returns vary around their average. A figure like "Bitcoin is risky" can't be compared or used in a plan. A figure like "30-day annualized volatility of 55%" can be compared across assets and time periods. It can also feed the position-sizing step later in this tutorial.
Volatility measures the size of moves, not their direction. A coin that rises 10% every day has high prices but almost zero volatility. A coin that alternates between +10% and -10% has high volatility and goes nowhere.
Step 1: Convert prices to returns
Prices from different assets can't be compared directly, because a move of 100 means different things for a 200 coin and a 60,000 coin. Returns express each move as a proportion of the starting price.
There are two common definitions:
- Simple return:
(new - old) / old, ornew / old - 1. A move from 100 to 104 is +4%. - Log return:
ln(new / old). The same move isln(1.04), about 3.92%.
For small moves the two are almost equal. They diverge on large moves, and crypto has many of those. A fall from 120 to 90 is a simple return of -25% but a log return of about -28.8%.
Log returns have one practical advantage. They add across time. If the log returns for three days are 2%, -1% and 4%, the three-day log return is exactly 5%. Simple returns have to be multiplied together. Additivity is why log returns are the usual input to volatility formulas.
| Day | Price | Simple return | Log return |
|---|---|---|---|
| 0 | 100 | n/a | n/a |
| 1 | 104 | +4.00% | +3.92% |
| 2 | 98 | -5.77% | -5.94% |
| 3 | 110 | +12.24% | +11.53% |
| 4 | 105 | -4.55% | -4.65% |
| 5 | 120 | +14.29% | +13.35% |
| 6 | 90 | -25.00% | -28.77% |
Seven prices produce six returns. Every return needs two prices, so a series of N prices always yields N - 1 returns.
Step 2: Standard deviation of returns
The standard deviation (SD) measures how far returns typically sit from their mean. To compute it:
- Find the mean return.
- Subtract the mean from each return and square the result.
- Add the squares and divide by
n - 1, wherenis the number of returns. The result is the variance. - Take the square root.
Dividing by n - 1 gives the sample standard deviation. You use it because your price history is a sample of a wider process, not the whole population. The n - 1 correction matters most when you have few observations, which is common when you analyze a newly listed token.
Squaring makes large moves count disproportionately. One -28.8% day affects the result far more than several 2% days. The variance step is what makes standard deviation a measure of "how bad can it get" and not just "how busy is the chart".
Step 3: Annualizing
A daily standard deviation is hard to compare with figures quoted in other units. Volatility is conventionally reported annualized, meaning scaled to a one-year horizon.
The scaling uses the square-root-of-time rule. If daily returns are independent of each other, variance grows in proportion to time, so the standard deviation grows with the square root of time:
annual_vol = daily_vol * sqrt(periods_per_year)
Crypto markets trade every day of the year, so use 365 periods. Stock-market convention uses about 252 trading days. Using 252 for crypto understates volatility by a factor of about 1.2, and it makes comparisons with other crypto figures wrong. For other sampling intervals, adjust the count. Hourly data gives 365 * 24 periods per year, and weekly data gives 52.
The code below runs all three steps on the example prices.
import math
prices = [100, 104, 98, 110, 105, 120, 90]
returns = [math.log(b / a) for a, b in zip(prices, prices[1:])]
mean = sum(returns) / len(returns)
variance = sum((r - mean) ** 2 for r in returns) / (len(returns) - 1)
daily_vol = math.sqrt(variance)
annual_vol = daily_vol * math.sqrt(365)
print(f"Daily volatility: {daily_vol:.2%}")
print(f"Annualized volatility: {annual_vol:.2%}")It prints a daily volatility of roughly 15% and an annualized figure of roughly 295%. These numbers are extreme because the example prices are invented to swing hard over seven days. Large cryptocurrencies have historically shown annualized figures that are often between about 40% and 100% over long windows, with spikes above that during crashes.
Reading the number
If daily volatility is 3%, a typical day's move is on the order of 3% up or down. If returns followed a normal distribution, about two-thirds of days would land within one standard deviation of the mean and about 95% within two.
Crypto returns do not follow that pattern. They have fat tails, meaning extreme moves occur far more often than a normal distribution predicts. A "five standard deviation" day that should be nearly impossible in a normal model shows up repeatedly in crypto history. Treat standard deviation as a useful summary of ordinary conditions and a poor guide to the worst case. The next chapter covers drawdown, which measures the worst case directly.
Rolling volatility and the choice of window
One volatility figure for an entire history hides change. Volatility clusters: calm periods and turbulent periods each tend to persist. A rolling volatility recomputes the figure over a moving window, such as the latest 30 days, and shows how risk evolves.
import math
import statistics
def log_returns(prices):
return [math.log(b / a) for a, b in zip(prices, prices[1:])]
def rolling_annualized_vol(prices, window=3, periods_per_year=365):
returns = log_returns(prices)
result = []
for end in range(window, len(returns) + 1):
chunk = returns[end - window:end]
result.append(statistics.stdev(chunk) * math.sqrt(periods_per_year))
return result
prices = [100, 104, 98, 110, 105, 120, 90]
for i, vol in enumerate(rolling_annualized_vol(prices), start=1):
print(f"Window {i}: {vol:.0%}")statistics.stdev already uses the n - 1 sample formula, so it matches the manual calculation above. The function returns one value per window position, so six returns with a window of three give four values.
The window length is a trade-off:
- A short window (7 to 14 days) reacts quickly but is noisy. With few observations, one big day dominates the result.
- A long window (90 to 365 days) is stable but slow to notice a regime change, so it can report calm for weeks after a market turns.
Always state the window and the sampling interval when you quote a volatility figure. "55% volatility" is incomplete. "55% annualized, 30-day window, daily closes" is a usable statement.
Common errors
- Using 252 instead of 365. Crypto trades daily, so 365 is the correct count for daily data.
- Dividing by
ninstead ofn - 1on a short history, which understates volatility. - Using prices instead of returns. The standard deviation of raw prices mostly measures the price level and trend, not risk.
- Mixing price sources or timestamps. Daily "closes" from exchanges with different cut-off times produce slightly different numbers. Use one source consistently.
- Annualizing from a tiny sample. Seven days of data can be annualized, as above, but the result is fragile. Treat it as an illustration, not an estimate.
- Assuming the rule is exact. The square-root-of-time rule assumes returns are independent and identically distributed. Volatility clustering and trends break that assumption, so annualized figures are approximations.
Summary of the method
- Collect prices at a regular interval from one consistent source.
- Convert them to log returns, giving N - 1 values for N prices.
- Compute the sample standard deviation of those returns.
- Multiply by the square root of the number of periods per year (365 for daily crypto data).
- Report the window and interval with the result, and remember the fat-tail caveat.
Exercise
A token's daily log returns over the last 30 days have a sample standard deviation of 3%. What is its annualized volatility using daily data for a market that trades every day, and why would using 252 periods instead of 365 give a wrong answer for crypto?
Show answer
Annualized volatility is 3% x sqrt(365). The square root of 365 is about 19.1, so the result is about 57.3%. Using 252 would give 3% x sqrt(252), about 47.6%, which understates the figure. Crypto trades on all 365 days, so there are 365 daily return periods per year, not 252.
Exercise
You have hourly prices for a token and compute an hourly sample standard deviation of 0.8%. Write the annualization factor and the annualized volatility.
Show answer
There are 365 x 24 = 8,760 hourly periods per year. The factor is sqrt(8760), about 93.6. Annualized volatility is 0.8% x 93.6, about 74.9%.