|
From: Sumit S. <su...@mo...> - 2020-09-06 20:47:39
|
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
|