Wrong logics for Hong Kong Calendar

Bug #1209946 reported by Henry Wong
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
JQuantLib
New
Medium
Unassigned

Bug Description

The original author made mistake about how Hong Kong holidays work.
e.g.
- SAT is non trading day but holiday will not be rearranged if it is on SAT
- Ching Ming Festival not necessary 5th April, please check wikipedia http://en.wikipedia.org/wiki/Qingming_Festival

Patch base on 0.1.2 attached, includes:
- test case for all trade days from 2006 to 2010
- remove support before 2006 (since I can't find any information to verify the correctness)
- added isHalfBusinessDay(Date) method as per HKEX announcement

Tags: general
Revision history for this message
Henry Wong (henryxwong) wrote :
Download full text (14.1 KiB)

### Eclipse Workspace Patch 1.0
#P jquantlib
Index: src/test/java/org/jquantlib/time/calendars/HongKongTest.java
===================================================================
--- src/test/java/org/jquantlib/time/calendars/HongKongTest.java (revision 0)
+++ src/test/java/org/jquantlib/time/calendars/HongKongTest.java (revision 0)
@@ -0,0 +1,201 @@
+package org.jquantlib.time.calendars;
+
+import static org.junit.Assert.assertTrue;
+
+import java.util.Arrays;
+
+import org.jquantlib.util.Date;
+import org.jquantlib.util.DateFactory;
+import org.junit.Test;
+
+/**
+ * Test base on information from these web pages:
+ * http://www.hkex.com.hk/tradinfo/tradcal/cal06.htm
+ * http://www.hkex.com.hk/tradinfo/tradcal/cal07.htm
+ * http://www.hkex.com.hk/tradinfo/tradcal/cal08.htm
+ * http://www.hkex.com.hk/tradinfo/tradcal/cal09.htm
+ * http://www.hkex.com.hk/tradinfo/tradcal/cal10.htm
+ *
+ * @author henry
+ *
+ */
+public class HongKongTest {
+
+ private HongKong hk = HongKong.getCalendar(HongKong.Market.HKEx);
+
+ private void checkDays(int year, int[][] tradeDays) {
+ Date d = DateFactory.getFactory().getDate(1, 1, year);
+
+ int day, month;
+ int[] days;
+ while (d.getYear() == year) {
+ day = d.getDayOfMonth();
+ month = d.getMonth();
+ days = tradeDays[month - 1];
+ if (Arrays.binarySearch(days, day) >= 0) {
+ assertTrue("Error for business day: " + day + "-" + month + "-"
+ + year, hk.isBusinessDay(d));
+ } else {
+ assertTrue("Error for holiday " + day + "-" + month + "-"
+ + year, hk.isHoliday(d));
+ }
+
+ d.increment();
+ }
+ }
+
+ @Test
+ public void test2006() {
+ int[][] tradeDays = {
+ { 3, 4, 5, 6, 9, 10, 11, 12, 13, 16, 17, 18, 19, 20, 23, 24,
+ 25, 26, 27 },
+ { 1, 2, 3, 6, 7, 8, 9, 10, 13, 14, 15, 16, 17, 20, 21, 22, 23,
+ 24, 27, 28 },
+ { 1, 2, 3, 6, 7, 8, 9, 10, 13, 14, 15, 16, 17, 20, 21, 22, 23,
+ 24, 27, 28, 29, 30, 31 },
+ { 3, 4, 6, 7, 10, 11, 12, 13, 18, 19, 20, 21, 24, 25, 26, 27,
+ 28 },
+ { 2, 3, 4, 8, 9, 10, 11, 12, 15, 16, 17, 18, 19, 22, 23, 24,
+ 25, 26, 29, 30 },
+ { 1, 2, 5, 6, 7, 8, 9, 12, 13, 14, 15, 16, 19, 20, 21, 22, 23,
+ 26, 27, 28, 29, 30 },
+ { 3, 4, 5, 6, 7, 10, 11, 12, 13, 14, 17, 18, 19, 20, 21, 24,
+ 25, 26, 27, 28, 31 },
+ { 1, 2, 3, 4, 7, 8, 9, 10, 11, 14, 15, 16, 17, 18, 21, 22, 23,
+ 24, 25, 28, 29, 30, 31 },
+ { 1, 4, 5, 6, 7, 8, 11, 12, 13, 14, 15, 18, 19, 20, 21, 22, 25,
+ 26, 27, 28, 29 },
+ { 3, 4, 5, 6, 9, 10, 11, 12, 13, 16, 17, 18, 19, 20, 23, 24,
+ 25, 26, 27, 31 },
+ { 1, 2, 3, 6, 7, 8, 9, 10, 13, 14, 15, 16, 17, 20, 21, 22, 23,
+ 24, 27, 28, 29, 30 },
+ { 1, 4, 5, 6, 7, 8, 11, 12, 13, 14, 15, 18, 19, 20, 21, 22, 27,
+ 28, 29 } };
+
+ checkDays(2006, tradeDays);
+ }
+
+ @Test
+ public void test2007() {
+ int[][] tradeDays = {
+ { 2, 3, 4, 5, 8, 9, 10, 11, 12, 15, 16, 17, 18, 19, 22, 23, 24,
+ 25, 26, 29, 30, 31 },
+ { 1, 2, 5, 6, 7, 8, 9, 12, 13, 14, 15, 16, 21, 22, 23, 26, 27,
+ 28 },
+ { 1, 2, 5, 6, 7, 8, 9, 12, 13, 14, 15, 16, 19, 20, 21, 22, 23,
+ 26, 27, 28, 29, 30 },
+ { 2, 3, 4, 10, 11, 12, 13, 16, 17, 18, 19, 20, 23...

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.