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

Exercises of Lab 12

Suppose we want to find the current prices of an European option so that the error at the current stock price $S(0)=S_0$ was less that $\varepsilon$. When using a finite difference method for the untransformed equation, we have to fix only one artificial boundary; a good starting point is to take $s_{max}=2\cdot S_0$ (if $\sigma$ is large or the time period is long, it may make sense to take larger value for $s_{max}$). In the case of solving the transformed equation, we also have to introduce another boundary for which we may take $s_{min}=\frac{S_0}{2}$ and define $x_{min}=\ln s_{min}, \ x_{max}=\ln s_{max}$. Our procedure is as follows:

  1. Fix a starting value $n_0$ so that $S_0$ corresponds to a grid point and choose $m_0$ (in the case of the explicit method choose it from the stability constraint) and define $z=1$.
  2. Solve the problem with a finite difference method (starting with $n=z\cdot n_0$ and $m=m_0$) in the domain $x_{min}=\ln \frac{S_0}{\rho}$, $x_{max}=\ln (\rho\,S_0)$ in the case of solving the transformed problem or in the domain $x_{min}=0$, $x_{max}=\rho\,S_0$ in the case of solving the untransformed problem and estimate the error by Runge's method, until the (estimated) finite difference discretization error is less than $\frac{\varepsilon}{2}$.
  3. multiply $\rho$ by 2 and increase $z$ by one in the case of the transformed equation or multiply it by two in the case of the untransformed equation and solve the problem with the same method (starting with $n=z\cdot n_0,\ m=m_0$ again until the (estimated) finite difference discretization error is less than $\frac{\varepsilon}{2}$. If the answer changes by more than $\frac{\varepsilon}{2}$ then repeat the step. Otherwise we have obtained the solution with the desired accuracy.

Exercise 1

Use the procedure above to compute the price of the call option with accuracy 0.02 by using the explicit finite difference method for the transformed problem and simple boundary conditions in the case $S_0=51$, $E=50$, $r=0.03$, $D=0$, $T=1$, $\sigma=0.5$. Find the actual error of the final answer.

Solution Of cause the solution procedure can (and finally should) be fully automated as a function that does all needed compuations and returns the final answer. But at leas first time it is reasonable to follow the procedure step by step. So here only step by step solution is presented.

We are going to use the function explicit_solver from lab9 (see the sample solutions of Lab9)

In [ ]:
#copy the solver from lab9 here, define data, payoff function and boundary conditions
   

Let us start the procedure. For this set the starting parameters. For $n_0$ usually a relatively small value (like 10) is chosen

In [ ]:
n0=10
z=
rho=
total_error=

Computations for the first value of $\rho$:

In [ ]:
#do the computations
Expected results (Click to see!) (answer1, answer2,comparison):11.05114939627261 11.028981906128978 True

As the estimate of the discretization error is smaller than half of the total error, we have found the final answer for this $\rho$. If it the estimate were larger than half of the total error, we would continue computing by setting answer1=answer2, multiplying n by 2, computing a new value for answer2 and estimating the discretization error again and so on.

Now we save the final answer for this $\rho$ in a variable and compute the final answer for the next value of $\rho$

In [ ]:
#computations for the second value of rho
Expected results (Click to see!) (answer1, answer2,comparison):11.136678112633405 11.131576052468692 True

As the the estimate of the discretization error is small enough, we have found the answer for the second value of $\rho$. So we save this answer in a variable and check if the truncation error is small enough

In [ ]:
answer_rho2=answer2
print(np.abs(answer_rho1-answer_rho2)<total_error/2)

So changing the value of $\rho$ had significant effect on the answer we got and therefore the truncation error is not small enough. We have to repeat the computations with larger value of $\rho$. For a new computation the last result answer_rho2 becomes the less acurate result answer_rho1, we increase the value of $\rho$ and z and compute a new answer_rho2

In [ ]:
#compute for next value of rho


#Compare the final answer  with the exact option price 
Expected results (Click to see!) Is error estimate valid for the for answer2: True Is the difference of final final answer for this rho and final answer for previous rho small enough?: True final answer: 11.132248310914854 exact price from BS formula: 11.110011780896492

As we see, that the final answer is computed with error that is very close to the allowed error 0.02 but slightly larger. So we have to understand that such practical procedures do not guarantee completely that we obtain the answer with desired accuracy, but usually they work reasonably well. There are several reasons why the error estimates we are using may be slightly wrong - the estimates are of limiting nature (for large enough value of n, the error is reduced approximately 4 times when n is multiplied by 2) and the estimates are valid when the solution of the PDE is smooth enough (has 4 derivatives with respect to it's variables). Actually, the later assumption is not valid for the pricing function of the Call option - since the derivative of the payoff function is not continuos, the pricing function is not 4 times differentiable at $t=T$, so that in Runge's estiamte it is safe not to divide by 3, but only with 1 if it is very important to compute the answer with given accuracy.

Exercise 2

Find the price of the European option with payoff $$p(s)=\begin{cases} 40-\frac{s}{2},& s\leq 80,\\ 0,& 80<s\leq 110,\\ \frac{3s}{2}-165,& s>110 \end{cases}$$ with maximal error $0.01$ for current stock price $S0=105$ in the case, $r=0.05$, $D=0$, $T=0.5$ and nonconstant volatility $$\sigma(s,t)=0.4+\frac{0.3}{1+0.01 (s-90)^2}.$$ Use Crank-Nicolson method for the untransformed equation, the exact boundary condition $$\phi_1(t)=p(0)e^{-r(T-t)}$$ at the boundary $x_{min}=0$ and the boundary condition corresponding to a special (linear in $s$) solution at the boundary $x=s_{max}$ to obtain the answer.

Solution

Define a solver which uses CN method. You can compare your results with the results given below to make sure that your solver works correctly!

In [ ]:
#Your CN solver. Sample code will not be given!

Define the data for the exercise

In [ ]:

Computations for the first $\rho$, first two computations

In [ ]:
 
Expected results (Click to see!) (answer1, answer2,comparison):21.869894170779006 22.429008391925763 False

Next computation, Runge's estimate:

In [ ]:
 
Expected results (Click to see!) (answer1, answer2,comparison):22.429008391925763 22.361372997046733 False

Next computation, Runge's estimate

In [ ]:
 
Expected results (Click to see!) (answer1, answer2,comparison):22.361372997046733 22.39863057158521 False

Next computation, Runge's estimate

In [ ]:
 
Expected results (Click to see!) (answer1, answer2,comparison):22.39863057158521 22.404554164523827 True

Now we have finished with the first value of $\rho$. We have to do the same for the next value of $\rho$. Of cause it is possible to avoid copying the same lines over and over again by using a while cycle

In [ ]:
#Try to automate the procedure
#compute the final result!
Expected results (Click to see!) (answer_rho1, answer_rho2,comparison):22.404554164523827 22.404582621241758 True

Changing $\rho$ did not change the answer significantly, so the final answer is 22.4045826212