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:
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)
#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
n0=10
z=
rho=
total_error=
Computations for the first value of $\rho$:
#do the computations
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$
#computations for the second value of rho
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
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
#compute for next value of rho
#Compare the final answer with the exact option price
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.
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!
#Your CN solver. Sample code will not be given!
Define the data for the exercise
Computations for the first $\rho$, first two computations
Next computation, Runge's estimate:
Next computation, Runge's estimate
Next computation, Runge's estimate
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
#Try to automate the procedure
#compute the final result!
Changing $\rho$ did not change the answer significantly, so the final answer is 22.4045826212