# 一、Heston模型

1993 年，Heston[5]提出了随机波动率模型，Heston 模型是 Black-Scholes 模型的延伸。其中，波动率(方差的平方根)不再被假定为常数，方差现在遵循一个随机(CIR)过程。

Heston 模型可以对市场中观察到的隐含波动率进行建模。

HESTON 模型是常见的随机波动率模型，模型假设标的资产价格服从布朗运动，并且将波动率看作一个随机过程。假设标的资产的价格S?和方差V?服从如下扩散过程：

Re[x]为被积函数的实部，i 是虚数单位，并且：

# 二、Heston模型定价实现

Heston模型的部分代码：

``````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
``````

``````# H93 Parameters
kappa_v = 1
theta_v = 0.05
sigma_v = 0.2
rho = -0.7
v0 = 0.04
``````
``````S0 = 100
K = 100.0
T = 1
r = 0.05
``````
``````print("H93 Value   %10.4f"
% H93_call_value(S0, K, T, r, kappa_v, theta_v, sigma_v, rho, v0))
``````
``````H93 Value      10.7679
``````

# 三、Heston模型参数校准

``````#H93模型校准
import sys
import math
import numpy as np
import pandas as pd
import matplotlib as mpl
from scipy.optimize import brute, fmin

mpl.rcParams['font.family'] = 'serif'
np.set_printoptions(suppress=True,
formatter={'all': lambda x: '%5.3f' % x})

kappa_r, theta_r, sigma_r = CIR_calibration()

S0 = 4.736
r0 = 0.015
t=0
``````
``````# Option Selection
tol = 0.9  # percent ITM/OTM options
options = data[(np.abs(data['行权价'] - S0) / S0) < tol]
options['交易时间'] = pd.DatetimeIndex(options['交易时间'])
options['到期日'] = pd.DatetimeIndex(options['到期日'])
options
``````
``````%time opt_sv = H93_calibration_full()
``````
``````opt_sv#最优参数
array([18.000, 0.026, 0.978, -0.821, 0.035])
``````

# 四、Heston模型定价分析

``````#参数设置
S0 =data['标的资产价格']  # initial index level
K = 5.25  # strike level
T = data['剩余到期日'] # call option maturity
r = data['无风险利率']/100 # constant short rate
t=0
# H93模型参数
kappa_v = 18
theta_v = 0.026
sigma_v = 0.978
rho =  -0.821
v0 =0.035
``````
``````label=data['收盘价']
# mape
mape=np.mean(np.abs((pred-label)/label))
# rmse
rmse=np.sqrt(np.mean(np.square(pred-label)))
# mae
mae=np.mean(np.abs(pred-label))
#MSE
mse=np.sum((label-pred)**2)/len(pred)
print('Heston模型测试集的mape:',mape,' rmse:',rmse,' mae:',mae,'MSE:',mse)
``````
``````Heston模型测试集的mape: 0.6331192663216758  rmse: 0.06059565311773451  mae: 0.04798357142393848 MSE: 0.0036718331767648087
``````

THE END