Wiener Process

A detour through Brownian motion, the Wiener process and GBM — with a simulated Wiener path to prepare for the later Black-Scholes code.

Alright, Chapter 4 — the Black-Scholes model.

Before I even start, let me tell you what I already know in my bones: I am not going to understand the Black-Scholes model right here in this blog post. lol Also, I absolutely cannot derive Black-Scholes. Like, not even close. lol

So this post lays out the Wiener-process ingredients and simulates a path. The Black-Scholes formula code comes in #10 . T_T No grand derivation here — let’s work through the ingredients.

OK then, let’s go. I’m gonna follow the book as faithfully as I can, and the actually-grasping-Black-Scholes-properly part? We’ll save that for grad school. Grad school. lol


So. Stock prices clearly move in some random way, right?

If there were any kind of sequential rule to them, somebody would’ve already — no, like a million people would already be billionaires.

But I wasn’t imagining some utter little monster of a path that jumps from +1893081094810984109 straight to 10 for no reason!!! lol. That’s my absurd-number joke; the continuous-path assumption in this model is the precise restriction.

But random does not mean we have no structure at all: we choose a model for stock prices. Real prices can jump; the continuous paths we’re about to use are a simplifying model assumption.

And to evaluate options on stocks, we need a model for their dynamics. One common starting point is Geometric Brownian Motion. It is useful and tractable, rather than a claim to capture every feature of real prices.

Wait, what?! Brownian motion — is that the one I’m thinking of?

Take a look sometime: ( Brownian Motion and the Langevin Equation (Thermal & Statistical Mechanics I Studied #70) )

Brownian motion — with the Langevin equation [ stuff I studied… ]

Around middle school??? You probably ran into Brownian motion. At school you dropped a drop of ink — splosh — into water, right???? How does liquid…

gdpresent.blog.me

That post is the physics-side explanation of Brownian motion. Related stochastic ideas also enter financial GBM, but a stock-price model is not literally a suspended particle moving through water.

(For the history, this is a good read: http://blog.naver.com/ketema/39957447 )

The history I had written down connected these ideas to Samuelson and then geometric Brownian motion in stock-price modeling, and described their move into economics after the world war. That’s the broad chronology in my old notes, not a complete verified history of all Brownian-motion finance models; the physics and financial models still need to be distinguished.

Ah… but going off and reading all those is a bit inefficient, so let me just briefly cover Brownian motion right here.

Brownian motion — in 1905, the miracle year, Einstein dropped 4 papers.

(All 4 were so insane that 1905 just got named “the miracle year.” lol)

One of those four is the special relativity paper — everyone knows that one now, thanks to Interstellar. Another one was on Brownian motion. Another was on mass-energy equivalence ($E=mc^2$). And the last one was on the photoelectric effect — the one that basically birthed quantum mechanics. Yeah. Miracle year is right.

Einstein supplied a molecular explanation of motion that had already been observed; Brownian motion did not first appear in 1905. That’s the physics connection behind the mathematical detour here.

Physical Brownian motion is the irregular motion of small particles suspended in a fluid, driven by the fluid molecules’ thermal motion. Ink spreading is a related diffusion example, not a definition of every kind of random motion. We’ll use the mathematical Wiener model as an ingredient of GBM.


So before we apply Brownian motion to the stock market, we lay down some assumptions first:

  1. Stock prices are uncertain. You can know today’s price; nobody knows tomorrow’s.
  2. In this GBM model, stock-price paths are continuous; this is not a promise that real prices never jump.
  3. Stock prices follow a log-normal distribution.
  4. In constant-parameter GBM, finite-period log returns are normally distributed; prices and gross returns are lognormal.
  5. Over a time interval $\Delta t$, log-return variance is $\sigma^2\Delta t$, so its standard deviation scales with $\sqrt{\Delta t}$, not with $\Delta t$. The log-return mean is $(\mu-\sigma^2/2)\Delta t$.

(A log-normal distribution is what you get when you exponentiate a normal distribution — and doing so gives you a distribution where the mode is skewed to the left. Apparently.)

Lay down those assumptions, and the stochastic process model for stock prices under GBM is:

Equation from the original notes

  • $S$: stock price
  • $\mu$: expected return of the stock price
  • $\sigma$: the return-volatility parameter (per square root of the chosen time unit), not the standard deviation of the price level itself lol

$\mu$ and $\sigma$ — these are technically variables, but we’re going to assume they’re constants.

$z_t$: the Wiener process — a family of random variables indexed by time, not one fixed random draw.

  • A standard Wiener process starts at zero, has continuous paths and independent normal increments. Over an interval of length $\Delta t$, $\Delta z\sim N(0,\Delta t)$. The variance is 1 only for a unit-length interval.

I’m weak at math, so I think I need to dig into “random variable” a little more before moving on. T_T

What even is a random variable, seriously? Ugh.

Random variable: A variable that assigns a real number to each outcome of a random experiment. Generally denoted $X$.

When you do an experiment or observe some phenomenon involving randomness, and a single real value $X$ shows up as the result — $X$ is a “variable” in the sense that it could’ve taken many possible values, but which value it takes and with what likelihood is described by the probability defined for it. That’s a random variable.

A discrete random variable has a finite or countably infinite set of possible values. The continuous variables we use here are described by a density, like the normal distribution. “Finite versus infinite” alone is not the distinction. OK, that’s enough vocabulary for $z$ for now.

So basically — $z$ wiggles around randomly~~~. Its increment over a stated interval has mean zero and variance equal to the interval length. The normal draw with variance 1 will be our standardized input, not the unscaled increment.

Cool. Then,

Equation from the original notes

This formula? Yeah, no way I’m proving this here lol. I keep telling you I’m not a math major. lol T_T sad. I want to be good at math too T_T

Let’s loosely — no no — very loosely understand this formula and move on.

  • $dS$ is the change in the stock price. Change. (the $d$ as in $\Delta S$.)
  • $\mu S\,dt$ is the expected value of the instantaneous change in stock price during a tiny time $dt$.
  • $\sigma S\,dz$ — and this is where the trouble is… heh

For a small finite step, write $\Delta z=\varepsilon\sqrt{\Delta t}$ with $\varepsilon\sim N(0,1)$. The differential shorthand $dz$ therefore has variance scale $dt$, not an interval-independent variance of 1.

So we can write:

Equation from the original notes

In other words — the change in stock price is random, but

Equation from the original notes

it’s not, like, super-random.


Ah, but in the actual stock market, observing $dS$ in practice is hard. What I mean is — measuring $dS$ over the unit time $dt$ (i.e., continuously, for all values) is a pain. So we look at $\Delta S$ over $\Delta t$ intervals instead of exactly $dt$.

From that angle, mathematically(?), $\Delta z$ has the property:

Equation from the original notes

like that, apparently. $\varepsilon$ is a number — a random number drawn from $N(0,1)$.

(This relationship is what Wiener showed, and we just use it. heh)


OK so I’m slowly going to start coding, but before that, let me organize a couple of things that are gonna get confusing as I keep going.

  • -dist: cumulative distribution value
  • -Inv: inverse CDF, or quantile — input a cumulative probability, get back the corresponding value

Later we’ll use a function called NormSInv, so let me get the why of “inverse” straight before moving on. I’ll lay out these 4: NormDist, NormSDist, NormInv, NormSInv. The legacy NormDist needs a fourth argument: True for the cumulative probability used here, False for the density, as in Microsoft’s function reference .

NormDist(x, mean, std, True): probability that the random variable comes out as $x$ or less, given a mean and standard deviation.

  • e.g. NormDist(10, 36, 21, True) = 0.1078
  • → In a normal distribution with mean 36 and std 21, the probability of getting 10 or less is 10.78%.

NormSDist(x): probability of getting $x$ or less in the standard normal distribution ($\mu=0$, $\sigma=1$).

  • e.g. NormSDist(0) = 0.5
  • → In the standard normal, the probability of getting 0 or less is 50%. Yep.

NormInv(prob, mean, std): the inverse direction — given a cumulative probability, what’s the random variable value, in a normal distribution with that mean and std?

  • e.g. NormInv(0.14, 35, 14) = 19.87553
  • → In a normal with mean 35 and std 14, the $x$ at which the cumulative probability hits 14% is 19.87553.

NormSInv(prob): yeah yeah, easy mode… too lazy to type more.

  • e.g. NormSInv(0.94) = 1.55477
  • → In the standard normal, the $x$ at which you’ve hit 94% is 1.55477.

OK. Now let’s just code up the Wiener process the way the book does it, and call it.

Equation from the original notes

One correction to the Randomize annotation: omitting its numeric argument uses the system timer. Omitting the whole Randomize statement does not do that. Initialize once before the loop. Also, VBA Rnd() can return zero; reject that endpoint before an inverse-normal call, which needs $0\lt u\lt1$. See Microsoft’s Randomize and Rnd descriptions.

We need to draw $\varepsilon$. Rnd() supplies a uniform input between 0 and 1: equal-width intervals have equal probabilities. That uniform input is not yet a normal shock for a Wiener increment.

What kind of number do we actually need?

Equation from the original notes

We need a normal draw. Compare equal-width intervals around different values: their probabilities depend on the normal density. An individual exact point has probability zero in either continuous model, so saying two exact points have different probabilities was too loose. Now you can see why Δz = Rnd() * sqr(deltaT) won’t cut it, right? A uniform draw is not a normal draw.

That’s why the inverse normal turns a uniform input $u$ into the standardized shock $\varepsilon$, as NormInv(u, 0, 1) or NormSInv(u). Then multiply by $\sqrt{\Delta t}$ and add that increment to the path. The inverse call alone is not the whole Wiener process. heh.

Excel sheet with the simulated Wiener process chart, next to the VBA editor showing the code

The same kind of Wiener process path, plotted with Python (matplotlib)

The Python example saves its chart in the directory where you run it; no private Desktop folder is required.

import numpy as np
import math
import pandas as pd
import matplotlib.pyplot as plt
T = 1; Days = 300; deltaT = T/Days; z=0

n_col = [x for x in range(0, 500)]
n_row = [x for x in range(0, 500)]

df = pd.DataFrame(columns=n_col, index=n_row)

np.random.seed(2000)

for x in range(1, 301):
    deltaZ = np.random.normal(loc=0, scale=1) * math.sqrt(deltaT)
    z = z + deltaZ
    df.loc[x, 1] = z

df.dropna(how='all', inplace=True, axis=1)
df.dropna(how='all', inplace=True, axis=0)
df = df.reset_index()
df.columns = range(df.shape[1])

plt.figure(figsize=(6, 4))
plt.plot(df.T.iloc[0].values, df.T.iloc[1].values)
plt.savefig('Wiener Process.png', dpi=200)

Questions or corrections?

Did a step lose you, or does a number look off? Email me or use the contact page. Include the note title and the step or figure you mean.

Feedback goes to me privately by email; it is not posted as a public comment.