eddelbuettel / rquantlib

R interface to the QuantLib library
119 stars 50 forks source link

SabrSwaption example now fails on current parameters #169

Open eddelbuettel opened 2 years ago

eddelbuettel commented 2 years ago

CRAN emailed me as they noticed that the (old) example in help(SabrSwaption) now fails:

    > setEvaluationDate(as.Date("2016-2-16"))
    [1] TRUE
    > times<-times <- seq(0,14.75,.25)
    >
    > data(tsQuotes)
    > dcurve <- DiscountCurve(params, tsQuotes, times=times,dclegparams)
    Error in discountCurveEngine(params, tsQuotes, times, matchlegs) :
     1st iteration: failed at 1st alive instrument, pillar March 17th, 2016, maturity March 17th, 2016, reference date February 17th, 2016: Missing no-fix1M Actual/360 fixing for February 15th, 2016
    Calls: DiscountCurve -> DiscountCurve.default -> discountCurveEngine
    Execution halted

Moving the date to 2016-02-15 appears to avoid this.

@klin333 as you spent so much time and careful attention on date counters, any other suggestion you may have?

klin333 commented 2 years ago

I couldn't reproduce the error on RQuantLib_0.4.15 and QL 1.16 Windows. However, here's my thoughts of what this might be. TLDR: evaluation date should be 2016-02-15 to begin with.

I don't think the error was due to DayCounters.

This error should be due to an IborIndex ("no-fix") created by the QL::DepositRateHelper (as part of RQuantLib:::discountCurveEngine). Somehow the fixingDays probably got set to 2 days, in which case an IborIndex that settles on 2016-02-17 would want fixing values for 2016-02-15, either via provided real historic fixing, or YieldTermStructure based forecast.

This is where the evaluationDate comes in, if 2016-02-15 is on or after the QuantLib global evaluation date, then QL will use YieldTermStructure to forecast, otherwise it tries to read historic fixings, and crash with this error msg when it realised historic fixings are not provided.

Overall I'm still very confused what happened here. Maybe somehow RQuantLib::setCalendarContext() got called, or maybe this QL commit 0ec47814 had an impact, I don't know because I couldn't reproduce the error with any of these either. But I do not believe day counter changes to RQuantLib was the culprit. https://github.com/lballabio/QuantLib/blob/ce82ebe144b7ed6b2dfe226c1dd2cac497ddb36b/ql/termstructures/yield/ratehelpers.cpp#L290-L303)

https://github.com/lballabio/QuantLib/blob/ce82ebe144b7ed6b2dfe226c1dd2cac497ddb36b/ql/indexes/interestrateindex.cpp#L73-L81

eddelbuettel commented 2 years ago

Yes it is likely something else is going on. This one example has been "brittle". I think I once moved the date to Feb 16.

Otherwise, similar here. It seems to behave (better) with the GH version and a date of Feb 15 so I will just push that for now. I won't have time to dig deeper.