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

Exercises of Lab13

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

If we have reduced the Black-Scholes equation for pricing function of European option to a problem of the form \begin{align*} \frac{\partial u}{\partial t}(x,t)&+\alpha(x,t)\frac{\partial^2 u}{\partial x^2}(x,t)+ \beta(x, t)\frac{\partial u}{\partial x}(x,t)-r\, u(x,t),\ x\in (x_{min},x_{max}), 0\leq t <T, \\ u(x_{min},t)&=\phi_1(t), 0\leq t <T, \\ u(x_{max},t)&=\phi_2(t), 0\leq t <T, \\ u(x,T)&=u_0(x),\ x\in (x_{min},x_{max}). \end{align*} and have derived a finite difference method for computing option prices, then approximate prices of the corresponding American option can be computed by taking maximum of found approximate prices $U_{ik}$ and the values of $u_0(x_i)$ at each time step before computing the values corresponding to $t=t_{k-1}$. The convergence rate of the resulting method is $O(\Delta t+\Delta x^2)$ even in the case of Crank-Nicolson method. The transformed equation is of this form with $u_0(x)=p(e^x)$, $\alpha(x,t)=\frac{\sigma(e^x,t)^2}{2}$ and $\beta(x,t)=r-D-\alpha(x,t)$; the untransformed equation (if we rename $s$ to $x$) is also of this form with $u_0(x)=p(x)$, $\alpha(x,t)=\frac{x^2 \sigma(x,t)^2}{2}$, $\beta(x,t)=(r-D)\cdot x$.

Exercise 1

Modify the solver using the basic implicit methods for computing prices of American options. Use the methods for computing approximate prices of the American put option in the case $r=0.1$, $\sigma=0.5$, $D=0$, $T=0.5$, $E=100$, $S_0=100$, $p(s)=\max(E-s,0)$ and for $n=10,20,40,80,160$, $m=5,20,80,320,1280$ (5 computations in total) by solving the transformed BS equation and then repeat computations for the untransformed (original) BS equation. Use $x_{max}$ that corresponds to the maximal stock price $2\cdot S_0$ (for transformed problem, it means that $x_{max}=\ln(2\cdot S_0)$) and in the case of solving the transformed problem, $x_{min}=\ln \frac{S0}{2}$ ($x_{min}=0$ in the case of solving untransformed problem). Use constant boundary conditions at both boundaries. In each case, compute the logarithms of the absolute values of differences between consecutive results and present them on a graph. Can we say that the values lie approximately on a straight line? If we can, what is the slope of the line?

Solution Let us consider first the solver for transformed BS equation.

In [ ]:
#define modified solver which can solve American options
#compute prices and differences
#produce graph of logarithm of differences
Check your results! computed prices: 11.07012914 11.67524142 11.84278767 11.88782766 11.89981267 computed differences: 0.60511228 0.16754625 0.04503999 0.011985

Looking at the differences, it is quite clear that at every step the differences are reduced approximately 4 times, which is consistent with the error estimate of the form $O(\Delta t+\Delta x^2)$. The logarithm of the differences displays linear decay, which is an alternative way to verify that at each new iteration the discretisation error is reduced by a fixed factor.

Similar computations in the case of untransformed problem:

In [ ]:
 
Check your results! computed prices: 10.6763245 11.60117483 11.82279662 11.88270707 11.89850574 computed differences: 0.92485033 0.22162179 0.05991045 0.01579867

Exercise 2

Find the price of the American put option considered in the previous exercise with maximal error $0.01$ for current stock price $S0=100$.Use basic implicit method for solving transformed BS equation in the case $m_0=10,n_0=10$.

Solution Let us compute the price by solving TBS with the basic implicit method. Let us improve the code of Lab 12 a little by defining a function for computing a result by a given discretisation error in the case when Runge's error estimate is used.

In [ ]:
def Runge(m0,n0,mfactor,nfactor,q,value,error):
    """value is a function of m,n, should return answer (a number)
    if we multipy m by mfactor,n by nfactor, the error is reduced by q
    error - how accurate answer we want
    """
    m=
    n=
    answer1=
    estimate=error+1
    while estimate>error:
        m=
        n=
        answer2=
        estimate= #Runges estimate
        answer1=answer2
        print("runge",m,n,rho,estimate)
    return answer2

Now, if we want to compute a price of option with a given accuracy, we should define a function that for given m and n returns an approximate price of the option. In the case of using the explicit method, the value of m given to the function is actually not used in the computation

In [ ]:
def price_implicit(m,n):
    return 

Now we can start the procedure of computing the price with a given accuracy. Of cause this part of the code can also be improved by defining a suitable function but this improvement is left as an exercise for the reader.

In [ ]:
total_error=0.01
rho=2
#after changing rho, correct xmin and xmax should be computed
xmin=
xmax=
answer_rho1=
estimate_rho=total_error
z=1
while estimate_rho>total_error/2:
   z=
   rho=
   #for each new value of rho we need to define new xmin and xmax
   xmin=
   xmax=
   answer_rho2=
   #estimate the truncation error
   estimate_rho=
   answer_rho1=answer_rho2
print("the price of the option is",answer_rho2)
Check your results! Runge's error estimates for the first location of the boundaries: numbers are m, n, rho, error estimate runge 40 20 2 0.1428352008851146 runge 160 40 2 0.03752101439394492 runge 640 80 2 0.009942411044166969 runge 2560 160 2 0.0025943869936787913 Runge's error estimates for the second location of the boundaries: numbers are m, n, rho, error estimate runge 40 40 4 0.14340614766110113 runge 160 80 4 0.037417590739352136 runge 640 160 4 0.009918185980755704 runge 2560 320 4 0.002588600084975449 Final answer: 11.901646333461995

Exercise 3

If we use the transformed equation for finding approximate prices, we can approximate the derivative of the option price with respect to $s$ by $$\frac{\partial v}{\partial s}(S(0),0)=\frac{1}{S(0)}\frac{\partial u}{\partial x}(\ln S(0),0)\approx \frac{1}{S(0)} \frac{U_{i+1,0}-U_{i-1,0}}{2 \Delta x},$$ where $i$ is such that $x_i=\ln S(0)$. If we use the untransformed equation for finding approximate prices, we can approximate the derivative of the option price with respect to $s$ by $$\frac{\partial v}{\partial s}(S(0),0)\approx \frac{U_{i+1,0}-U_{i-1,0}}{2 \Delta s},$$ where $i$ is such that $s_i=S(0)$. If we use our standard methods of choosing $m$ and $n$ values, then the discretization error of those approximations is at least $O(\Delta x)$ for the transformed equation and $O(\Delta s)$ for the untransformed equation (can you see why?) and hence it is safe to assume that the discretisation error is reduced approximately by two when we do computations with new $m$ and $n$ values.

Exercise Find the value $\frac{\partial v}{\partial s}(100,0)$ of the price $v$ of American put option with maximal error $0.001$ for the option considered in the previous exercise by using the explicit method for solving transformed BS equation.

Solution Here a solution by using the solver for TBS using the explicit method is given.

Define the solver (and the helper function for finding max value of alpha)

In [ ]:
 

Let us define a funciton for computing the derivative in the case of the untransformed problem:

In [ ]:
def derivative(n,American,i_price):
    #i_price is the index of the current stock price for which we compute the derivative
    prices=
    #need to know delta_s
    xmax=
    xmin=
    delta_s=
    return #formula for the derivative
n=10
rho=2
derivative(n,True,n//2)

Now we can use same procedure as before, but have to take into account that the error of the answer is reduced by 2, when n is multiplied by 2 and m is multiplied by 4.

In [ ]:
 
Check your result! If derivatives are computed with n_0=10, the results are as follows: First location of the boundary: runge 40 20 2 0.0008647286485480854 runge 160 40 2 0.0002899085041087046 Second location of the boundary: runge 40 40 4 0.000839527279675456 runge 160 80 4 0.0002790149376876716 Final answer: the delta of the option is -0.40002872378992466