Python QuantLib의 SABR 모델 가격 엔진
Sep 04 2020
Python QuantLib 설정에서 SABR 모델 가격 책정 엔진을 찾고 있습니다. C ++ 버전에 존재한다는 것을 알고 있지만 Python에서 사용할 수 있는지 확실하지 않습니다. Python 소스 코드에 대한 제안 / 피드백은 대단히 감사하겠습니다!. 감사!
답변
5 DavidDuarte Sep 04 2020 at 21:47
다음은 유용 할 수있는 간단한 예입니다. 기본적으로 주어진 섹션에 대한 매개 변수를 찾습니다. 일부 매개 변수는 보정되지 않고 시작시 가정 될 수 있습니다.
import QuantLib as ql
import matplotlib.pyplot as plt
import numpy as np
from scipy.optimize import minimize
strikes = [105, 106, 107, 108, 109, 110, 111, 112]
fwd = 120.44
expiryTime = 17/365
marketVols = [0.4164, 0.408, 0.3996, 0.3913, 0.3832, 0.3754, 0.3678, 0.3604]
params = [0.1] * 4
def f(params):
vols = np.array([
ql.sabrVolatility(strike, fwd, expiryTime, *params)
for strike in strikes
])
return ((vols - np.array(marketVols))**2 ).mean() **.5
cons=(
{'type': 'ineq', 'fun': lambda x: 0.99 - x[1]},
{'type': 'ineq', 'fun': lambda x: x[1]},
{'type': 'ineq', 'fun': lambda x: x[3]}
)
result = minimize(f, params, constraints=cons)
new_params = result['x']
newVols = [ql.sabrVolatility(strike, fwd, expiryTime, *new_params) for strike in strikes]
plt.plot(strikes, marketVols, marker='o', label="market")
plt.plot(strikes, newVols, marker='o', label="SABR")
plt.legend();