|
From: Luigi B. <lui...@gm...> - 2019-10-03 17:12:28
|
It was also updated in the cookbook, so if you log in to your account on Leanpub you can download the uploaded version (for free, of course). You can also opt in to be notified when an update is published. On Tue, Oct 1, 2019, 09:57 Steven Van Haren <sh...@op...> wrote: > Hi Robin, > > You have to use BlackCalibrationHelper. This was renamed a while back. > > Kind regards, > Steven > > Op 1 okt. 2019 om 09:50 heeft Robin Schreur <rob...@ho...> > het volgende geschreven: > > Hi All, > > I want to calibrate the HullWhite model via normal swaption vols (using > Jamshidian swaption model). I found the code below which does this ( > https://github.com/lballabio/QuantLib-SWIG/issues/98) > Unfortunately I get the following error: > > AttributeError: 'function' object has no attribute 'RelativePriceError'. > Looks like ql.Calibrationhelper doesn't have a RelativePriceError > attribute. What can I use instead of > ql.CalibrationHelper.RelativePriceError > > Many thanks! > > Robin > > > > from collections import namedtuple > import QuantLib as ql > > def create_swaption_helpers(data, index, term_structure, engine): > swaptions = [] > fixed_leg_tenor = ql.Period(1, ql.Years) > fixed_leg_daycounter = ql.Actual360() > floating_leg_daycounter = ql.Actual360() > 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, > fixed_leg_tenor, > fixed_leg_daycounter, > floating_leg_daycounter, > term_structure, > ql.CalibrationHelper.RelativePriceError, > ql.nullDouble(), > 1., > ql.Normal, > 0. > ) > helper.setPricingEngine(engine) > swaptions.append(helper) > return swaptions > > > > today = ql.Date(15, ql.February, 2002) > settlement = ql.Date(19, ql.February, 2002) > ql.Settings.instance().evaluationDate = today > term_structure = ql.YieldTermStructureHandle( > ql.FlatForward(settlement, 0.04875825, ql.Actual365Fixed()) > ) > index = ql.Euribor1Y(term_structure) > 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)] > model = ql.HullWhite(term_structure) > engine = ql.JamshidianSwaptionEngine(model) > swaptions = create_swaption_helpers(data, index, term_structure, engine) > > 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) > > a, sigma = model.params() > > _______________________________________________ > QuantLib-users mailing list > Qua...@li... > https://lists.sourceforge.net/lists/listinfo/quantlib-users > > _______________________________________________ > QuantLib-users mailing list > Qua...@li... > https://lists.sourceforge.net/lists/listinfo/quantlib-users > |