|
From: Brian S. <bri...@gm...> - 2021-04-09 23:44:51
|
Hi,
I have below code to price a floating rate bond:
import math
import datetime
mydate = Date(8, 10, 2014)
issueDate = Date(8, August, 2014)
maturityDate = Date(8, August, 2019)
Settings.instance().evaluationDate = mydate
spots = [mydate + Period("6m"), mydate + Period("1y"), mydate +
Period("2y"), mydate + Period("5y")]
spotsdate = [0.002, 0.002, 0.002, 0.002]
curveHandle = YieldTermStructureHandle(ZeroCurve(spots, spotsdate,
Actual360(), TARGET(), Linear(), Compounded, Semiannual))
myindex = Euribor6M(curveHandle)
myindex.addFixing(Date(6, August, 2014), spotsdate[1], True)
bond_schedule = Schedule(issueDate, maturityDate, Period(6, Months),
TARGET(), Following, Following, DateGeneration.Backward, False)
mybond = FloatingRateBond(3, 100, bond_schedule, myindex, Actual360())
mybond.setPricingEngine(DiscountingBondEngine(curveHandle))
mybond.NPV()
When I run this code, I get error as
RuntimeError: negative time (-0.161111) given
In one of the earlier discussions, it was suggested to use some dummy
rate corresponding to pricing date, during the curve construction. But
if I use a dummy rate as 0 then I get different value for bond from
using some other rate. So below 2 choices give me 2 different results
-
spots = [mydate, mydate + Period("6m"), mydate + Period("1y"), mydate
+ Period("2y"), mydate + Period("5y")]
spotsdate = [0.00, 0.002, 0.002, 0.002, 0.002]
and
spots = [mydate, mydate + Period("6m"), mydate + Period("1y"), mydate
+ Period("2y"), mydate + Period("5y")]
spotsdate = [0.002, 0.002, 0.002, 0.002, 0.002]. ### simple backfilling
So I wonder, what is the right way to correct the RuntimeError:
negative time (-0.161111) given?
|