|
From: Ashwani S. <ash...@gm...> - 2021-03-04 01:43:33
|
Looked into archeived messages but couldn't find anything relevant. I am trying to calibrate Hull White model using Goutam's code here <http://gouthamanbalaraman.com/blog/short-interest-rate-model-calibration-quantlib.html> with a tweak that instead of using flatForward term_structure, I am using ql.PiecewiseCubicZero(calc_date, bond_helpers, day_count) calibrated to US Treasuries. I suspect the error has to do with negative rates, but here is the piece of code which throws an error when I try running it swaptions = [] index = ql.USDLibor(ql.Period(3, ql.Months), term_structure) # Read US Swaptions vol data CalibrationData = namedtuple("CalibrationData", "start, length, volatility") data = [CalibrationData(1, 5, 0.1148), CalibrationData(2, 4, 0.1108), CalibrationData(3, 3, 0.1070), CalibrationData(4, 2, 0.1021), CalibrationData(5, 1, 0.1000 )] for d in data: vol_handle = ql.QuoteHandle(ql.SimpleQuote(d.volatility)) helper = ql.SwaptionHelper(ql.Period(d.start, ql.Years), ql.Period(d.length, ql.Years), vol_handle, index, index.tenor(), day_count, day_count, term_structure, ql.Normal, ) helper.setPricingEngine(engine) swaptions.append(helper) optimization_method = ql.LevenbergMarquardt(1.0e-8,1.0e-8,1.0e-8) end_criteria = ql.EndCriteria(10000, 100, 1e-6, 1e-8, 1e-8) model.calibrate(swaptions, optimization_method, end_criteria) ---------------------------------------------------------------------------RuntimeError Traceback (most recent call last)<ipython-input-78-1c3c09dff89b> in <module> 24 model = ql.HullWhite(yield_curve_handle) 25 engine = ql.JamshidianSwaptionEngine(model)---> 26 alpha, sigma = calibrate_hullwhite(yield_curve_handle, engine, model, day_count) 27 28 # Generate HW simulation paths <ipython-input-77-cab060688d5e> in calibrate_hullwhite(term_structure, engine, model, day_count) 32 optimization_method = ql.LevenbergMarquardt(1.0e-8,1.0e-8,1.0e-8) 33 end_criteria = ql.EndCriteria(10000, 100, 1e-6, 1e-8, 1e-8)---> 34 model.calibrate(swaptions, optimization_method, end_criteria) 35 36 return model.params() ~\AppData\Local\anaconda3\lib\site-packages\quantlib-1.21-py3.8-win-amd64.egg\QuantLib\QuantLib.py in calibrate(self, *args) 11289 > 11291 return _QuantLib.CalibratedModel_calibrate(self, *args) 11290 def calibrate(self, *args): 11292 11293 def setParams(self, params): RuntimeError: strike + displacement (-0.0114291 + 0) must be non-negative Any suggestions would be appreciated. Thanks. |