|
From: Luigi B. <lui...@gm...> - 2020-10-19 08:43:28
|
That's correct - with a floor, we need some kind of volatility model for the rates in order to forecast the coupon amount. You can see an example at < https://quantlib-python-docs.readthedocs.io/en/latest/cashflows.html#blackiborcouponpricer>; in your case, in which you don't build the leg directly, you would use something like ql.setCouponPricer(bond.cashflows(), pricer) instead, but the idea is the same. Luigi On Sat, Sep 19, 2020 at 12:18 AM Arkadiy Naumov <ark...@gm...> wrote: > This isn't based on any research (I didn't actually look at the code to > confirm), but from a naive perspective - once you add a floor, you can no > longer use the discounted cash flows engine to value this bond, since it > has an embedded option. Unless of course there is something built into the > engine just for this case (i.e. it assumes zero volatility or something of > that nature). > > On Sun, Sep 6, 2020 at 4:49 PM Sumit Sengupta <su...@mo...> > wrote: > >> Hi all, >> >> I am trying to price a Floating rate note (as per the quantlib python cookbook). >> >> It seems to fail whenever I put a *floor = [0], * with the error... >> >> Traceback (most recent call last): >> File "C:/Users/sumit/.PyCharm2018.3/config/scratches/scratch_48.py", line 88, in calc_bond_price >> return (bond.cleanPrice() - price)**2 >> File "C:\Users\sumit\Anaconda3\envs\msq-360-plus\lib\site-packages\QuantLib\QuantLib.py", line 16229, in cleanPrice >> return _QuantLib.Bond_cleanPrice(self, *args) >> RuntimeError: pricer not set >> >> Note that it fails when I try to fit a discount margin spread over my discount rate curve >> >> *My code is as below....* >> >> forecast_curve = ql.RelinkableYieldTermStructureHandle() >> discount_curve = ql.RelinkableYieldTermStructureHandle() >> >> term_structure_handle, index = generate_swaps_market_data() >> index.addFixing(ql.Date(16, 7, 2020), 0/100) >> >> forecast_curve.linkTo(ql.ZeroSpreadedTermStructure(term_structure_handle, ql.QuoteHandle(ql.SimpleQuote(0.)))) >> >> issue_date = ql.Date(19, 1, 2001) >> maturity_date = ql.Date(19, 1, 2031) >> >> schedule = ql.Schedule(issue_date, maturity_date,ql.Period(ql.Quarterly), ql.TARGET(), >> ql.Following, ql.Following,ql.DateGeneration.Backward, False) >> >> bond = ql.FloatingRateBond(settlementDays = 2,faceAmount = 100,schedule = schedule, >> index = index,paymentDayCounter = ql.Actual360(), >> paymentConvention = ql.Following, fixingDays = index.fixingDays(),gearings = [], >> spreads = [0.3/10000],caps= [],*floors = [0]*,inArrears = False,redemption = 100.0,issueDate = issue_date >> ) >> >> bond.setPricingEngine(ql.DiscountingBondEngine(discount_curve)) >> >> DM = ql.SimpleQuote(0.0) >> discount_curve.linkTo(ql.ZeroSpreadedTermStructure(forecast_curve,ql.QuoteHandle(DM))) >> >> price=88.466 >> >> def calc_bond_price(param): >> s = param[0] >> DM.setValue(s) >> return (bond.cleanPrice() - price)**2 >> >> x0=0.0003 >> bounds=[[-1000, 1000]] >> res = minimize(calc_bond_price, x0, bounds=bounds) >> print(f"DM:{res.x[0]*10000}") >> >> DM.setValue(res.x[0]) >> print(f"clean price:{bond.cleanPrice()}") >> >> >> -- >> Mosaic Smart Data >> >> mobile +44 (0)7961839363 >> su...@mo... >> 25 Finsbury Circus ▫ EC2M 7EE ▫ London ▫ United Kingdom >> www.mosaicsmartdata.com >> _______________________________________________ >> 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 > |