I figured out that the C++ version of QuantLib offers a function called holidayList in the calendar class.

//! Returns the holidays between two dates
static std::vector<Date> holidayList(const Calendar& calendar,
                                     const Date& from,
                                     const Date& to,
                                     bool includeWeekEnds = false);

I tried to get all holidays between two dates by using this call:

TARGET_calendar = TARGET()
TARGET_calendar.holidayList(TARGET_calendar, Date(1,1,2015), Date(1,1,2016))

AttributeError: 'TARGET' object has no attribute 'holidayList'

Since I am not so familliar with converting C++ to Python, I also tried:

holidayList(TARGET_calendar, Date(1,1,2015), Date(1,1,2016))

NameError: name 'holidayList' is not defined

Can anybody help me out, please?

Thank you very much!


The holidayList() function is not exposed in Python: https://github.com/lballabio/QuantLib-SWIG/blob/master/SWIG/calendars.i

You can submit an issue asking for it to be added, or do it yourself via a pull request or just locally but in this last case you'd have to rebuild the QuantLib Python library, etc.

As a workaround, you can use the isHoliday() function in order to get this list, combined with isWeekend() if you want want to exclude the weekends from the holidays list:

TARGET_calendar = TARGET()
date = Date(1,1,2015)
holiday_list = []
while date < Date(1,1,2016):
    if(TARGET_calendar.isHoliday(date) and not
    date = date + Period(1, Days)
  • $\begingroup$ In case you want to open an issue, the place to do it is github.com/lballabio/QuantLib-SWIG/issues. $\endgroup$ – Luigi Ballabio May 14 '18 at 9:09
  • $\begingroup$ Dear byouness, dear Luigi! Thank you very much for your answers. The workaround warks like a charm. Thanks! Unfortunately I am a beginner in Python and have no idea about C++ so I am not able to integrate the function myself. I have opened an issue here: github.com/lballabio/QuantLib-SWIG/issues/112 $\endgroup$ – Bernd May 14 '18 at 15:36
  • $\begingroup$ Hello @BerndMeyer! Glad that this helped. If it answers your question, please mark it as accepted so that people who have the same question can find it more quickly. Thanks. $\endgroup$ – byouness Jun 5 '18 at 16:12

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.