QuantLib-SWIG
QuantLib-SWIG copied to clipboard
Missing Class Export in R
Setup:
- fresh installation of QuantLib 1.27 + QuantLib-SWIG 1.27
- R 4.2.1
- swig 4.02 (as distributed with - Ubuntu 22.04)
Error (after trying to QuantLib::DiscountCurve
):
Error in getClass(Class, where = topenv(parent.frame())) : “_p_ext__shared_ptrT_InterpolatedDiscountCurveTLogLineart_t” is not a defined class
Sample code for reproducing the bug:
library(QuantLib)
bToday = QuantLib::Date(31, "August", 2022)
QuantLib::Settings_setEvaluationDate(self = QuantLib::Settings_instance(), d = bToday)
print(Settings_instance()$getEvaluationDate())
bufDates = QuantLib::DateVector()
QuantLib::DateVector_append(self = bufDates, x = Date(31, "August", 2022))
QuantLib::DateVector_append(self = bufDates, x = Date(30, "September", 2022))
QuantLib::DateVector_size(self = bufDates)
bCurve = QuantLib::DiscountCurve(dates = bufDates , discounts = c(1.0, 1.0), dayCounter = Actual360())
in discountcurve.i
the necessary export seem to be present:
%template(DiscountCurve) InterpolatedDiscountCurve<LogLinear>;
other functions seem to work correctly.
Thanks for posting! It might take a while before we look at your issue, so don't worry if there seems to be no feedback. We'll get to it.
some additional observations:
- compiling QL for python in the same environment produces a working module when testing these cases
- it seems that in R if a templated class is exported using
%template
of ashared_ptr
we get broken code (see log below for
> bCurve = QuantLib::DiscountCurve(dates = bufDates , discounts = c(1.0, 1.0), dayCounter = Actual360())
Error in getClass(Class, where = topenv(parent.frame())) :
“_p_ext__shared_ptrT_InterpolatedDiscountCurveTLogLineart_t” is not a defined class
> bCurve = QuantLib::MonotonicLogCubicDiscountCurve(dates = bufDates , discounts = c(1.0, 1.0), dayCounter = Actual360())
Error in getClass(Class, where = topenv(parent.frame())) :
“_p_ext__shared_ptrT_InterpolatedDiscountCurveTMonotonicLogCubict_t” is not a defined class
> bCurve = QuantLib::NaturalCubicDiscountCurve__SWIG_1(dates = bufDates , discounts = c(1.0, 1.0), dayCounter = Actual360(), calendar = TARGET())
Error in getClass(Class, where = topenv(parent.frame())) :
“_p_ext__shared_ptrT_InterpolatedDiscountCurveTSplineCubict_t” is not a defined class
> bCurve = QuantLib::ZeroCurve__SWIG_3(dates = bufDates , yields = c(0.01, 0.01), dayCounter = Actual360(), calendar = TARGET())
Error in getClass(Class, where = topenv(parent.frame())) :
“_p_ext__shared_ptrT_InterpolatedZeroCurveTLineart_t” is not a defined class
> bCurve = QuantLib::ForwardCurve__SWIG_1(dates = bufDates, forwards = c(0.01, 0.01), dayCounter = Actual360(), calendar = TARGET())
Error in getClass(Class, where = topenv(parent.frame())) :
“_p_ext__shared_ptrT_InterpolatedForwardCurveTBackwardFlatt_t” is not a defined class
did it ever work in R ?
is this a config problem on QL side or on SWIG side?
opened an issue also on swig side, as it seems it's maybe more related to swig: https://github.com/swig/swig/issues/2372
It does seem more related to swig, but we'll need a self-contained example for them to have a chance at diagnosing the problem. Let me know if I can help with that.
Unfortunately the CI build (see https://github.com/lballabio/QuantLib-SWIG/blob/master/.build/r.build) just tries compiling the R module. It would be great if it also tried running a few examples (e.g. those in R/demo) but I don't know R so I have no idea how to do that. I'm open to suggestions.
Hallo, I guess I managed to replicate the bug in a easy way for the SWIG team, maybe you can "up-vote" the bug :) ?
I can try to stitch together something for the R CI build, but right now I fear it would just keep on failing, because basically any template class does not work. I looked at the code swig produces, it seems some king of weird naming issue, but I'm no swig expert.
Thanks
Hallo, I guess I fixed it in swig with https://github.com/swig/swig/pull/2386
Thanks — let's see what happens.