Creation of this worksheet was supported by IT Academy program of Information Technology Foundation for Education (HITSA)

Exercises of Lab 15

The aim of the lab is to learn to compute prices of Asian options.

Let us assume that the volatility $\sigma$ in the Black-Scholes market model depends only on time and the current stock price $S$.

Let $v(s,I,t)$ be the function giving the price of an Asian option (depending on arithmetic average) with exercise time $T$ and payoff $p(s,A_T)$. For finding approximate option prices we introduce artificial boundaries $I_{max},S_{max}$, choose natural numbers $n_s,n_I,m$ and look for approximate values of $v$ at points $(s_i,I_j,t_k)$, where $$s_i=i \Delta s=i\frac{S_{max}}{n_s},\ I_j=j\Delta I=j\frac{I_{max}}{n_I},\ t_k=k\Delta t=k\frac{T}{m}.$$ Denote those approximate values by $V_{ijk}$. A finite difference approximation gives the following equations for the unknown values: $$a_{ik}V_{i-1,jk}+b_{ik}V_{ijk}+c_{ik}V_{i+1,jk}=\frac{s_i\Delta t}{\Delta I}V_{i,j+1,k}+V_{ij,k+1},$$ where $i=1,2,\ldots,n_s-1,\ j=0,1,\ldots,n_I-1,\ k=0,\ldots,m-1$ and (using the notation $\rho=\frac{\Delta t}{\Delta s^2}$) \begin{align*} a_{ik}&=\frac{\rho}{2}(-s_i^2\sigma^2(s_i,t_k)+(r-D)s_i\Delta s),\\ b_{ik}&=\left(1+\rho s_i^2\sigma^2(s_i,t_k)+\frac{s_i\Delta t}{\Delta I}+r\Delta t \right), \\ c_{ik}&=- \frac{\rho}{2}(s_i^2\sigma^2(s_i,t_k)+(r-D)s_i\Delta s). \end{align*}

The equations together with equations for $V_{0jk}$ and $V_{n_s,j,k}$ (specified below) can be viewed as a three-diagonal system for finding the values of $V_{ijk},\ i=0,\ldots,n_s$, if the values corresponding to the level $t=t_{k+1}$ and the values $V_{i,j+1,k},\ i=0,\ldots,n_s$ have been found earlier. So we solve the system in backward direction with respect to k (for $k=m-1,m-2,...,0$) for each $k$, we solve it for $j=n_I-1,n_I-2,...,0$.

The values of $V_{ijm}$ can be found from the final condition: $$V_{ijm}=p(s_i,\frac{I_j}{T}),\ i=0,\ldots,n_s,\ j=0,\ldots,n_I.$$ At the boundary $S=0$ we have the exact boundary condition $v(0,I,t)=p(0,\frac{I}{T})e^{-r\,(T-t)}$, hence $$V_{0jk}=p(0,\frac{I_j}{T})e^{-r (T-t_k)},\ k=0,\ldots,m-1.$$ In order to determine all values of $V_{ijk}$ uniquely, we have to specify boundary conditions for the boundary $I=I_{max}$ and the boundary $s=S_{max}$. Denote by $\phi_1(s,I_{max},t)$ and $\phi_2(S_{max},I,t)$ the functions describing the boundary conditions, then $$V_{i,n_I,k}=\phi_1(s_i,I_{max},t_k),\ V_{n_s,j,k}=\phi_2(S_{max},I_j,t_k).$$

The procedure for solving the option pricing equation is as follows.

  1. Fill in the values for $V_{ijm},\ i=0,\ldots,n_s,\ j=0,\ldots,n_I$, using the payoff function.
  2. For each $k=m-1,m-2,\ldots,0$
    1. Apply the boundary condition at $I=I_{max}$ to define $V_{i,n_I,k},\ i=0,\ldots,n_s$.
    2. For each $j=n_I-1,\ldots,0$ solve the three-diagonal system for values $V_{ijk},\ i=0,\ldots,n_s$, using the boundary conditions at $s=0$ and $s=S_{max}$ to get two additional equations .

Exercise 1 Let us consider an average price put option (payoff function $p(s,A_T)=\max(E-A_T,0)$, where $E$ is the exercise price specified in the option contract). Assume $r=0.05$, $D=0$, $\sigma=0.5$, $T=0.5$, $E=100$, $S(0)=95$. Define $I_{max}=E\,T$, $S_{max}=190$, $\phi_1(s,I_{max},t)=0$, $$\phi_2(S_{max},I,t)=\max\{Ee^{-r (T-t)}+\frac{e^{-D (T-t)}}{(r-D)T}(e^{-(r-D)(T-t)}-1)S_{max}-\frac{e^{-r(T-t)}}{T}I,0\}.$$ Write a function, that for given values $m,n_s,n_I$ finds an approximate option price at $t=0$ using the finite difference method described above. Use this function to compute approximately the option price for $m=50,n_s=100,n_I=100$

Solution Define the general solver function:

Define a function test, which solves the problem given in the exercise for given m,ns,nI and returns the full matrix V of computed option prices.

Run the following cell and compare your answers to expected results. If there are some differences, correct the part of code which computes corresponding values.

Test your results! Final condition: [[100. 75. 50. 25. 0.] [100. 75. 50. 25. 0.] [100. 75. 50. 25. 0.] [100. 75. 50. 25. 0.] [100. 75. 50. 25. 0.]] Boundary at Imax [[0. 0. 0. 0. 0.] [0. 0. 0. 0. 0.] [0. 0. 0. 0. 0.] [0. 0. 0. 0. 0.] [0. 0. 0. 0. 0.]] Boundary at Smax [[ 0. 0. 4.3490638 52.0250778 100. ] [ 0. 0. 0. 27.18084053 75. ] [ 0. 0. 0. 2.33660327 50. ] [ 0. 0. 0. 0. 25. ] [ 0. 0. 0. 0. 0. ]] Boundary at s=0: [[ 97.5309912 98.14246877 98.75778005 99.37694906 100. ] [ 73.1482434 73.60685158 74.06833504 74.5327118 75. ] [ 48.7654956 49.07123439 49.37889002 49.68847453 50. ] [ 24.3827478 24.53561719 24.68944501 24.84423727 25. ] [ 0. 0. 0. 0. 0. ]] Prices at t=0, corresponding to different s and I values [[97.5309912 73.1482434 48.7654956 24.3827478 0. ] [54.94201646 34.48362335 17.34808618 5.39330293 0. ] [29.25738355 16.25859913 7.03726952 1.81630934 0. ] [14.14402945 7.28555597 2.8996165 0.68521056 0. ] [ 0. 0. 0. 0. 0. ]]

Define function price(m,ns,nI), which computes the price of option at t=0 corresponding to S(0)=95 and compute the price for $m=50,n_s=100,n_I=100$

Check your result!

Answer should be 12.258574036017402

Exercise 2

Keeping a 3-dimensional array of approximate option prices in memory requires a lot of space (RAM). If we need only prices at time $t=0$, we can avoid storing the full matrix. One possibility is to keep available only values for two time levels - one, which we have already filled with values and the other one with which we currently work. So, inside the for cycle for k we should have (ns+1)x(nI+1) matrix Vold, which corresponds to V[i,j,k+1] for the current value of k, and a (ns+1)x(nI+1) matrix Vnew, corresponding to V[i,j,k], which we fill with computed values step-by-step.

Please modify the solver and the pricing function of the previous exercise so that only 2-dimensional matrices are used.

Solution