I am trying to value an FRA in quantlib Python using the below code:

import QuantLib as ql

calendar = ql.UnitedStates()

todaysDate = ql.Date(7, ql.May, 2017)
ql.Settings.instance().evaluationDate = todaysDate

spotDates = [ql.Date(7, 5, 2017)+ql.Period(i*6, ql.Months) for i in range(0, 10)]

spotRates = [4.3291/100]*len(spotDates)

interpolation = ql.Linear()

compounding = ql.Compounded

compoundingFrequency = ql.Annual

spotCurve = ql.ZeroCurve(spotDates, spotRates, ql.Actual360(), calendar,interpolation, compounding, compoundingFrequency)

spotCurveHandle = ql.YieldTermStructureHandle(spotCurve)

indexCurve1 = ql.Euribor6M(spotCurveHandle)

indexCurve1.addFixing(ql.Date(7, 5, 2017) -3,0.9,True)

forward_rates=[spotCurve.zeroRate(x,ql.Actual360(),compounding,compoundingFrequency).rate()for x in spotDates]

fra = ql.ForwardRateAgreement(ql.Date(7, 5, 2017),ql.Date(15,12,2020),ql.Position.Long,0.01,10e6,ql.Euribor6M(spotCurveHandle))

However if I change the valuation date in the function

fra = ql.ForwardRateAgreement(ql.Date(7, 5, 2018),ql.Date(15,12,2020),ql.Position.Long,0.01,10e6,ql.Euribor6M(spotCurveHandle))

It gives me an error:RuntimeError: empty Handle cannot be dereferenced

Can anyone please help me with this error? I would sincerely appreciate.

Thanks in advance!


You are not giving the constructor a discountCurve. The constructor is:

ql.ForwardRateAgreement(valueDate, maturityDate, position, strikeForward, notional, iborIndex, discountCurve=ql.YieldTermStructureHandle())

So you should add a the spotCurveHandle as the last parameter:

fra = ql.ForwardRateAgreement(ql.Date(7, 5, 2018), ql.Date(15,12,2020), ql.Position.Long, 0.01, 10e6,ql.Euribor6M(spotCurveHandle), spotCurveHandle)
| improve this answer | |
  • $\begingroup$ It worked! Thanks a ton :) $\endgroup$ – user47760 Jun 24 at 12:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy