Wrong logics for Hong Kong Calendar
Bug #1209946 reported by
Henry Wong
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://
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 isHalfBusinessD
To post a comment you must log in.
### Eclipse Workspace Patch 1.0 java/org/ jquantlib/ time/calendars/ HongKongTest. java ======= ======= ======= ======= ======= ======= ======= ======= ==== java/org/ jquantlib/ time/calendars/ HongKongTest. java (revision 0) java/org/ jquantlib/ time/calendars/ HongKongTest. java (revision 0) time.calendars; Assert. assertTrue; util.Date; util.DateFactor y; www.hkex. com.hk/ tradinfo/ tradcal/ cal06.htm www.hkex. com.hk/ tradinfo/ tradcal/ cal07.htm www.hkex. com.hk/ tradinfo/ tradcal/ cal08.htm www.hkex. com.hk/ tradinfo/ tradcal/ cal09.htm www.hkex. com.hk/ tradinfo/ tradcal/ cal10.htm getCalendar( HongKong. Market. HKEx); getFactory( ).getDate( 1, 1, year); binarySearch( days, day) >= 0) { y(d));
#P jquantlib
Index: src/test/
=======
--- src/test/
+++ src/test/
@@ -0,0 +1,201 @@
+package org.jquantlib.
+
+import static org.junit.
+
+import java.util.Arrays;
+
+import org.jquantlib.
+import org.jquantlib.
+import org.junit.Test;
+
+/**
+ * Test base on information from these web pages:
+ * http://
+ * http://
+ * http://
+ * http://
+ * http://
+ *
+ * @author henry
+ *
+ */
+public class HongKongTest {
+
+ private HongKong hk = HongKong.
+
+ private void checkDays(int year, int[][] tradeDays) {
+ Date d = DateFactory.
+
+ int day, month;
+ int[] days;
+ while (d.getYear() == year) {
+ day = d.getDayOfMonth();
+ month = d.getMonth();
+ days = tradeDays[month - 1];
+ if (Arrays.
+ assertTrue("Error for business day: " + day + "-" + month + "-"
+ + year, hk.isBusinessDa
+ } 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...