1

I am trying to use QuantLib python to price a basic floating rate bond but met error negative time (-9.94444) given. My logic is like this: first construct forecast curve (which is based on simply the risk free rate 1.5%); then I construct the floating rate bond FRN based on the reference index USDLibor. Then, I print out the cash flows of the FRN. It seems works.

After that, I specify the discounting curve (risk free rate 0.015 and credit spread 0.005) for pricing. But error is generated when I print the NPV, clean price and dirty prices. Can you please help?

My python code is as below:

import QuantLib as ql
from datetime import datetime, timedelta
from pandas import DataFrame

start = ql.Date(15,12,2019)
issue_date = ql.Date(15,12,2019)
maturity = ql.Date(15,12,2022)
settle_date = ql.Date(15,12,2019)
settlement_days = 0

calendar = ql.UnitedStates()

coupons = [0.06]
coupon_freq = ql.Period(ql.Semiannual)
face_value = 100
dateGeneration = ql.DateGeneration.Backward
businessConvention = ql.Following
schedule = ql.Schedule(issue_date, maturity, coupon_freq, calendar, businessConvention, businessConvention, dateGeneration,False)
day_count = ql.Thirty360()
#ql.ActualActual(ql.ActualActual.ISMA)

#construction of forecast curves with index specification

forecast_curve = ql.YieldTermStructureHandle(ql.FlatForward(start,0.015, day_count, ql.Compounded)) #let forecast term structure same as yield ts
index = ql.IborIndex('USD Libor', coupon_freq, settlement_days, ql.USDCurrency(), calendar, businessConvention, False, day_count, forecast_curve)
#index = ql.IborIndex('Euribor', coupon_freq, 2, ql.EURCurrency(), calendar, businessConvention, False, day_count, forecast_curve)

#after constructing discount and forecasting term structure with index specification, construct the FRN
margin = [0.01]
fixing_days = 2
FRN = ql.FloatingRateBond(settlement_days, face_value, schedule, index, day_count, spreads=margin)
dates = [c.date() for c in FRN.cashflows()]
cfs = [c.amount() for c in FRN.cashflows()]
print(DataFrame(zip(dates, cfs), columns=('date', 'amount'))) #works


#discount curve with credit spread
crv = ql.FlatForward(start,0.015, day_count, ql.Compounded)
yts = ql.YieldTermStructureHandle(crv)

spread_handle1 = ql.QuoteHandle(ql.SimpleQuote(0.0050))
ts_spreaded1 = ql.ZeroSpreadedTermStructure(yts, spread_handle1)
discount_ts_handle = ql.YieldTermStructureHandle(ts_spreaded1)

#ENGINE 
FRN_engine = ql.DiscountingBondEngine(discount_ts_handle)
FRN.setPricingEngine(FRN_engine)
print("FRN NPV is", FRN.NPV()) #error: negative time (-9.94444) given
print("FRN clean price is", FRN.cleanPrice())
print("FRN dirty price is", FRN.dirtyPrice())
  • always put full error message (starting at word "Traceback") in question (not comment) as text (not screenshot, not link to external portal). There are other useful information. – furas Aug 06 '21 at 21:26

1 Answers1

0

Make sure that you specify your evaluation date:

ql.Settings.instance().evaluationDate = start

and that you add fixings, where required:

index.addFixing(ql.Date(), rate)
ql.user2511
  • 369
  • 2
  • 12