Random Walks and GBM (Concept) TODO
Concept
A random walk is a stochastic process built by repeatedly adding independent increments; in a symmetric simple random walk, variance grows proportionally with time, so the typical distance traveled scales with the square root of time. Taking this to a continuous-time limit gives Brownian motion, where increments are independent and normally distributed. Geometric Brownian motion (GBM) is a model where the logarithm of the value follows Brownian motion; because this keeps the value from going negative and gives returns a lognormal distribution, it's widely used to model asset prices. Real markets, though, show fat tails and volatility clustering, so GBM is ultimately only a first-order approximation.
Being able to estimate the swing of an accumulating stochastic process — price, balance, queue length — using square-root-of-time scaling is what lets you set risk limits or timeouts on solid ground rather than guesswork.
Code & Formula
# Day 38 — 랜덤워크/GBM(개념)
# 대칭 단순 랜덤워크를 시뮬레이션하고, 로그값이 랜덤워크를 따르는 기하 브라운 운동(GBM) 근사 경로도 만든다.
import random
import math
random.seed(1)
# 1) 대칭 단순 랜덤워크: 매 스텝 +1 또는 -1
n_steps = 20
walk = [0]
for _ in range(n_steps):
step = random.choice([-1, 1])
walk.append(walk[-1] + step)
print(f"단순 랜덤워크 경로 ({n_steps}스텝):")
print(walk)
print(f"최종 위치 = {walk[-1]}, 이론적 표준편차(sqrt(n)) = {math.sqrt(n_steps):.3f}\n")
# 2) 이산시간 GBM 근사: S_t = S_0 * exp(sum of small normal increments)
# dlogS = (mu - 0.5*sigma^2)*dt + sigma*sqrt(dt)*Z, Z ~ N(0,1)
S0 = 100.0
mu = 0.05 # 연간 기대수익률
sigma = 0.2 # 연간 변동성
n_gbm_steps = 10
dt = 1 / 252 # 하루 단위
prices = [S0]
for _ in range(n_gbm_steps):
z = random.gauss(0, 1)
drift = (mu - 0.5 * sigma ** 2) * dt
diffusion = sigma * math.sqrt(dt) * z
next_price = prices[-1] * math.exp(drift + diffusion)
prices.append(next_price)
print(f"GBM 근사 가격 경로 ({n_gbm_steps}일):")
for i, p in enumerate(prices):
print(f" day {i}: {p:.4f}")
Exercise
Simulate a few thousand paths each of a simple random walk and a GBM process, then plot the variance over time and the distribution of final values to visually confirm the normal and lognormal shapes.
Practical Connection
A prediction-market price behaves close to a martingale that updates whenever new information arrives, but because it's confined between 0 and 1, GBM can't be applied directly — understanding that difference is necessary to quantitatively estimate Verex's price swings or its collateral requirements.
Where it lands in Jayverse
- Verex: set price-swing risk limits and collateral requirements from a bounded-martingale model, not GBM. Verex prices are confined to [0,1] and don't follow a lognormal distribution.
- DeFi: keep the from-scratch staking-rate study's volatility model separate from Verex's. GBM's continuous-compounding assumption fits DeFi's unbounded rate math far better than Verex's bounded prices.
- gitboard: state which model — bounded martingale or GBM — backs any displayed expected-price-swing figure for a Verex market. So a viewer can't read a GBM-shaped confidence interval onto a bounded price.
Key expressions
| Expression | 뜻 · 쓰이는 자리 |
|---|---|
| scale with | ~에 비례해서 커지다 · 이동 거리의 전형적 크기가 시간의 제곱근에 비례할 때. "scales with the square root of time" |
| keep ... from -ing | ~이 ~하지 못하게 막다 · 값이 음수가 되는 것을 구조적으로 방지할 때. "this keeps the value from going negative" |
| on solid ground | 확실한 근거 위에, 탄탄한 토대 위에 · 추측이 아니라 수학적 근거로 판단할 때. "on solid ground rather than guesswork" |
| confined between | ~ 사이에 갇혀 있는, ~로 제한된 · 값의 범위가 특정 구간 안으로 한정될 때. "confined between 0 and 1" |
| first-order approximation | 1차 근사(대략적인 근사 모델) · 현실을 완벽히 설명 못하지만 출발점으로 쓰는 단순 모델. "GBM is ultimately only a first-order approximation" |
| swing (n.) | (가격·값의) 변동폭, 요동 · 누적되는 확률과정이 얼마나 출렁이는지 말할 때. "estimate the swing of an accumulating stochastic process" |
| close to | ~에 가까운 · 어떤 과정이 이론적 모델과 거의 비슷하게 움직일 때. "behaves close to a martingale" |
| GBM | 기하 브라운 운동(Geometric Brownian Motion) · 로그값이 브라운 운동을 따르는 확률과정 모델, 자산가격을 모형화할 때 널리 쓰이지만 팻테일은 못 담아냄. "Geometric Brownian motion (GBM) is a model" |
| Brownian motion | 브라운 운동 · 독립적이고 정규분포를 따르는 증분으로 이루어진 연속시간 확률과정, 랜덤워크의 연속극한. "Taking this to a continuous-time limit gives Brownian motion" |
| martingale | 마팅게일(새 정보가 반영될 뿐 기대값이 변하지 않는 확률과정) · 예측시장 가격이 이론적으로 근접하는 성질을 가리킴. "behaves close to a martingale that updates whenever new information arrives" |
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/.