|
From: Josh C. <jc...@fa...> - 2024-03-09 00:33:00
|
Dear QL community, Need to price callable zero coupon bond (ZCB) by QuantLib-Python. >From tech document on-line as below. I use ql.CallableZeroCouponBond https://rkapl123.github.io/QLAnnotatedSource/d4/ddb/class_quant_lib_1_1_callable_zero_coupon_bond.html I know the basic application and example about pricing bond object by QL. Below code I'm doing this ZCB testing example. The find out from result is that ql.CallableZeroCouponBond + ql.TreeCallableFixedRateBondEngine This pricing module seems get wrong price. Anyone know how to pricing ZCB by correct BondEngine ? thanks. #************************************************************************************************************************************* *import QuantLib as ql*** ** *calc_date = ql.Date(31,12,2023)*** *ql.Settings.instance().evaluationDate = calc_date*** *day_count = ql.ActualActual(ql.ActualActual.Bond)*** *rate = 0.035*** *ts = ql.FlatForward(calc_date,*** * rate,*** * day_count,*** * ql.Compounded,*** * ql.Semiannual)*** *ts_handle = ql.YieldTermStructureHandle(ts)*** ** *CallSch = ql.CallabilitySchedule()*** *CallSch.append(ql.Callability(ql.BondPrice(104,ql.BondPrice.Clean), ql.Callability.Call, ql.Date(15,1,2016)))*** *CallSch.append(ql.Callability(ql.BondPrice(136.8569,ql.BondPrice.Clean), ql.Callability.Call, ql.Date(15,1,2023)))*** *CallSch.append(ql.Callability(ql.BondPrice(180.0943,ql.BondPrice.Clean), ql.Callability.Call, ql.Date(15,1,2030)))*** *CallSch.append(ql.Callability(ql.BondPrice(236.9919,ql.BondPrice.Clean), ql.Callability.Call, ql.Date(15,1,2037)))*** *CallSch.append(ql.Callability(ql.BondPrice(311.8651,ql.BondPrice.Clean), ql.Callability.Call, ql.Date(15,1,2044)))*** *CallSch.append(ql.Callability(ql.BondPrice(324.3398,ql.BondPrice.Clean), ql.Callability.Call, ql.Date(15,1,2045)))*** ** *ZCBobj= ql.CallableZeroCouponBond(2,3000000,ql.TARGET(),ql.Date(15,1,2045),* * ql.Thirty360(ql.Thirty360.ISDA),ql.Following,324.3398,ql.Date(15,1,2015),CallSch)*** ** *a = 0.03*** *s = 0.12*** *grid_points = 40*** *model = ql.HullWhite(ts_handle, a, s)*** *engine = ql.TreeCallableFixedRateBondEngine(model, grid_points)*** *ZCBobj.setPricingEngine(engine)*** *ZCBobj.cleanPrice()*** *Out[25]: 11.938197755007225*** *ZCBobj.NPV()*** *Out[26]: 358044.0890306983* Best, Josh ----------------- "Talk is cheap. Show me the code." By Linus Torvalds. |