第11节 隐式有限差分法计算期权价格
11.1 简介
我们这里也以美式看跌期权为例。类似显示有限差分法,我们也先将微分方程表示为差分形式。只是这时
∂
f
∂
t
(
i
,
j
)
\frac{\partial f}{\partial t}(i,j)
∂t∂f(i,j)的表示是向前近似。首先同样的,我们让
Δ
S
=
S
m
a
x
M
,
Δ
t
=
T
N
,
S
m
a
x
=
3
S
0
,
f
(
i
,
j
)
=
f
(
i
Δ
t
,
j
Δ
S
)
,
S
(
i
,
j
)
=
j
Δ
S
.
\Delta S = \frac{S_{max}}{M}, \; \Delta t = \frac{T}{N},\; S_{max} = 3S_0,\; f(i,j) = f(i\Delta t, j\Delta S),\;S(i,j)= j\Delta S\;.
ΔS=MSmax,Δt=NT,Smax=3S0,f(i,j)=f(iΔt,jΔS),S(i,j)=jΔS.
然后由
∂
f
∂
t
(
i
,
j
)
+
r
S
(
i
,
j
)
∂
f
∂
S
(
i
,
j
)
+
1
2
σ
2
S
2
(
i
,
j
)
∂
2
f
∂
S
2
(
i
,
j
)
=
r
f
(
i
,
j
)
,
\frac{\partial f}{\partial t}(i, j) +rS(i,j)\frac{\partial f}{\partial S}(i,j)+\frac{1}{2}\sigma^2S^2(i,j)\frac{\partial^2f}{\partial S^2}(i,j)=rf(i,j)\;,
∂t∂f(i,j)+rS(i,j)∂S∂f(i,j)+21σ2S2(i,j)∂S2∂2f(i,j)=rf(i,j),
∂
f
∂
t
(
i
,
j
)
=
f
(
i
+
1
,
j
)
−
f
(
i
,
j
)
Δ
t
,
\frac{\partial f}{\partial t}(i,j) = \frac{f(i+1,j)-f(i,j)}{\Delta t}\;,
∂t∂f(i,j)=Δtf(i+1,j)−f(i,j),
∂
f
∂
S
(
i
,
j
)
=
f
(
i
,
j
+
1
)
−
f
(
i
,
j
−
1
)
2
Δ
S
,
\frac{\partial f}{\partial S}(i,j) = \frac{f(i,j+1)-f(i,j-1)}{2\Delta S}\;,
∂S∂f(i,j)=2ΔSf(i,j+1)−f(i,j−1),
∂
2
f
∂
S
2
(
i
,
j
)
=
f
(
i
,
j
+
1
)
+
f
(
i
,
j
−
1
)
−
2
f
(
i
,
j
)
Δ
S
2
.
\frac{\partial^2 f}{\partial S^2}(i,j) = \frac{f(i,j+1)+f(i,j-1)-2f(i,j)}{\Delta S^2}\;.
∂S2∂2f(i,j)=ΔS2f(i,j+1)+f(i,j−1)−2f(i,j).
得到
f
(
i
+
1
,
j
)
=
a
j
f
(
i
,
j
−
1
)
+
b
j
f
(
i
,
j
)
+
c
j
f
(
i
,
j
+
1
)
,
f(i+1,j)=a_jf(i,j-1)+b_jf(i,j)+c_jf(i,j+1)\;,
f(i+1,j)=ajf(i,j−1)+bjf(i,j)+cjf(i,j+1),
a
j
=
1
2
r
j
Δ
t
−
1
2
σ
2
j
2
Δ
t
,
a_j = \frac{1}{2}rj\Delta t-\frac{1}{2}\sigma^2j^2\Delta t\;,
aj=21rjΔt−21σ2j2Δt,
b
j
=
1
+
r
Δ
t
+
σ
2
j
2
Δ
t
,
b_j = 1+r\Delta t+\sigma^2j^2\Delta t\;,
bj=1+rΔt+σ2j2Δt,
c
j
=
−
1
2
r
j
Δ
t
−
1
2
σ
2
j
2
Δ
t
.
c_j = -\frac{1}{2}rj\Delta t-\frac{1}{2}\sigma^2j^2\Delta t\;.
cj=−21rjΔt−21σ2j2Δt.
然后对于所有
i
i
i时刻的
f
(
i
,
j
)
f(i,j)
f(i,j)和所有
i
+
1
i+1
i+1时刻的
f
(
i
+
1
,
j
)
f(i+1,j)
f(i+1,j)就会有关系:
(
b
1
c
1
a
2
b
2
c
2
a
3
b
3
c
3
⋱
⋱
⋱
a
M
−
2
b
M
−
2
c
M
−
2
a
M
1
b
M
−
1
)
⋅
(
f
(
i
,
1
)
f
(
i
,
2
)
f
(
i
,
3
)
⋮
f
(
i
,
M
−
2
)
f
(
i
,
M
−
1
)
)
=
(
f
(
i
+
1
,
1
)
−
a
1
f
(
i
,
0
)
f
(
i
+
1
,
2
)
f
(
i
+
1
,
3
)
⋮
f
(
i
+
1
,
M
−
2
)
f
(
i
+
1
,
M
−
1
)
−
c
M
−
1
f
(
i
,
M
)
)
.
\left(\begin{array}{cccccc} b_1 & c_1 & \quad &\quad &\quad &\quad \\ a_2 & b_2 & c_2 & \quad & \quad & \quad \\ \quad & a_3 & b_3 & c_3 & \quad & \quad\\\quad&\quad&\ddots&\ddots&\ddots&\quad\\ \quad & \quad & \quad & a_{M-2} & b_{M-2} & c_{M-2}\\\quad & \quad &\quad &\quad & a_{M_1} & b_{M-1}\end{array}\right)\cdot\left(\begin{array}{c}f(i,1)\\f(i,2)\\ f(i,3) \\ \vdots \\ f(i,M-2)\\ f(i,M-1)\end{array}\right) = \left(\begin{array}{c}f(i+1,1)-a_1f(i,0)\\f(i+1,2)\\f(i+1,3)\\ \vdots \\ f(i+1,M-2)\\ f(i+1,M-1)-c_{M-1}f(i,M)\end{array}\right)\;.\\
⎝⎜⎜⎜⎜⎜⎜⎛b1a2c1b2a3c2b3⋱c3⋱aM−2⋱bM−2aM1cM−2bM−1⎠⎟⎟⎟⎟⎟⎟⎞⋅⎝⎜⎜⎜⎜⎜⎜⎜⎛f(i,1)f(i,2)f(i,3)⋮f(i,M−2)f(i,M−1)⎠⎟⎟⎟⎟⎟⎟⎟⎞=⎝⎜⎜⎜⎜⎜⎜⎜⎛f(i+1,1)−a1f(i,0)f(i+1,2)f(i+1,3)⋮f(i+1,M−2)f(i+1,M−1)−cM−1f(i,M)⎠⎟⎟⎟⎟⎟⎟⎟⎞.
我们可以将其记为
M
⋅
F
i
=
F
i
+
1
.
M\cdot F_i = F_{i+1} \; .
M⋅Fi=Fi+1.
其中
M
,
F
i
+
1
M,\,F_{i+1}
M,Fi+1都是已知的,
F
i
F_i
Fi为上一时刻除边界外的未知价格。对
M
M
M求逆后,我们有
F
i
=
M
−
1
F
i
+
1
.
F_i = M^{-1}F_{i+1} \; .
Fi=M−1Fi+1.
然后加上上下边界
f
(
i
,
M
)
=
0
,
f
(
i
,
0
)
=
K
f(i,M)=0,\; f(i,0)=K
f(i,M)=0,f(i,0)=K,即得到由差分关系递推出的
i
i
i时刻期权价格。然后考虑在每个格点处是否应该执行美式看跌期权,就完成了一次美式看跌期权价格的递推。这样重复进行到初始时刻,即可得到隐式差分法计算的美式看跌期权价格。
11.2 计算美式看跌期权价格算法
- 确定时间和股价变化范围, 0 ≤ t ≤ T , 0 ≤ S ≤ S m a x , S m a x = 3 S 0 0\leq t\leq T,\; 0\leq S\leq S_{max},\;S_{max}=3S_0 0≤t≤T,0≤S≤Smax,Smax=3S0,并将区间离散化为二维等间距网格点, Δ t = T / N , Δ S = S m a x / M \Delta t = T/N, \; \Delta S = S_{max}/M Δt=T/N,ΔS=Smax/M。
- 确定 T T T时刻期权价格 f ( N , j ) = max ( 0 , K − j Δ S ) f(N,j) = \max{(0, K-j\Delta S)} f(N,j)=max(0,K−jΔS)。
- 往上一时刻递推。由 F i = M − 1 F i + 1 F_i = M^{-1}F_{i+1} Fi=M−1Fi+1,先计算出 M M M和 F i + 1 F_{i+1} Fi+1,再求出 M − 1 M^{-1} M−1,即得到 F i = ( f ( i , 1 ) , f ( i , 2 ) , . . . , f ( i , M − 1 ) ) T F_i = (f(i,1),f(i,2),...,f(i,M-1))^T Fi=(f(i,1),f(i,2),...,f(i,M−1))T,加上上下股价边界边界条件 f ( i , 0 ) = K , f ( i , M ) = 0 f(i,0)=K,\;f(i,M)=0 f(i,0)=K,f(i,M)=0,就得出 i i i时刻所有股价对应的 f ( i , j ) f(i,j) f(i,j)。
- 考虑应不应该在 i i i时刻的格点处执行美式看跌期权,即更新 f ( i , j ) = max ( f ( i , j ) , K − Δ S j ) f(i,j) = \max{(f(i,j), K-\Delta Sj)} f(i,j)=max(f(i,j),K−ΔSj)。
- 重复步骤3、4直到初始时刻,然后使用线性插值法得出 S = S 0 S=S_0 S=S0处的期权价格。
11.3 算法Python代码实现
import numpy as np
def American_put_implicit(r, sigma, S_0, K, T, M, N):
dS = 3*S_0/M
dt = T/N
# 将 a_j, b_j, c_j 写为3个函数。
a = lambda j: 0.5*r*j*dt-0.5*sigma*sigma*j*j*dt
b = lambda j: 1+r*dt+sigma*sigma*j*j*dt
c = lambda j: -0.5*r*j*dt-0.5*sigma*sigma*j*j*dt
# f1 和 f2 为两列用来迭代计算的期权价格。
f1 = [max(K-i*dS, 0.0) for i in range(M+1)]
f2 = [None for i in range(M+1)]
# coeffs 为上文中的 M 系数矩阵。
coeffs = np.zeros((M-1, M-1))
for i in range(N-1, -1, -1):
f2 = list(f1)
coeffs[0][0] = b(1)
coeffs[0][1] = c(1)
coeffs[M-2][M-2] = b(M-1)
coeffs[M-2][M-3] = a(M-1)
for j in range(2, M-1, 1):
coeffs[j-1][j-2] = a(j)
coeffs[j-1][j-1] = b(j)
coeffs[j-1][j] = c(j)
# 参数矩阵求逆。
coeffs_inv = np.linalg.inv(coeffs)
F2 = f2[1:-1]
F2[0] -= a(1)*K
F1 = np.matmul(coeffs_inv, F2)
f1[1:M] = F1
f1[0] = K
f1[M] = 0
# 判断是否执行美式看跌期权。
f1 = np.maximum(f1, K-np.linspace(0, M, M+1)*dS)
pos = int(S_0/dS)
put_price = f1[pos] + (f1[pos+1]-f1[pos])/dS*(S_0-pos*dS)
return put_price
# 计算例子。
if __name__ == "__main__":
put_price = American_put_implicit(0.1, 0.4, 50, 50, 5/12.0, 300, 300)
print("American put price: {0:0.5f}".format(put_price))
American put price: 4.27847
11.4 参考资料
- 《期权、期货及其他衍生产品》,John C. Hull 著,王勇、索吾林译。