从Quantlib BachelierSwaption价格中检索Black vol

时间:2019-05-29 14:29:09

标签: python quantlib

我想从Quantlib BachelierSwaptionEngine计算出的掉期价格中检索Black Vol。看起来这可以通过优化程序(例如newton方法)在Quantlib中完成,也可以通过impliedVolatility方法直接完成。 我无法在Quantlib Python中使用Quantlib优化器或impliedVolatility方法。

以下代码显示了我如何在Quantlib中计算掉期价格。从那里,我需要根据代码中计算出的掉期价格检索一个黑色卷

calc_date = ql.Date(29,3,2019)

rate = ql.SimpleQuote(0.01)
rate_handle = ql.QuoteHandle(rate)
dc = ql.Actual365Fixed()
spot_curve = ql.FlatForward(calc_date, rate_handle, dc)

start = 10
length = 10
start_date =  ql.TARGET().advance(calc_date, start, ql.Years)
maturity_date = start_date + ql.Period(length, ql.Years)
fixed_schedule = ql.Schedule(start_date, maturity_date,
                      ql.Period(1, ql.Years), ql.TARGET(), ql.Unadjusted, 
                      ql.Unadjusted,ql.DateGeneration.Forward, False)
floating_schedule = ql.Schedule(start_date, maturity_date,
                        ql.Period(6, ql.Months), ql.TARGET(), 
                        ql.ModifiedFollowing, ql.ModifiedFollowing,
                        ql.DateGeneration.Forward, True)

rate = 1.45 / 100
swap = ql.VanillaSwap(ql.VanillaSwap.Receiver, 10000000,
               fixed_schedule, rate, ql.Thirty360(ql.Thirty360.BondBasis),
               floating_schedule, index6m, 0.0, index6m.dayCounter())

swap.setPricingEngine(ql.DiscountingSwapEngine( 
ql.YieldTermStructureHandle(spot_curve)))


swaption_normal_model = ql.Swaption(swap, 
  ql.EuropeanExercise(swap.startDate()))


normal_vol = ql.SimpleQuote(0.005266)
swaption_normal_model.setPricingEngine
(ql.BachelierSwaptionEngine(ql.YieldTermStructureHandle(spot_curve), 
ql.QuoteHandle(normal_vol)))
swaption_normal_model_value = swaption_normal_model.NPV()

2 个答案:

答案 0 :(得分:1)

我使用牛顿最小化函数从scipy检索隐含的黑色体积,见下文:

return window.btoa(binary);

答案 1 :(得分:0)

QuantLib具有确定隐含波动率的内部功能,您可以求解ShiftedLognormal体积或Normal体积。

这里是一个例子:

yts = ql.YieldTermStructureHandle(spot_curve)
blackVol = swaption_normal_model.impliedVolatility(swaption_normal_model_value, yts, 0.5)

blackEngine = ql.BlackSwaptionEngine(yts, ql.QuoteHandle(ql.SimpleQuote(blackVol)))
swaption_normal_model.setPricingEngine(blackEngine)

print(swaption_normal_model.NPV(), swaption_normal_model_value)

此外,将交换对象命名为swaption_normal_model并不是一个好主意,因为您可以设置不同的定价引擎