|
From: Ashwani S. <ash...@gm...> - 2021-03-04 14:01:22
|
Thanks Alix. I saw another post with similar problem this morning which was useful, here is the link <https://quant.stackexchange.com/questions/59269/quantlib-calibrating-hull-white-one-factor-on-negative-interest-rates> Updated the SwaptionHelper as you suggested (code below) and now it works. helper = ql.SwaptionHelper(ql.Period(d.start, ql.Years), ql.Period(d.length, ql.Years), ql.QuoteHandle(ql.SimpleQuote(d.volatility)), ql.USDLibor(ql.Period(3, ql.Months), term_structure), ql.Period('1Y'), ql.Actual360(), ql.Actual360(), term_structure, ql.BlackCalibrationHelper.RelativePriceError, ql.nullDouble(), 1.0, ql.Normal, 0.0, ) On Thu, Mar 4, 2021 at 6:16 AM Alix Lassauzet <ali...@gm...> wrote: > Hi, > > The constructor of a SwaptionHelper object does not look correct to me. > Take a look on the 3 différents ways to instantiate this class: > > C++ > > https://github.com/lballabio/QuantLib/blob/master/ql/models/shortrate/calibrationhelpers/swaptionhelper.hpp > > Swig > > https://github.com/lballabio/QuantLib-SWIG/blob/master/SWIG/calibrationhelpers.i > > Alix > > > Le jeu. 4 mars 2021 à 02:44, Ashwani Singh <ash...@gm...> a > écrit : > >> 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. >> >> _______________________________________________ >> QuantLib-users mailing list >> Qua...@li... >> https://lists.sourceforge.net/lists/listinfo/quantlib-users >> > |