def testChinaIB(self): # China Inter Bank working weekend list in the year 2014 expectedWorkingWeekEnd = [Date(2014, 1, 26), Date(2014, 2, 8), Date(2014, 5, 4), Date(2014, 9, 28), Date(2014, 10, 11), # China Inter Bank working weekend list in the year 2015 Date(2015, 1, 4), Date(2015, 2, 15), Date(2015, 2, 28), Date(2015, 9, 6), Date(2015, 10, 10), # China Inter Bank working weekend list in the year 2016 Date(2016, 2, 6), Date(2016, 2, 14), Date(2016, 6, 12), Date(2016, 9, 18), Date(2016, 10, 8), Date(2016, 10, 9), # China Inter Bank working weekend list in the year 2017 Date(2017, 1, 22), Date(2017, 2, 4), Date(2017, 4, 1), Date(2017, 5, 27), Date(2017, 9, 30)] cal = Calendar('China.IB') for day in expectedWorkingWeekEnd: self.assertEqual(cal.isHoliday(day), False, "{0} is not expected to be a holiday in {1}".format(day, cal)) self.assertEqual(cal.isBizDay(day), True, "{0} is expected to be a working day in {1} ".format(day, cal))
def testChinaSSE(self): # China Shhanghai Securities Exchange holiday list in the year 2014 expectedHol = [Date(2014, 1, 1), Date(2014, 1, 31), Date(2014, 2, 1), Date(2014, 2, 2), Date(2014, 2, 3), Date(2014, 2, 4), Date(2014, 2, 5), Date(2014, 2, 6), Date(2014, 2, 8), Date(2014, 4, 5), Date(2014, 4, 6), Date(2014, 4, 7), Date(2014, 5, 1), Date(2014, 5, 2), Date(2014, 5, 3), Date(2014, 5, 4), Date(2014, 5, 31), Date(2014, 6, 1), Date(2014, 6, 2), Date(2014, 9, 6), Date(2014, 9, 7), Date(2014, 9, 8), Date(2014, 9, 28), Date(2014, 10, 1), Date(2014, 10, 2), Date(2014, 10, 3), Date(2014, 10, 4), Date(2014, 10, 5), Date(2014, 10, 6), Date(2014, 10, 7), Date(2014, 10, 11), # China Shhanghai Securities Exchange holiday list in the year 2015 Date(2015, 1, 1), Date(2015, 1, 2), Date(2015, 1, 3), Date(2015, 1, 4), Date(2015, 2, 15), Date(2015, 2, 18), Date(2015, 2, 19), Date(2015, 2, 20), Date(2015, 2, 21), Date(2015, 2, 22), Date(2015, 2, 23), Date(2015, 2, 24), Date(2015, 2, 28), Date(2015, 4, 5), Date(2015, 4, 6), Date(2015, 5, 1), Date(2015, 5, 2), Date(2015, 5, 3), Date(2015, 6, 20), Date(2015, 6, 21), Date(2015, 6, 22), Date(2015, 9, 3), Date(2015, 9, 4), Date(2015, 9, 27), Date(2015, 10, 1), Date(2015, 10, 2), Date(2015, 10, 3), Date(2015, 10, 4), Date(2015, 10, 5), Date(2015, 10, 6), Date(2015, 10, 7), Date(2015, 10, 10)] cal = Calendar('China.SSE') for day in expectedHol: self.assertEqual(cal.isHoliday(day), True, "{0} is expected to be a holiday in {1}".format(day, cal)) self.assertEqual(cal.isBizDay(day), False, "{0} is expected not to be a working day in {1} ".format(day, cal))
def testNullCalendar(self): cal = Calendar("Null") testDate = Date(2015, 1, 1) self.assertTrue(cal.isBizDay(testDate)) self.assertTrue(not cal.isHoliday(testDate)) self.assertTrue(cal.isWeekEnd(Weekdays.Saturday)) self.assertTrue(cal.isWeekEnd(Weekdays.Sunday)) self.assertTrue(not cal.isWeekEnd(Weekdays.Friday))
def testDatesList(self): fromDate = Date(2014, 1, 31) toDate = Date(2014, 2, 28) sseCal = Calendar('China.SSE') ibCal = Calendar('China.IB') benchmarkHol = [Date(2014, 1, 31), Date(2014, 2, 3), Date(2014, 2, 4), Date(2014, 2, 5), Date(2014, 2, 6)] sseHolList = sseCal.holDatesList(fromDate, toDate, False) self.assertEqual(sseHolList, benchmarkHol) ibHolList = ibCal.holDatesList(fromDate, toDate, False) self.assertEqual(ibHolList, benchmarkHol) sseHolList = sseCal.holDatesList(fromDate, toDate, True) benchmarkHol = [Date(2014, 1, 31), Date(2014, 2, 1), Date(2014, 2, 2), Date(2014, 2, 3), Date(2014, 2, 4), Date(2014, 2, 5), Date(2014, 2, 6), Date(2014, 2, 8), Date(2014, 2, 9), Date(2014, 2, 15), Date(2014, 2, 16), Date(2014, 2, 22), Date(2014, 2, 23)] self.assertEqual(sseHolList, benchmarkHol) ibHolList = ibCal.holDatesList(fromDate, toDate, True) benchmarkHol = [Date(2014, 1, 31), Date(2014, 2, 1), Date(2014, 2, 2), Date(2014, 2, 3), Date(2014, 2, 4), Date(2014, 2, 5), Date(2014, 2, 6), Date(2014, 2, 9), Date(2014, 2, 15), Date(2014, 2, 16), Date(2014, 2, 22), Date(2014, 2, 23)] self.assertEqual(ibHolList, benchmarkHol) sseWorkingDayList = sseCal.bizDatesList(fromDate, toDate) d = fromDate while d <= toDate: if sseCal.isBizDay(d): self.assertTrue(d in sseWorkingDayList and d not in sseHolList) d += 1 ibWorkingDayList = ibCal.bizDatesList(fromDate, toDate) d = fromDate while d <= toDate: if ibCal.isBizDay(d): self.assertTrue(d in ibWorkingDayList and d not in ibHolList) d += 1
def isBizDay(holidayCenter, ref): cal = Calendar(holidayCenter) ref = check_date(ref) return cal.isBizDay(ref)
def isBizDay(holidayCenter, ref): cal = Calendar(holidayCenter) ref = Date.fromDateTime(ref) return cal.isBizDay(ref)
def testChinaSSE(self): # China Shanghai Securities Exchange holiday list in the year 2014 expectedHol = [ Date(2014, 1, 1), Date(2014, 1, 31), Date(2014, 2, 3), Date(2014, 2, 4), Date(2014, 2, 5), Date(2014, 2, 6), Date(2014, 4, 7), Date(2014, 5, 1), Date(2014, 5, 2), Date(2014, 6, 2), Date(2014, 9, 8), Date(2014, 10, 1), Date(2014, 10, 2), Date(2014, 10, 3), Date(2014, 10, 6), Date(2014, 10, 7), # China Shanghai Securities Exchange holiday list in the year 2015 Date(2015, 1, 1), Date(2015, 1, 2), Date(2015, 2, 18), Date(2015, 2, 19), Date(2015, 2, 20), Date(2015, 2, 23), Date(2015, 2, 24), Date(2015, 4, 6), Date(2015, 5, 1), Date(2015, 6, 22), Date(2015, 9, 3), Date(2015, 9, 4), Date(2015, 10, 1), Date(2015, 10, 2), Date(2015, 10, 5), Date(2015, 10, 6), Date(2015, 10, 7), # China Shanghai Securities Exchange holiday list in the year 2016 Date(2016, 1, 1), Date(2016, 2, 8), Date(2016, 2, 9), Date(2016, 2, 10), Date(2016, 2, 11), Date(2016, 2, 12), Date(2016, 4, 4), Date(2016, 5, 2), Date(2016, 6, 9), Date(2016, 6, 10), Date(2016, 9, 15), Date(2016, 9, 16), Date(2016, 10, 3), Date(2016, 10, 4), Date(2016, 10, 5), Date(2016, 10, 6), Date(2016, 10, 7), # China Shanghai Securities Exchange holiday list in the year 2017 Date(2017, 1, 1), Date(2017, 1, 2), Date(2017, 1, 27), Date(2017, 1, 28), Date(2017, 1, 29), Date(2017, 1, 30), Date(2017, 1, 31), Date(2017, 2, 1), Date(2017, 2, 2), Date(2017, 4, 2), Date(2017, 4, 3), Date(2017, 4, 4), Date(2017, 5, 1), Date(2017, 5, 28), Date(2017, 5, 29), Date(2017, 5, 30), Date(2017, 10, 1), Date(2017, 10, 2), Date(2017, 10, 3), Date(2017, 10, 4), Date(2017, 10, 5), Date(2017, 10, 6), Date(2017, 10, 7), Date(2017, 10, 8), # China Shanghai Securities Exchange holiday list in the year 2018 Date(2018, 1, 1), Date(2018, 2, 15), Date(2018, 2, 16), Date(2018, 2, 17), Date(2018, 2, 18), Date(2018, 2, 19), Date(2018, 2, 20), Date(2018, 2, 21), Date(2018, 4, 5), Date(2018, 4, 6), Date(2018, 4, 7), Date(2018, 4, 29), Date(2018, 4, 30), Date(2018, 5, 1), Date(2018, 6, 16), Date(2018, 6, 17), Date(2018, 6, 18), Date(2018, 9, 22), Date(2018, 9, 23), Date(2018, 9, 24), Date(2018, 10, 1), Date(2018, 10, 2), Date(2018, 10, 3), Date(2018, 10, 4), Date(2018, 10, 5), Date(2018, 10, 6), Date(2018, 10, 7), # China Shanghai Securities Exchange holiday list in the year 2019 Date(2019, 1, 1), Date(2019, 2, 4), Date(2019, 2, 5), Date(2019, 2, 6), Date(2019, 2, 7), Date(2019, 2, 8), Date(2019, 4, 5), Date(2019, 5, 1), Date(2019, 5, 2), Date(2019, 5, 3), Date(2019, 6, 7), Date(2019, 9, 13), Date(2019, 10, 1), Date(2019, 10, 2), Date(2019, 10, 3), Date(2019, 10, 4), Date(2019, 10, 5), Date(2019, 10, 6), Date(2019, 10, 7), # China Shanghai Securities Exchange holiday list in the year 2020 Date(2020, 1, 1), Date(2020, 1, 24), Date(2020, 1, 25), Date(2020, 1, 26), Date(2020, 1, 27), Date(2020, 1, 28), Date(2020, 1, 29), Date(2020, 1, 30), Date(2020, 4, 4), Date(2020, 4, 5), Date(2020, 4, 6), Date(2020, 5, 1), Date(2020, 5, 2), Date(2020, 5, 3), Date(2020, 5, 4), Date(2020, 5, 5), Date(2020, 6, 25), Date(2020, 6, 26), Date(2020, 6, 27), Date(2020, 10, 1), Date(2020, 10, 2), Date(2020, 10, 3), Date(2020, 10, 4), Date(2020, 10, 5), Date(2020, 10, 6), Date(2020, 10, 7), Date(2020, 10, 8), ] cal = Calendar('China.SSE') for day in expectedHol: self.assertEqual( cal.isHoliday(day), True, "{0} is expected to be a holiday in {1}".format(day, cal)) self.assertEqual( cal.isBizDay(day), False, "{0} is not expected to be a working day in {1} ".format( day, cal))