I'm trying to create a Trading calendar using Pandas. I'm able to create a cal instance based on the USFederalHolidayCalendar. The USFederalHolidayCalendar is not consistent with the Trading calendar in that the Trading calendar doesn't include Columbus Day and Veteran's Day. However, the Trading calendar includes Good Friday (not included in the USFederalHolidayCalendar). Everything except for the last line in following code works:
from pandas.tseries.holiday import get_calendar, HolidayCalendarFactory, GoodFriday
from datetime import datetime
cal = get_calendar('USFederalHolidayCalendar') # Create calendar instance
cal.rules.pop(7) # Remove Veteran's Day rule
cal.rules.pop(6) # Remove Columbus Day rule
tradingCal = HolidayCalendarFactory('TradingCalendar', cal, GoodFriday)
The tradingCal instance seems to work in that I'm able to view the Holiday rules.
In[10]: tradingCal.rules
Out[10]:
[Holiday: Labor Day (month=9, day=1, offset=<DateOffset: kwds={'weekday': MO(+1)}>),
Holiday: Presidents Day (month=2, day=1, offset=<DateOffset: kwds={'weekday': MO(+3)}>),
Holiday: Good Friday (month=1, day=1, offset=[<Easter>, <-2 * Days>]),
Holiday: Dr. Martin Luther King Jr. (month=1, day=1, offset=<DateOffset: kwds={'weekday': MO(+3)}>),
Holiday: New Years Day (month=1, day=1, observance=<function nearest_workday at 0x000000000A190BA8>),
Holiday: Thanksgiving (month=11, day=1, offset=<DateOffset: kwds={'weekday': TH(+4)}>),
Holiday: July 4th (month=7, day=4, observance=<function nearest_workday at 0x000000000A190BA8>),
Holiday: Christmas (month=12, day=25, observance=<function nearest_workday at 0x000000000A190BA8>),
Holiday: MemorialDay (month=5, day=31, offset=<DateOffset: kwds={'weekday': MO(-1)}>)]
When I try to list the holidays in a date range, I get the following error:
In[11]: tradingCal.holidays(datetime(2014, 12, 31), datetime(2016, 12, 31))
Traceback (most recent call last):
File "C:Python27libsite-packagesIPythoncoreinteractiveshell.py", line 3035, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-12-2708cd2db7a0>", line 1, in <module>
tradingCal.holidays(datetime(2014, 12, 31), datetime(2016, 12, 31))
TypeError: unbound method holidays() must be called with TradingCalendar instance as first argument (got datetime instance instead)
Any ideas?
See Question&Answers more detail:
os