# Stochastic Differential Equations Okay, now we know how to model randomness. How can we use this to actually model price? Look at the log price of S&P 500 since 2008: <img src="/static/images/snp500.png" alt="Probability Tree" style="max-width: 80%;"> It's random, it's messy - but there's a trend to it. Most price charts are like this. By the way, people often look at log price instead of pure price because equal percentage moves look equal on the chart (so going from price 10 to 20 looks the same as 100 to 200). Otherwise, price swings when price is already high look much more pronounced than when it is low. --- ## Geometric Brownian Motion So can we somehow both have a directional trend and introduce randomness? Yes. Let's build the log price step by step. We start at some price $log(S_0)$ and then add increments every $dt$ time step, like we did for brownian motion. Say we measured that log price has on average been moving at a slope $\mu$. Then the next point will most likely be $\mu\cdot dt$ higher (red increment in graph below). But we also want to add randomness to it. We already saw brownian motion can do that for us, so let's also add $\sigma \cdot dB_t$ - where $\sigma$ is some constant to control how wild the randomness is. The higher the $\sigma$, the more the random swings are scaled by. So if your price chart is very chaotic, you'd set this to a high number. Notice this increment can be positive or negative - and is most likely close to 0, because $dB_t\sim N(0,dt)$. It's colored blue in the graph below. <img src="/static/images/building_price.png" alt="Probability Tree" style="max-width: 90%;"> Okay, so we built our increment in log price as: $$d\ log(S_t) = \mu \cdot dt + \sigma dB_t$$ We already know $dB_t\sim N(0,dt)$, so for a fixed $t$ this increment is a normal variable. You're just adding a constant ($\mu\cdot dt$) to a random variable. What are its parameters? $$E(d\ log(S_t))=\mu \cdot dt + \sigma E(N(0,dt))=\mu\cdot dt$$ $$Var(d\ log(S_t))=0 + \sigma^2 Var(N(0,dt))=\sigma^2 dt$$ Also notice we can apply chain rule to $d\ log(S_t)$ to get: $$\frac{d\ log(S_t)}{dS_t}=\frac{1}{S_t}\Rightarrow d\ log(S_t)=\frac{dS_t}{S_t}$$ We can re-write the model as: $$\frac{dS_t}{S_t}=\mu dt + \sigma dB_t$$ Now what is $\frac{dS_t}{S_t}$? it's the percentage change in price over a tiny period: $\frac{dS_t}{S_t}=lim_{\Delta t \rightarrow 0}\frac{S_{t+\Delta t}-S_t}{S_t}$. Percentage change in price is also called the **return**. Therefore $\mu$ is the **mean return**, and $\sigma$ is the **volatility** of the return. The model we've just built is called **Geometric Brownian Motion**, or sometimes referred to as the **Black-Scholes Price** model. Differential equations that contain 'random' elements like $dB_t$ are called **stochastic differential equations (SDEs)**. ## Breakdown of Classical Calculus Okay, so now we've established a model of how price changes. Common interview question can be to solve the model and find a formula for the price. You'd also need to do this in order to price financial products. How would you normally solve a differential equation like this? Well equation's telling you how the price changes in an infinitesimal time increment. So if you know the starting point, you can just sum up these increments and add it to the starting point, and you can determine the price at any later time. Summing up infinitesimal increments is just integration. So you'd integrate the price differential equation. You're essentially doing the following in continuous time: $$S_3 = S_0 + (S_1-S_0) + (S_2-S_1) + (S_3-S_2)$$ Because you know the starting point, and your model tells you how the increments behave, you can solve this to find $S_3$. Problem is, **brownian motion is not differentiable**. Recall what that means - as much as you zoom in, the chart never gets less messy. It's never well-approximated by a straight slope like a smooth function does. So if you were simply adding up the slopes, you'd miss all the 'roughness' that still exists when you're zoomed in. It's as if we're missing some extra 'roughness' terms before we can integrate. ## Quadratic Variation Before we proceed, I promise you this is not unnecessary theoretical detail. This lies at the heart of all of stochastic calculus, and you're expected to understand the intuition behind it - so power through. Okay, so we've said the slope of the function is no longer a good approximation for the tiny increment. Mathematically, that means: $$lim_{\Delta t\rightarrow 0}\frac{f(B_t + \Delta B_t)-f(B_t)}{\Delta B_t} \neq f'(B_t) $$ To find what's missing, let's see where this assumption's coming from in the first place. It comes from a Taylor expansion of the function $f(x+dx)$ close to $f(x)$. $$f(x+dx) = \sum_{i=0}^\infty \frac{f^{(i)}(x+dx)|_{x+dx=x}(x+dx-x)^i}{i!}=f(x) + f'(x)dx + \frac{1}{2}f''(x)dx^2...$$ Now when we set $dx\rightarrow 0$, $dx^2$ terms become so small we can ignore them. Then first order derivative (slope) is a decent approximation of tiny increment: $$f(x+dx)-f(x) \approx f'(x)$$ This is exactly what fails in stochastic calculus. The $dx^2$ terms don't become small enough to ignore. That's the 'roughness' that appears even when you're zoomed in. So for our stochastic function the Taylor expansions looks like: $$f(B_t+dB_t)-f(B_t)=f'(B_t)dB_t + \frac{1}{2}f''(B_t)dB_t \cdot dB_t...$$ So what are these $dB\cdot dB_t$ terms if not 0? Well first note that $dB_t$ is not a scalar, it's a normal random variable (recall $dB_t\sim N(0, dt)$). When you want to multiply random variables $X$ and $Y$, you take their dot product: $$\langle X, Y \rangle = E(XY)$$ So to multiply two $dB_t$ terms, we have: $$\langle dB_t, dB_t\rangle = E(dB_t^2)$$ Remember that $E(dB_t)=0$, and that variance can be written as $Var(X)=E(X^2)-E(X)^2$, so that: $$\langle dB_t, dB_t \rangle = Var(dB_t)=Var(N(0, dt))=dt$$ This second order term is called **quadratic variation**. It's the built-up randomness of a stochastic function. It's the reason you can't approximate a 'messy' function with a slope when you zoom in. It's one of the most important results in stochastic calculus: $$\langle dB_t, dB_t \rangle = dt$$ If you try to take quadratic variation of anything that's not a random variable, you get 0: $$\langle dB_t, t \rangle = E(dB_t\cdot t)=t\cdot E(dB_t)=0$$ ## Itô's Lemma Let's now go back to our Taylor expansion and see what it looks like with these non-0 second-order terms. $$f(B_t + dB_t)-f(B_t)\approx f'(B_t)dB_t + \frac{1}{2}f''(B_t) \langle B_t, B_t \rangle$$ Taking the limit $dB_t \rightarrow 0$, we get what's known as **Itô's lemma**: $$df(B_t) = f'(B_t)dB_t + \frac{1}{2}f''(B_t) \langle B_t, B_t \rangle$$ This is equivalent of the chain rule in regular calculus: if $x$ moves by $dx$, how much does $f(x)$ move by. So before you want to integrate a stochastic differential equation, you first find $df(B_t)$. Note this is generalised to other 'random' things inside - not necessarily just brownian motion. In its full form, we say that for a stochastic process $X_t$ following some SDE form, we have: $$df(t, X_t)=\frac{\partial f(t, X_t)}{\partial X_t}dX_t + \frac{\partial f(t, X_t)}{\partial t}dt + \frac{1}{2}\frac{\partial^2 f(t, X_t)}{\partial^2 X_t}\langle dX_t, dX_t\rangle$$ Be careful not to be mislead by notation. SDEs look like they're already in the right form - e.g. we had $dS_t = S_t ...$, but remember the hidden randomness that shows up when you want to use them. First find $df(S_t)$ and then integrate that. We'll finish with an important example. <div style="display: flex; justify-content: space-between; align-items: baseline;"> <h2>Interview Question</h2> </div> --- Solve the Black-Scholes SDE and find the price expression. <div> <button class="toggle-solution" >Show Solution <i class="fa-solid fa-chevron-down"></i></button> <div class="solution"> Recall the Black-Scholes price model:$$dS_t = S_t(\mu dt + \sigma dB_t)$$ So first we want to apply Itô's lemma and add the missing randomness before we can integrate. To do that we want to first have function expressed as $df(S_t)$: $$\frac{dS_t}{S_t}=d\ log(S_t)=\mu dt + \sigma dB_t$$ Okay so $f(S_t) = log(S_t)$. Applying Itô's lemma: $$d\ log(S_t)=\frac{1}{S_t}dS_t - \frac{1}{2}\frac{1}{S_t^2}\langle dS_t, dS_t \rangle$$ We saw before that $\langle \rangle$ operator behaves like variance / covariance for centered random variables. Therefore it's additive and you can decompose it as follows: $$\langle dS_t, dS_t \rangle = \langle S_t(\mu dt + \sigma dB_t), S_t (\mu dt + \sigma dB_t)\rangle$$ Recall that variance / covariance of constants is 0, so we just have: $$\langle dS_t, dS_t \rangle = S_t^2\sigma^2 \langle dB_t, dB_t \rangle = S_t^2 \sigma^2 dt$$ Therefore: $$d\ log(S_t)=\frac{dS_t}{S_t} - \frac{1}{2}\frac{1}{S_t^2}S_t^2\sigma^2 dt$$ Now we know the first term is simply $\mu dt + \sigma dB_t$ from the SDE definition. $$d\ log(S_t)=\mu dt + \sigma dB_t - \frac{1}{2}\sigma^2 dt$$ Now we're finally ready to integrate. This extra $\frac{1}{2}\sigma^2 t$ captures the cumulative randomness we were missing before. $$\int_0^T d\ log(S_t) dt = \int_0^T (\mu -\frac{1}{2}\sigma^2)dt + \int_0^T \sigma dB_t$$ $$log(S_T) - log(S_0) = (\mu - \frac{1}{2}\sigma^2)(T-0) + B_T - B_0$$ Taking the exponential of both sides and recalling that $B_0=0$, we get: $$S_T = S_0 e^{(\mu-\frac{1}{2}\sigma^2)T + B_T}$$ That's your answer! </div> </div> ## Executive Summary <div class="executive-summary"> <h3>New Definitions</h3> <b>Geometric Brownian Motion</b> - stochastic process defined by the following stochastic differential equation: $$dS_t = S_t(\mu dt + \sigma dB_t)$$ Also called the Black-Scholes price model. <b>Quadratic Variation</b> - a measure of randomness of two stochastic processes. $\langle B_t, B_t\rangle = dt$. Quadratic variation is 0 if at least one of the two components is continuous and has finite variation. <b>Itô's Lemma</b> - Taylor expansion up to 2nd order of a tiny increment of a stochastic function. Equivalent of a chain rule for stochastic calculus: $$df(t, X_t)=\frac{\partial f(t, X_t)}{\partial X_t}dX_t + \frac{\partial f(t, X_t)}{\partial t} dt + \frac{1}{2}\frac{\partial^2 f(t,X_t)}{\partial X_t^2}\langle dX_t, dX_t\rangle$$ <h3>Problem Solving Tricks</h3> When given a SDE, always remember to apply the Itô Lemma before solving the SDE / integrating.<br>To solve the Black Scholes price SDE, remember that $\frac{d\log(S_t)}{dS_t}=\frac{1}{S_t}$ </div>