SABR Model Pricing Engine in Python QuantLib
Sep 04 2020
Ich suche nach einer SABR-Modellpreis-Engine in der Python QuantLib-Einstellung. Ich weiß, dass es in der C ++ - Version existiert, bin mir aber nicht sicher, ob es in Python verfügbar ist. Jeder Vorschlag / Feedback in Bezug auf Python-Quellcode wird sehr geschätzt!. Vielen Dank!
Antworten
5 DavidDuarte Sep 04 2020 at 21:47
Hier ist ein einfaches Beispiel, das nützlich sein könnte. Grundsätzlich Parameter für einen bestimmten Abschnitt finden. Einige der Parameter werden möglicherweise zu Beginn angenommen und nicht kalibriert.
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();