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$.
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.
#define modified solver which can solve American options
#compute prices and differences
#produce graph of logarithm of differences
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:
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.
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
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.
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)
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)
Let us define a funciton for computing the derivative in the case of the untransformed problem:
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.