|
The Black-Scholes partial differential equation for the price, $V$, of a European option is, \[ \frac{\partial V}{\partial t} +\frac{\sigma^2 S^2}{2}\frac{\partial^2 V}{\partial S^2} + rS\frac{\partial V}{\partial S} -rV = 0 \qquad\text{ in } S>0 \text{ and } T > t \ge 0. \]
The calculation above is based on an explicit finite difference approximation of the Black-Scholes partial differential equation.
We choose an $S_\mathrm{max}$ to replace the boundary at infinity and define step sizes $\delta S = S_\mathrm{max}/N_s$ and $\delta t = T/N_t$. Here, of course, $N_s$ and $N_t$ are natural numbers. Letting $V^i_j$ denote the approximation to $V(S_j, t_i)$ and setting $S_j = j\, \delta S$, we approximate the partials using finite differences as follows: \[ \frac{\partial V}{\partial t} \approx \frac{V^i_j - V^{i-1}_j}{\delta t}, \] \[ \frac{\partial V}{\partial S} \approx \frac{V^i_{j+1} - V^i_{j-1}}{2\delta S} \] and \[ \frac{\partial^2 V}{\partial S^2} \approx \frac{V^i_{j+1} - 2 V^i_j + V^i_{j-1}}{(\delta S)^2}. \] Assuming that the boundary and final values are known (details not given here) we then use these finite difference replacements to obtain the explicit update formula, \[ V^{i-1}_j = a_j V^i_j + b_j V_{j+1}^i + c_j V_{j-1}^i \] where: \[ a_j = 1 - \frac{\delta t}{(\delta S)^2}\sigma^2 S_j^2 - r\delta t, \] \[ b_j = \frac{\delta t}{(\delta S)^2}\frac{\sigma^2 S_j^2}{2} + \frac{\delta t}{\delta S}\frac{r S_j}{2} \] and \[ c_j = \frac{\delta t}{(\delta S)^2}\frac{\sigma^2 S_j^2}{2} - \frac{\delta t}{\delta S}\frac{r S_j}{2}. \]
Of course, much better schemes exist but the point of this page is to demonstrate a little bit of easily coded computational math on a web page, along with some accompanying mathematical details. The tools are javascript for the code and mathjax for the $\LaTeX$.
Web apps are (possibly) the future...
Some examples of what is possible using HTML 5 are: