Log Returns and Volatility (σ) TODO
Concept
Log return is defined as the natural logarithm of the ratio of consecutive prices, ln(P_t/P_{t-1}). Unlike simple returns, log returns add up over consecutive periods, which makes multi-period aggregation easy, treats gains and losses symmetrically, and is nearly identical to the simple return when the value itself is small. Volatility σ is the standard deviation of these returns; under the assumption that returns are independent and identically distributed, it scales with the square root of the time period, so short-interval volatility is converted to a longer horizon by multiplying by the square root of the number of periods. Real financial time series don't fully satisfy that assumption — they show fat tails and volatility clustering — which is why realized volatility computed from historical data differs from the implied volatility backed out of option prices. The choice of sample window length and observation frequency has a large effect on the estimate.
Risk limits, margin, and pricing models all rest on volatility figures, but mechanically applying square-root-of-time scaling systematically underestimates tail risk. Knowing which assumptions a given number rests on is the whole point.
Code & Formula
# Day 36 — 로그수익률·변동성(σ)
# 짧은 가격 시계열에서 로그수익률을 계산하고 표준편차(변동성)를 구한 뒤, 기간 환산을 보여준다.
import math
prices = [100.0, 101.5, 99.8, 102.3, 103.0, 101.0, 104.5, 103.8, 106.0, 105.2]
log_returns = [math.log(prices[i] / prices[i - 1]) for i in range(1, len(prices))]
n = len(log_returns)
mean_r = sum(log_returns) / n
variance = sum((r - mean_r) ** 2 for r in log_returns) / (n - 1) # 표본분산 (n-1)
daily_vol = math.sqrt(variance)
print("가격:", prices)
print("\n일별 로그수익률:")
for i, r in enumerate(log_returns, start=1):
print(f" day {i}: {r:+.5f}")
print(f"\n평균 로그수익률 = {mean_r:.5f}")
print(f"일간 변동성(σ_daily) = {daily_vol:.5f}")
# 연환산: iid 가정 아래 변동성은 기간 수의 제곱근에 비례
trading_days = 252
annual_vol = daily_vol * math.sqrt(trading_days)
print(f"연환산 변동성(σ_annual, sqrt(252) 법칙) = {annual_vol:.5f} ({annual_vol*100:.2f}%)")
Exercise
Take a daily closing-price series for any asset, compute log returns, derive the standard deviation and its square-root-time-scaled value, then compare the frequency of extreme moves the normal-distribution assumption predicts against what actually occurred.
Practical Connection
Prediction-market prices are probabilities bounded between 0 and 1, so log returns don't apply directly, but converting to log-odds aligns with the way LMSR prices respond linearly to holdings — giving volatility analysis a natural coordinate system.
If you study this on a given day, add a note link and a ✅ to this line in the source curriculum (docs/knowledge/math-50-curriculum.md) and this spot will lead straight to the note body. You can also write directly on this page — but regenerating overwrites it, so it's safer to keep anything you want to save as markdown under docs/algorithms/.