15 The Code # 3: 2-D output
Tải bản đầy đủ - 0trang
1222
Part Six numerical methods and programs
Theta = -0.5 * Vol ^ 2 * S(i) ^ 2 * Gamma - _
Int_Rate * S(i) * Delta + Int_Rate * VOld(i) _
’ Black-Scholes
VNew(i) = VOld(i) - dt * Theta ’ Update option value
Next i
VNew(0) = VOld(0) * (1 - Int_Rate * dt) ’ Boundary condition at S=0
VNew(NAS) = 2 * VNew(NAS - 1) - VNew(NAS - 2) ’ Boundary condition at S=infinity
For i = 0 To NAS ’ Replace Old with New
VOld(i) = VNew(i)
Next i
If EType = "Y" Then ’ Check for early exercise
For i = 0 To NAS
VOld(i) = Application.Max(VOld(i), Payoff(i))
Next i
End If
Next k
For i = 1 To NAS - 1
Dummy(i, 3) = VOld(i) ’ Third column of Dummy is option value
Dummy(i, 4) = (VOld(i + 1) - VOld(i - 1)) / 2 / dS ’ Fourth column of Dummy _
is delta
Dummy(i, 5) = (VOld(i + 1) - 2 * VOld(i) + VOld(i - 1)) / dS / dS
’ Fifth column of Dummy is gamma
Dummy(i, 6) = -0.5 * Vol ^ 2 * S(i) ^ 2 * Dummy(i, 5) - _
Int_Rate * S(i) * Dummy(i, 4) + Int_Rate * VOld(i) ’ Sixth column _
of Dummy is theta
Next i
Dummy(0, 3) = VOld(0)
Dummy(NAS, 3) = VOld(NAS)
Dummy(0, 4) = (VOld(1) - VOld(0)) / dS ’ End points need to be treated _
separately for delta, gamma and theta
Dummy(NAS, 4) = (VOld(NAS) - VOld(NAS - 1)) / dS
Dummy(0, 5) = 0
Dummy(NAS, 5) = 0
Dummy(0, 6) = Int_Rate * VOld(0)
Dummy(NAS, 6) = -0.5 * Vol ^ 2 * S(NAS) ^ 2 * Dummy(NAS, 5) - _
Int_Rate * S(NAS) * Dummy(NAS, 4) + Int_Rate * VOld(NAS)
Option_Value_2D_US = Dummy ’ Output array
End Function
Table 77.4 shows the results from this code, same parameters but now 40 asset steps.
77.16 BILINEAR INTERPOLATION
Suppose that we have an estimate for the option value, or its derivatives, on the mesh points;
how can we estimate the value at points in between? The simplest way to do this is to use
finite-difference methods for one-factor models Chapter 77
Table 77.4 Call option values and greeks output by the explicit finitedifference code.
Stock
0
5
10
15
20
25
30
35
40
45
50
55
60
65
70
75
80
85
90
95
100
105
110
115
120
125
130
135
140
145
150
155
160
165
170
175
180
185
190
195
200
Payoff
Option
Delta
Gamma
0.000
0.000
0.000
0.000
0.000
0.000
0.000
0.000
0.000
0.000
0.000
0.000
0.000
0.000
0.000
0.000
0.000
0.000
0.000
0.000
0.000
5.000
10.000
15.000
20.000
25.000
30.000
35.000
40.000
45.000
50.000
55.000
60.000
65.000
70.000
75.000
80.000
85.000
90.000
95.000
100.000
0.000
0.000
0.000
0.000
0.000
0.000
0.000
0.000
0.000
0.001
0.003
0.016
0.058
0.173
0.437
0.953
1.832
3.174
5.044
7.461
10.403
13.816
17.628
21.764
26.149
30.722
35.430
40.235
45.107
50.023
54.969
59.935
64.913
69.900
74.892
79.886
84.883
89.881
94.880
99.878
104.877
0.000
0.000
0.000
0.000
0.000
0.000
0.000
0.000
0.000
0.000
0.002
0.005
0.016
0.038
0.078
0.139
0.222
0.321
0.429
0.536
0.636
0.723
0.795
0.852
0.896
0.928
0.951
0.968
0.979
0.986
0.991
0.994
0.997
0.998
0.999
0.999
0.999
1.000
1.000
1.000
1.000
0.000
0.000
0.000
0.000
0.000
0.000
0.000
0.000
0.000
0.000
0.000
0.001
0.003
0.006
0.010
0.015
0.019
0.021
0.022
0.021
0.019
0.016
0.013
0.010
0.007
0.005
0.004
0.003
0.002
0.001
0.001
0.001
0.000
0.000
0.000
0.000
0.000
0.000
0.000
0.000
0.000
Theta
0.000
0.000
0.000
0.000
0.000
0.000
0.000
0.000
−0.001
−0.005
−0.023
−0.086
−0.256
−0.617
−1.235
−2.113
−3.168
−4.255
−5.224
−5.962
−6.425
−6.625
−6.614
−6.459
−6.225
−5.965
−5.712
−5.488
−5.301
−5.153
−5.039
−4.954
−4.892
−4.848
−4.817
−4.796
−4.781
−4.770
−4.761
−4.754
−4.754
1223
1224
Part Six numerical methods and programs
V1
V2
A3
A4
Want to estimate value here
A2
A1
V4
Figure 77.14
V3
Bilinear interpolation.
a two-dimensional interpolation method called bilinear interpolation. This method is most
easily explained via the schematic diagram in Figure 77.14.
We want to estimate the value of the option, say, at the interior point in the figure. The
values of the option at the four nearest neighbors are called V1 , V2 , V3 and V4 , simplifying
earlier notation just for this brief section. The areas of the rectangles made by the four corners
and the interior point are labeled A1 , A2 , A3 and A4 . But note that the subscripts for the areas
correspond to the subscripts of the option values at the corners opposite. The approximation
for the option value at the interior point is then
4
i=1 Ai Vi
.
4
i=1 Ai
77.17 UPWIND DIFFERENCING
The constraint (77.4) can be avoided if we use a one-sided
difference instead of a central difference for the first derivative of the option value with respect to the asset. As I said
in Chapter 6 the first S derivative represents a drift term. This
drift has a direction associated with it, as t decreases, moving
away from expiry, so the drift is towards smaller S. In a sense,
this makes the forward price of the asset a better variable to
use. Anyway, the numerical scheme can make use of this by using a one-sided difference. That
is the situation for the Black–Scholes equation. More generally, the approximation that we use
finite-difference methods for one-factor models Chapter 77
for delta in the equation could depend on the sign of b. For example, use the following
V k − Vik
∂V
(S, t) = i+1
∂S
δS
if b(S, t) ≥ 0 then
but if
b(S, t) < 0 then
k
V k − Vi−1
∂V
(S, t) = i
.
∂S
δS
This removes the limitation (77.4) on the asset step size, improving stability. However, since
these one-sided differences are only accurate to O(δS) the numerical method is less accurate.
The use of one-sided differences that depend on the sign of the coefficient b is called upwind
differencing.3 There is a small refinement of the technique in the choice of the value chosen
for the function b:
if b(S, t) ≥ 0 then b(S, t)
but if
b(S, t) < 0 then b(S, t)
V k − Vik
∂V
(S, t) = bk 1 i+1
i+ 2
∂S
δS
k
V k − Vi−1
∂V
(S, t) = bk 1 i
.
i− 2
∂S
δS
Notice how I have used the mid-point value for b.4
Below is a Visual Basic code fragment that uses a one-sided difference, depending on the
sign of the drift term. This code fragment can be used for interest rate products, since it is
solving
∂V
∂ 2V
∂V
+ 12 σ (r)2 2 + (µ(r) − λ(r)σ (r))
− rV = 0.
∂t
∂r
∂r
Note the arbitrary σ (r) = Volatility(IntRate(i)) and µ(r) − λ(r)σ (r) =
RiskNeutralDrift(IntRate(i)).
This fragment of code is just the time stepping; above it would go declarations and setting up
the payoff. Below it would go the outputting. It does not implement any boundary conditions
at i = 0 or at i = NoIntRateSteps; these would depend on the contract being valued.
For i = 1 To NoIntRateSteps - 1
If RiskNeutralDrift(IntRate(i)) > 0 Then
Delta(i) = (VOld(i + 1) - VOld(i)) / dr
RNDrift = RiskNeutralDrift(IntRate(i) + 0.5 * dr)
Else
Delta(i) = (VOld(i) - VOld(i - 1)) / dr
RNDrift = RiskNeutralDrift(IntRate(i) - 0.5 * dr)
End If
Gamma(i) = (VOld(i + 1) - 2 * VOld(i) + VOld(i - 1)) / (dr * dr)
VNew(i) = VOld(i) + Timestep * (0.5 * Volatility(IntRate(i)) _
* Volatility(IntRate(i)) * Gamma(i) + RNDrift * Delta(i) - IntRate(i) * VOld(i))
Next i
3
That’s ‘wind’ as in breeze, not as in to wrap or coil.
This choice won’t make much difference to the result but it does help to make the numerical method ‘conservative,’
meaning that certain properties of the partial differential equation are retained by the solution of the difference equation.
Having a conservative scheme is important in computational fluid dynamics applications, otherwise the scheme will exhibit
mass ‘leakage.’
4
1225
1226
Part Six numerical methods and programs
To get back the O(δS 2 ) accuracy of the central difference with a one-sided difference you
can use the approximations described in Section 77.6.
We have seen that the explicit finite-difference method suffers from restrictions in the size of
the grid steps. The explicit method is similar in principle to the binomial tree method, and the
restrictions can be interpreted in terms of risk-neutral probabilities. The terms A, B and C are
related to the risk-neutral probabilities of reaching the points i − 1, i and i + 1. Instability is
equivalent to one of these being a negative quantity, and we can’t allow negative probabilities.
More sophisticated numerical methods exist that do not suffer from such restrictions, and I will
describe these next.
The advantages of the explicit method
• It is very easy to program and hard to make mistakes
• When it does go unstable it is usually obvious
• It copes well with coefficients that are asset and/or time-dependent
• It is easy to incorporate accurate one-sided differences
The disadvantage of the explicit method
• There are restrictions on the time step so the method can be slower than
other schemes
77.18 SUMMARY
The diffusion equation has been around for a long time. Numerical schemes for the solution of
the diffusion equation have been around quite a while too, not as long as the equation itself but
certainly a lot longer than the Black–Scholes equation and the binomial method. This means
that there is a great deal of academic literature on the efficient solution of parabolic equations
in general. I’ve introduced you to the subject with the explicit method, and in the next chapter
I’ll show you how the numerical methods can get more sophisticated.
FURTHER READING
• For general numerical methods see Johnson & Riess (1982) and Gerald & Wheatley (1992).
• The first use of finite-difference methods in finance was due to Brennan & Schwartz (1978).
For its application in interest rate modeling see Hull & White (1990).
• An excellent, well written, book on numerical methods in finance is Ahmad (2006).
CHAPTER 78
further
finite-difference
methods for
one-factor models
In this Chapter. . .
•
•
•
•
•
implicit finite-difference methods including Crank–Nicolson
Douglas schemes
Richardson extrapolation
American-style exercise
exotic options
78.1
INTRODUCTION
We continue with one-factor numerical methods, discussing the more difficult to program
implicit methods. The extra complexity of the methods is outweighed, though, by their superior
stability properties. I also show how to extend the finite-difference method to cope with early
exercise and path-dependent contracts.
78.2
IMPLICIT FINITE-DIFFERENCE METHODS
The fully implicit method uses the points as shown in Figure 78.1 to calculate the option value.
The scheme is superficially just like the explicit method using finite-difference estimates of the
option value, its delta and gamma but now at the time step k + 1. The relationship between the
option values on the mesh is simply
Vik − Vik+1
δt
+ aik+1
k+1
k+1
Vi+1
− 2Vik+1 + Vi−1
δS 2
1228
Part Six numerical methods and programs
S
Calculate option
values at these
points
from the option
value at this point
t
Figure 78.1 The relationship between option values in the fully implicit method.
+ bik+1
k+1
k+1
− Vi−1
Vi+1
2 δS
+ cik+1 Vik+1 = 0.
(It doesn’t matter much whether the coefficients a, b and c are evaluated at the time step k + 1
or k.) The method is still accurate to O(δt, δS 2 ).
This can be written as
k+1
k+1
Ak+1
Vi−1
+ (1 + Bik+1 )Vik+1 + Cik+1 Vi+1
= Vik
i
(78.1)
where
= −ν 1 aik+1 − 12 ν 2 bik+1 ,
Ak+1
i
Bik+1 = 2ν 1 aik+1 − δt cik+1
and
Cik+1 = −ν 1 aik+1 + 12 ν 2 bik+1
where
ν1 =
δt
δS 2
and ν 2 =
δt
.
δS
Again, Equation (78.1) does not hold for i = 0 or i = I , the boundary conditions supply the
two remaining equations.
further finite-difference methods for one-factor models Chapter 78
There is a world of difference between this scheme and the explicit finite-difference scheme.
The two main differences concern the stability of the method and the solution procedure.
The method no longer suffers from the restriction on the time step. The asset step can be
small and the time step large without the method running into stability problems.
The solution of the difference equation is no longer so straightforward. To get Vik+1 from
k
Vi means solving a set of linear equations; each Vik+1 is directly linked to its two neighbors
and thus indirectly linked to every option value at the same time step.
I am not going to pursue the fully implicit method any further since the method can be
significantly improved upon with little extra computational effort.
78.3
THE CRANK–NICOLSON METHOD
The Crank–Nicolson method can be thought of as an average of the explicit method and the
fully implicit method. It uses the six points shown in Figure 78.2.
The Crank–Nicolson scheme is
Vik − Vik+1
δt
+
aik+1
2
k+1
k+1
− 2Vik+1 + Vi−1
Vi+1
δS 2
+
bik+1
2
k+1
k+1
− Vi−1
Vi+1
2 δS
+
+
aik
2
bik
2
k
k
− 2Vik + Vi−1
Vi+1
δS 2
k
k
− Vi−1
Vi+1
2 δS
+ 12 cik+1 Vik+1 + 12 cik Vik = O(δt 2 , δS 2 ).
S
Calculate option
values at these
points
from the option
values at these
points
t
Figure 78.2 The relationship between option values in the Crank–Nicolson method.
1229
1230
Part Six numerical methods and programs
This can be written as
k+1
k+1
k
k
Vi−1
+ (1 − Bik+1 )Vik+1 − Cik+1 Vi+1
= Aki Vi−1
+ (1 + Bik )Vik + Cik Vi+1
,
−Ak+1
i
(78.2)
where
Aki = 12 ν 1 aik − 14 ν 2 bik ,
Bik = −ν 1 aik + 12 δt cik ,
and
Cik = 12 ν 1 aik + 14 ν 2 bik .
These equations only hold for 1 ≤ i ≤ I − 1. The boundary conditions again supply the two
missing equations. They are harder to handle than in the explicit method and I will discuss
them in depth shortly.
Although this looks a bit messy, and it is harder to solve, the beauty of this method lies in
its stability and accuracy. As with the fully implicit method there is no relevant limitation on
the size of the time step for the method to converge. Better yet, the method is more accurate
than the two considered so far. The error in the method is O(δt 2 , δS 2 ). So now we can use
larger time steps, and still get an accurate solution. To see that the error due to the size of the
time step is now O(δt 2 ) expand Equation (78.2) about the point S, t − 12 δt (this is the point
‘x’ in Figure 78.2).
The Crank–Nicolson method can be written in the matrix form
k+1
V0
k+1
V
1
−Ak+1
1 − B1k+1 −C1k+1
0
.
.
.
1
.
.
1 − B2k+1 .
.
.
.
0
−Ak+1
2
.
.
0
.
.
.
0
.
.
k+1
k+1
.
.
.
. 1 − BI −2
−CI −2
0
.
k+1
k+1
1 − BIk+1
.
.
.
0 −Ak+1
V
I −1
−1 −CI −1
I −1
Ak1
0
= .
.
.
1 + B1k
C1k
0
.
.
.
Ak2
0
1 + B2k
.
.
.
.
.
.
0
.
.
CIk−2
0
1 + BIk−1
CIk−1
.
.
.
.
.
0
1+
BIk−2
AkI −1
V0k
V1k
.
.
.
.
.
Vk
I −1
VIk+1
(78.3)
VIk
The two matrices have I − 1 rows and I + 1 columns. This is a representation of I − 1
equations in I + 1 unknowns.
further finite-difference methods for one-factor models Chapter 78
The two equations that we are missing come from the boundary conditions. Using these
conditions, I am going to convert this system of equations, (78.3), into a system of equations
involving a square matrix. The aim is to write the system of equations in the form
k+1
+ rk = MkR vk ,
Mk+1
L v
for known square matrices Mk+1
and MkR , and a known vector rk , and where details of the
L
boundary conditions have been fully incorporated.
I will consider three cases separately, depending on the form of the boundary condition that
is to be implemented. I will also only deal with a boundary condition at i = 0; obviously
boundary conditions at i = I are treated similarly.
78.3.1
Boundary Condition Type I: V0k+1 Given
Sometimes we know that our option has a particular value on the boundary i = 0, or on i = I .
For example, if we have a European put we know that V (0, t) = Ee−r(T −t) . This translates to
knowing that V0k+1 = Ee−r(k+1)δt . We can write
k+1
V0
V k+1
k+1
k+1
1
−Ak+1
1
−
B
−C
0
.
.
.
1
1
1
.
k+1
k+1
1 − B2
.
.
.
.
0
−A2
.
.
.
0
.
.
.
0
.
.
k+1
k+1
.
.
.
.
. 1 − BI −2
−CI −2
0
k+1
k+1
k+1
1
−
B
−C
.
.
.
0 −Ak+1
I −1
I −1
I −1
VI −1
VIk+1
as
1 − B1k+1
−Ak+1
2
+
−C1k+1
0
.
.
1 − B2k+1
.
.
.
0
.
.
.
0
.
.
.
1 − BIk+1
−2
−CIk+1
−2
.
0
−Ak+1
I −1
1 − BIk+1
−1
.
k+1
−Ak+1
1 V0
0
0
.
.
0
.
V1k+1
.
.
.
.
.
VIk+1
−1
= Mk+1 vk+1 + rk .
L
All I have done here is to multiply out the top and bottom rows of the matrix. The matrix ML
is square and of size I − 1. The vector rk , which is of length I − 1, only has non-zero elements
1231
1232
Part Six numerical methods and programs
at the top (and bottom) and is completely known because it only depends on the function A and
the prescribed value of V at the boundary.
78.3.2
Boundary Condition Type II: Relationship Between V0k+1 and V1k+1
If we have a barrier option for which a grid point does not coincide with the barrier we must
use the approximation explained in Section 77.10:
V0k+1 =
1
f − (1 − α)V1k+1 .
α
This relationship between V0k+1 and V1k+1 for a ‘down’ barrier or between VIk+1 and VIk+1
−1 for
an ‘up’ barrier is seen in other contexts. Perhaps we know the slope of the option value for
large or small S; this gives us a gradient boundary condition, which is also of this form. If we
use a one-sided difference for the derivative then the boundary condition can also be written
as a relationship between the last grid point and the last but one. More generally, suppose
we have
V0k+1 = a + bV1k+1 .
This time the left-hand side of (78.3) can be written as
B1k+1
1−
−Ak+1
2
−C1k+1
1−
0
.
.
0
.
.
.
.
.
.
0
.
.
.
1 − BIk+1
−2
−CIk+1
−2
.
.
0
−Ak+1
I −1
1 − BIk+1
−1
B2k+1
k+1
−Ak+1
)
V1k+1
1 (a + bV1
.
0
.
0
.
+
.
.
.
.
.
0
k+1
VI −1
.
Again, this comes from multiplying out the top row of the matrix. By absorbing the V1k+1 term
into the matrix we can write this as
k+1
−aAk+1
V1
1
k+1
k+1
k+1
1 − B1 − bA1
−C1
0 .
.
. 0
1 − B2k+1 . .
.
−Ak+1
2
. 0
0
.
.
.
0
.
. +
.
k+1
k+1
.
.
.
.
.
1
−
B
−C
I
−2
I
−2
. 0
k+1
k+1
.
. 0 −AI −1
1 − BI −1
.
VIk+1
−1
Again this is of the form
k+1
Mk+1
+ rk
L v
but for different Mk+1
and rk from before. This matrix and this vector are both known.
L