5
$\begingroup$

I'm reading Introduction to Selected Classes of the QuantLib Library I by Dimitri Reiswich and am trying to "convert" it to Python.

It seems to me that some C++ possibilities aren't available in python.

I'm not familiar with SWIG but I guess it's a matter of declaring them in the appropriate *.i files.

For instance both these work following the pdf text:

January: either QuantLib::January or QuantLib::Jan

print(ql.Date(12, 12, 2015))
print(ql.Date(12, ql.January, 2015))

But why Jan doesn't work ?

print(ql.Date(12, ql.Jan, 2015))

In the Calendar description the 2 following commented lines return an error, browsing through the code I failed at finding them. Would someone be kind enough to point me directions on how to make them available ?

import QuantLib as ql


def calendarTesting():
    frankfurtCal = ql.Germany(ql.Germany.FrankfurtStockExchange)
    saudiArabCal = ql.SaudiArabia()
    myEve = ql.Date(31, 12, 2009)
    print('is BD: {}'.format(frankfurtCal.isBusinessDay(myEve)))
    print('is Holiday: {}'.format(frankfurtCal.isHoliday(myEve)))
    # print('is weekend: {}'.format(saudiArabCal.isWeekend(ql.Saturday)))
    print('is last BD: {}'.format(frankfurtCal.isEndOfMonth(ql.Date(30, 12, 2009))))
    # print('last BD: {}'.format(frankfurtCal.endOfMonth(myEve)))


calendarTesting()
$\endgroup$
3
$\begingroup$

Yes, lots of methods are still missing in the Python wrappers (the two in your question are now available, though). That's because the declarations in the SWIG interfaces must be kept in sync with the C++ library manually; we make sure that they don't break as the library evolves, but other than that, the time we can give to this is limited and new stuff is only being added when someone needs it and does the work.

In case you want to give it a try, you can have a look at http://www.implementingquantlib.com/2016/09/quantlib-and-swig.html. It explains the reasons for some of the quirks of the wrappers, and hopefully will give you some general directions.

$\endgroup$
0
$\begingroup$

I'm not sure how you built the python bindings but looking at the swig code here:

https://github.com/lballabio/quantlib/blob/master/QuantLib-SWIG/SWIG/calendars.i#L63

it doesn't look like there are any specific declarations ie..

#if defined(SWIGPYTHON) 

that would preclude those methods. Having said that, I don't see those methods listed in the swig definition at all which indicates you'll need to add them yourself you want to call them.

$\endgroup$

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.