-
Notifications
You must be signed in to change notification settings - Fork 0
/
BCC_option_valuation.py
280 lines (235 loc) · 8.33 KB
/
BCC_option_valuation.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
#
# Valuation of European Call and Put Options
# Under Stochastic Volatility and Jumps
# 09_gmm/BCC_option_valuation.py
#
# (c) Dr. Yves J. Hilpisch
# Derivatives Analytics with Python
#
import numpy as np
from scipy.integrate import quad
from CIR_zcb_valuation import B
import warnings
warnings.simplefilter('ignore')
#
# Example Parameters B96 Model
#
# H93 Parameters
kappa_v = 1.5
theta_v = 0.02
sigma_v = 0.15
rho = 0.1
v0 = 0.01
# M76 Parameters
lamb = 0.25
mu = -0.2
delta = 0.1
sigma = np.sqrt(v0)
# General Parameters
S0 = 100.0
K = 100.0
T = 1.0
r = 0.05
#
# Valuation by Integration
#
def BCC_call_value(S0, K, T, r, kappa_v, theta_v, sigma_v, rho, v0,
lamb, mu, delta):
''' Valuation of European call option in B96 Model via Lewis (2001)
Fourier-based approach.
Parameters
==========
S0: float
initial stock/index level
K: float
strike price
T: float
time-to-maturity (for t=0)
r: float
constant risk-free short rate
kappa_v: float
mean-reversion factor
theta_v: float
long-run mean of variance
sigma_v: float
volatility of variance
rho: float
correlation between variance and stock/index level
v0: float
initial level of variance
lamb: float
jump intensity
mu: float
expected jump size
delta: float
standard deviation of jump
Returns
=======
call_value: float
present value of European call option
'''
int_value = quad(lambda u: BCC_int_func(u, S0, K, T, r, kappa_v, theta_v,
sigma_v, rho, v0, lamb, mu, delta),
0, np.inf, limit=250)[0]
call_value = max(0, S0 - np.exp(-r * T) * np.sqrt(S0 * K) /
np.pi * int_value)
return call_value
def H93_call_value(S0, K, T, r, kappa_v, theta_v, sigma_v, rho, v0):
''' Valuation of European call option in H93 model via Lewis (2001)
Fourier-based approach.
Parameters
==========
S0: float
initial stock/index level
K: float
strike price
T: float
time-to-maturity (for t=0)
r: float
constant risk-free short rate
kappa_v: float
mean-reversion factor
theta_v: float
long-run mean of variance
sigma_v: float
volatility of variance
rho: float
correlation between variance and stock/index level
v0: float
initial level of variance
Returns
=======
call_value: float
present value of European call option
'''
int_value = quad(lambda u: H93_int_func(u, S0, K, T, r, kappa_v,
theta_v, sigma_v, rho, v0),
0, np.inf, limit=250)[0]
call_value = max(0, S0 - np.exp(-r * T) * np.sqrt(S0 * K) /
np.pi * int_value)
return call_value
def M76_call_value(S0, K, T, r, v0, lamb, mu, delta):
''' Valuation of European call option in M76 model via Lewis (2001)
Fourier-based approach.
Parameters
==========
S0: float
initial stock/index level
K: float
strike price
T: float
time-to-maturity (for t=0)
r: float
constant risk-free short rate
lamb: float
jump intensity
mu: float
expected jump size
delta: float
standard deviation of jump
Returns
=======
call_value: float
present value of European call option
'''
sigma = np.sqrt(v0)
int_value = quad(lambda u: M76_int_func_sa(u, S0, K, T, r,
sigma, lamb, mu, delta),
0, np.inf, limit=250)[0]
call_value = max(0, S0 - np.exp(-r * T) * np.sqrt(S0 * K) /
np.pi * int_value)
return call_value
#
# Integration Functions
#
def BCC_int_func(u, S0, K, T, r, kappa_v, theta_v, sigma_v, rho, v0,
lamb, mu, delta):
''' Valuation of European call option in BCC97 model via Lewis (2001)
Fourier-based approach: integration function.
Parameter definitions see function BCC_call_value.'''
char_func_value = BCC_char_func(u - 1j * 0.5, T, r, kappa_v, theta_v,
sigma_v, rho, v0, lamb, mu, delta)
int_func_value = 1 / (u ** 2 + 0.25) \
* (np.exp(1j * u * np.log(S0 / K)) * char_func_value).real
return int_func_value
def H93_int_func(u, S0, K, T, r, kappa_v, theta_v, sigma_v, rho, v0):
''' Valuation of European call option in H93 model via Lewis (2001)
Fourier-based approach: integration function.
Parameter definitions see function H93_call_value.'''
char_func_value = H93_char_func(u - 1j * 0.5, T, r, kappa_v,
theta_v, sigma_v, rho, v0)
int_func_value = 1 / (u ** 2 + 0.25) \
* (np.exp(1j * u * np.log(S0 / K)) * char_func_value).real
return int_func_value
def M76_int_func_sa(u, S0, K, T, r, sigma, lamb, mu, delta):
''' Valuation of European call option in M76 model via Lewis (2001)
Fourier-based approach: integration function.
Parameter definitions see function M76_call_value.'''
char_func_value = M76_char_func_sa(u - 0.5 * 1j, T, r, sigma,
lamb, mu, delta)
int_func_value = 1 / (u ** 2 + 0.25) \
* (np.exp(1j * u * np.log(S0 / K)) * char_func_value).real
return int_func_value
#
# Characteristic Functions
#
def BCC_char_func(u, T, r, kappa_v, theta_v, sigma_v, rho, v0,
lamb, mu, delta):
''' Valuation of European call option in BCC97 model via Lewis (2001)
Fourier-based approach: characteristic function.
Parameter definitions see function BCC_call_value.'''
BCC1 = H93_char_func(u, T, r, kappa_v, theta_v, sigma_v, rho, v0)
BCC2 = M76_char_func(u, T, lamb, mu, delta)
return BCC1 * BCC2
def H93_char_func(u, T, r, kappa_v, theta_v, sigma_v, rho, v0):
''' Valuation of European call option in H93 model via Lewis (2001)
Fourier-based approach: characteristic function.
Parameter definitions see function BCC_call_value.'''
c1 = kappa_v * theta_v
c2 = -np.sqrt((rho * sigma_v * u * 1j - kappa_v) ** 2 -
sigma_v ** 2 * (-u * 1j - u ** 2))
c3 = (kappa_v - rho * sigma_v * u * 1j + c2) \
/ (kappa_v - rho * sigma_v * u * 1j - c2)
H1 = (r * u * 1j * T + (c1 / sigma_v ** 2) *
((kappa_v - rho * sigma_v * u * 1j + c2) * T -
2 * np.log((1 - c3 * np.exp(c2 * T)) / (1 - c3))))
H2 = ((kappa_v - rho * sigma_v * u * 1j + c2) / sigma_v ** 2 *
((1 - np.exp(c2 * T)) / (1 - c3 * np.exp(c2 * T))))
char_func_value = np.exp(H1 + H2 * v0)
return char_func_value
def M76_char_func(u, T, lamb, mu, delta):
''' Valuation of European call option in M76 model via Lewis (2001)
Fourier-based approach: characteristic function.
Parameter definitions see function M76_call_value.'''
omega = -lamb * (np.exp(mu + 0.5 * delta ** 2) - 1)
char_func_value = np.exp((1j * u * omega + lamb *
(np.exp(1j * u * mu - u ** 2 *
delta ** 2 * 0.5) - 1)) * T)
return char_func_value
def M76_char_func_sa(u, T, r, sigma, lamb, mu, delta):
''' Valuation of European call option in M76 model via Lewis (2001)
Fourier-based approach: characteristic function "jump component".
Parameter definitions see function M76_call_value.'''
omega = r - 0.5 * sigma ** 2 - lamb * (np.exp(mu + 0.5 * delta ** 2) - 1)
char_func_value = np.exp((1j * u * omega - 0.5 * u ** 2 * sigma ** 2 +
lamb * (np.exp(1j * u * mu -
u ** 2 * delta ** 2 * 0.5) -
1)) * T)
return char_func_value
if __name__ == '__main__':
#
# Example Parameters CIR85 Model
#
kappa_r, theta_r, sigma_r, r0, T = 0.3, 0.04, 0.1, 0.04, T
B0T = B([kappa_r, theta_r, sigma_r, r0, T]) # discount factor
r = -np.log(B0T) / T
#
# Example Values
#
print("M76 Value %10.4f"
% M76_call_value(S0, K, T, r, v0, lamb, mu, delta))
print("H93 Value %10.4f"
% H93_call_value(S0, K, T, r, kappa_v, theta_v, sigma_v, rho, v0))
print("BCC97 Value %10.4f"
% BCC_call_value(S0, K, T, r, kappa_v, theta_v,
sigma_v, rho, v0, lamb, mu, delta))