我想从Quantlib BachelierSwaptionEngine计算出的掉期价格中检索Black Vol。看起来可以通过优化器(例如newton方法)在Quantlib中完成此操作,也可以通过implicedVolatility方法直接进行此操作。
我无法在Quantlib Python中使用Quantlib优化器或impliedVolatility方法。
下面的代码显示了我如何在Quantlib中计算掉期价格。从那里,我需要根据代码中计算出的掉期价格检索Black vol
import Quantlib as ql
from scipy import optimize
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)
index6m = ql.Euribor6M(ql.YieldTermStructureHandle(spot_curve))
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()
最佳答案
我从scipy中使用了牛顿最小化函数来检索隐含的黑色体积,请参见下文:
swaption_black_model = ql.Swaption(swap, ql.EuropeanExercise(swap.startDate()))
initial_vol_guess = 0.60
def find_implied_black(vol):
black_vol = ql.SimpleQuote(vol)
swaption_black_model.setPricingEngine(
ql.BlackSwaptionEngine(ql.YieldTermStructureHandle(spot_curve),
ql.QuoteHandle(black_vol)))
swaption_black_model_value = swaption_black_model.NPV()
diff = swaption_normal_model_value - swaption_black_model_value
return diff
implied_black_vol = optimize.newton(find_implied_black, initial_vol_guess)
implied_black_vol = ql.SimpleQuote(implied_black_vol)
swaption_black_model.setPricingEngine(
ql.BlackSwaptionEngine(ql.YieldTermStructureHandle(spot_curve),
ql.QuoteHandle(implied_black_vol)))
swaption_black_model_value = swaption_black_model.NPV()
print('Normal swaption price is {}'.format(swaption_normal_model_value))
print('Black swaption price is {}'.format(swaption_black_model_value))
关于python - 从Quantlib BachelierSwaption价格中检索Black vol,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/56362943/