เครื่องมือกำหนดราคาโมเดล SABR ใน Python QuantLib

Sep 04 2020

ฉันกำลังมองหาเครื่องมือกำหนดราคาโมเดล SABR ในการตั้งค่า Python QuantLib ฉันรู้ว่ามีอยู่ในเวอร์ชัน 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();