
Some parts of this message have been removed.
Learn more about Nabble's
security policy.
|
I am proposing to modify the South Korea Calender, QuantLib::SouthKorea.
Attached files cantain my proposed modification.
See southkorea.hpp and southkorea.cpp.
There are also testing routines of the modified class,
in southkoreancalendar_test.hpp and southkoreancalendar_test.cpp.
Main diferences of my implementation from the current QuantLib::SouthKorea (version 0.9.0) are as flows:
- added Settlement case, where was KRX case only
- abolished Arbor Day (after 2006) and Constitution Day (after 2008) from public holidays
- added election days for national assembly, presidency and regional election.
- added year-end closing days (KRX only)
I wish quantlib-dev companions chech the proposition.
Regards,
Charles Chongseok Hyun.
(from South Korea) |
Meritz Securities Co. LTD.
Manager/OTC Derivatives Management Team
T. +82-2-6309-4875, C. +82-16-541-5807
25-1, Yoido-dong, Youngdeungpo-ku, Seoul, Korea 150-878 ordeeq@...
/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
Copyright (C) 2004 FIMAT Group
Copyright (C) 2007 StatPro Italia srl
Copyright (C) 2008 Charles Chongseok Hyun (
ordeeq@...)
This file is part of QuantLib, a free-software/open-source library
for financial quantitative analysts and developers -
http://quantlib.org/ QuantLib is free software: you can redistribute it and/or modify it
under the terms of the QuantLib license. You should have received a
copy of the license along with this program; if not, please email
<
quantlib-dev@...>. The license is also available online at
<
http://quantlib.org/license.shtml>.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the license for more details.
*/
/*! \file southkorea.hpp
\brief South Korean calendars
*/
#ifndef quantlib_south_korean_calendar_hpp
#define quantlib_south_korean_calendar_hpp
#include <ql/time/calendar.hpp>
namespace QuantLib {
//! South Korean calendars
/*! Public holidays with definite rules:
<ul>
<li>Saturdays</li>
<li>Sundays</li>
<li>New Year's Day, January 1st</li>
<li>Independence Day, March 1st</li>
<li>Children's Day, May 5th</li>
<li>Memorial Day, June 6th</li>
<li>Liberation Day, August 15th</li>
<li>National Fondation Day, October 3th</li>
<li>Christmas Day, December 25th</li>
</ul>
Other public holidays for which no rule is given
(data available for 2004-2010 only):
<ul>
<li>Lunar New Year: The last day of the previous lunar year, January 1st, 2nd in lunar calendar</li>
<li>Election Days
<ul>
<li>National Assembly: 2004-APR-15, 2008-APR-09</li>
<li>Presidency: 2007-DEC-19</li>
<li>Regional Election: 2006-MAY-31</li>
</ul>
<li>Buddha's birthday, April 8th in lunar calendar</li>
<li>Harvest Moon Day: August 14th, 15th, 16th in lunar calendar</li>
</ul>
<B>Holidays for settlements</B>:
<ul>
<li>All public holidays listed above</li>
<li>Labour Day, May 1st</li>
</ul>
<B>Holidays for the Korea exchange</B>
(data from <
http://www.krx.co.kr> or
<
http://www.dooriworld.com/daishin/holiday/holiday.html>):
<ul>
<li>All public holidays listed above
<li>Labour Day, May 1st</li>
<li>Year-end closing: 2004-DEC-31, 2005-DEC-30, 2006-DEC-29, 2007-DEC-31</li>
</ul>
<B>Important changes!!!</B>:
<ul>
<li>Arbour Day, April 5th: a holiday until 2005, not a holiday after 2005</li>
<li>Constitution Day, July 17th: a holiday until 2007, not a holiday after 2008</li>
</ul>
\ingroup calendars
*/
class SouthKorea : public Calendar {
private:
//! SettlementImpl represents South Korean public holidays.
class SettlementImpl : public Calendar::Impl {
public:
SettlementImpl() : calendarName_("South Korean settlement"){}
virtual std::string name() const { return calendarName_; }
virtual bool isWeekend(Weekday) const;
virtual bool isBusinessDay(const Date&) const;
protected:
//! Constructor
/*! This constructor is for the sake of calling from subclasses.
*/
SettlementImpl(const std::string& calendarName) : calendarName_(calendarName){}
protected:
std::string calendarName_;
};
/*!
KrxImpl inherits SettlementImpl
because all KRX business days are also settlement business days.
*/
class KrxImpl : public SettlementImpl {
public:
KrxImpl() : SettlementImpl(std::string("South Korean settlement")){}
virtual bool isBusinessDay(const Date&) const;
};
public:
enum Market { Settlement, //!< generic settlement calendar
KRX //!< Korea exchange calendar
};
SouthKorea(Market m = Settlement);
};
}
#endif
/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
Copyright (C) 2004 FIMAT Group
Copyright (C) 2007 StatPro Italia srl
Copyright (C) 2008 Charles Chongseok Hyun (
ordeeq@...)
This file is part of QuantLib, a free-software/open-source library
for financial quantitative analysts and developers -
http://quantlib.org/ QuantLib is free software: you can redistribute it and/or modify it
under the terms of the QuantLib license. You should have received a
copy of the license along with this program; if not, please email
<
quantlib-dev@...>. The license is also available online at
<
http://quantlib.org/license.shtml>.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the license for more details.
*/
#include "southkorea.hpp"
#include <ql/errors.hpp>
namespace QuantLib {
SouthKorea::SouthKorea(Market market) {
typedef boost::shared_ptr<Calendar::Impl> t_ptr_cal_impl;
// all calendar instances share the same implementation instance
static t_ptr_cal_impl settlementImpl(new SouthKorea::SettlementImpl);
static t_ptr_cal_impl krxImpl(new SouthKorea::KrxImpl);
switch (market) {
case Settlement:
impl_ = settlementImpl;
break;
case KRX:
impl_ = krxImpl;
break;
default:
QL_FAIL("unknown market");
}
}
bool SouthKorea::SettlementImpl::isWeekend(Weekday w) const {
return w == Saturday || w == Sunday;
}
bool SouthKorea::SettlementImpl::isBusinessDay(const Date& date) const {
Weekday w = date.weekday();
Day d = date.dayOfMonth();
Month m = date.month();
Year y = date.year();
if (isWeekend(w)
// New Year's Day
|| (d == 1 && m == January)
// Independence Day
|| (d == 1 && m == March)
// Labor Day
|| (d == 1 && m == May)
// Children's Day
|| (d == 5 && m == May)
// Memorial Day
|| (d == 6 && m == June)
// Liberation Day
|| (d == 15 && m == August)
// National Foundation Day
|| (d == 3 && m == October)
// Christmas Day
|| (d == 25 && m == December)
// Lunar New Year 2004
|| ((d == 21 || d==22 || d==23 || d==24 || d==26 )
&& m == January && y==2004)
|| ((d == 8 || d==9 || d==10) && m == February && y==2005)
|| ((d==29 || d==30 || d==31 ) && m == January && y==2006)
|| (d==19 && m == February && y==2007)
|| ((6==d || 7==d || 8==d) && February==m && 2008==y)
|| ((25==d || 26==d || 27==d) && January==m && 2009==y)
|| ((13==d || 14==d || 15==d) && February==m && 2010==y)
// Election Day
|| (15==d && April==m && 2004==y) //National Assembly
|| (9==d && April==m && 2008==y)
|| (19==d && December==m && 2007==y) //Presidency
|| (31==d && May==m && 2006==y) //Regional election
// Buddha's birthday
|| (d == 26 && m == May && 2004==y)
|| (d == 15 && m == May && 2005==y)
|| (d == 5 && m == May && 2006==y)
|| (d == 24 && m == May && 2007==y)
|| (12==d && May==m && 2008==y)
|| (2==d && May==m && 2009==y)
|| (21==d && May==m && 2010==y)
// Harvest Moon Day
|| ((d == 27 || d == 28 || d == 29) && m == September && y==2004)
|| ((d == 17 || d == 18 || d == 19) && m == September && y==2005)
|| ((d == 5 || d == 6 || d == 7) && m == October && y==2006)
|| ((d == 24 || d == 25 || d == 26) && m == September && y==2007)
|| ((13==d || 14==d || 15==d) && September==m && 2008==y)
|| ((2==d || 3==d || 4==d) && October==m && 2009==y)
|| ((21==d || 22==d || 23==d) && September==m && 2010==y)
)
return false;
// changes from the South Korean national holiday system
if (
// Arbour Day
(5==d && April==m && y < 2006)
// Constitution Day
|| (17==d && July==m && y < 2008) )
return false;
return true;
}
bool SouthKorea::KrxImpl::isBusinessDay(const Date& date) const {
Weekday w = date.weekday();
Day d = date.dayOfMonth();
Month m = date.month();
Year y = date.year();
// Check settlement business day
if ( !SettlementImpl::isBusinessDay(date) )
return false;
// Year-end closing
if (
(31==d && December==m && 2004==y)
|| (30==d && December==m && 2005==y)
|| (29==d && December==m && 2006==y)
|| (30==d && December==m && 2007==y)
)
return false;
return true;
}
}
/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
Copyright (C) 2008 Charles Chongseok Hyun (
ordeeq@...)
This file is for the purpose of testing QuantLib::SouthKorea,
which has been modified from the class with same name in QuantLib version 0.9.0
by Charles Chongseok Hyun.
Contact the modifier by email with '
ordeeq@...' for more details.
*/
#pragma once
#include <boost/test/unit_test.hpp>
/* remember to document new and/or updated tests in the Doxygen
comment block of the corresponding class */
class CalendarPatchTest {
public:
//! South Korean Settlement calendar
static void testSouthKoreanSettlement();
//! Korea Stock Exchange calendar (
http://www.krx.co.kr)
static void testKoreaStockExchange();
//! Make a bundle of test functions
static boost::unit_test_framework::test_suite* suite();
};
/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
Copyright (C) 2008 Charles Chongseok Hyun (
ordeeq@...)
This file is for the purpose of testing QuantLib::SouthKorea,
which has been modified from the class with same name in QuantLib version 0.9.0
by Charles Chongseok Hyun.
Contact the modifier by email with '
ordeeq@...' for more details.
*/
#include "southkoreancalendar_test.hpp"
#include "southkorea.hpp"
#include <ql/errors.hpp>
#include <fstream>
using namespace QuantLib;
using namespace boost::unit_test_framework;
void CalendarPatchTest::testSouthKoreanSettlement() {
BOOST_MESSAGE("Testing South Korean settlement holiday list...");
std::vector<Date> expectedHol;
expectedHol.push_back(Date(1,January,2004));
expectedHol.push_back(Date(21,January,2004));
expectedHol.push_back(Date(22,January,2004));
expectedHol.push_back(Date(23,January,2004));
expectedHol.push_back(Date(1,March,2004));
expectedHol.push_back(Date(5,April,2004));
expectedHol.push_back(Date(15,April,2004)); //election day
// expectedHol.push_back(Date(1,May,2004)); // Saterday
expectedHol.push_back(Date(5,May,2004));
expectedHol.push_back(Date(26,May,2004));
// expectedHol.push_back(Date(6,June,2004)); // Sunday
// expectedHol.push_back(Date(17,July,2004)); // Saturday
// expectedHol.push_back(Date(15,August,2004)); // Sunday
expectedHol.push_back(Date(27,September,2004));
expectedHol.push_back(Date(28,September,2004));
expectedHol.push_back(Date(29,September,2004));
// expectedHol.push_back(Date(3,October,2004)); // Sunday
// expectedHol.push_back(Date(25,December,2004)); // Saturday
// expectedHol.push_back(Date(1,January,2005)); // Saturday
expectedHol.push_back(Date(8,February,2005));
expectedHol.push_back(Date(9,February,2005));
expectedHol.push_back(Date(10,February,2005));
expectedHol.push_back(Date(1,March,2005));
expectedHol.push_back(Date(5,April,2005));
expectedHol.push_back(Date(5,May,2005));
// expectedHol.push_back(Date(15,May,2005)); // Sunday
expectedHol.push_back(Date(6,June,2005));
// expectedHol.push_back(Date(17,July,2005)); // Sunday
expectedHol.push_back(Date(15,August,2005));
// expectedHol.push_back(Date(17,September,2005)); // Saturday
// expectedHol.push_back(Date(18,September,2005)); // Sunday
expectedHol.push_back(Date(19,September,2005));
expectedHol.push_back(Date(3,October,2005));
// expectedHol.push_back(Date(25,December,2005)); // Sunday
// expectedHol.push_back(Date(1,January,2006)); // Sunday
// expectedHol.push_back(Date(28,January,2006)); // Saturday
// expectedHol.push_back(Date(29,January,2006)); // Sunday
expectedHol.push_back(Date(30,January,2006));
expectedHol.push_back(Date(1,March,2006));
expectedHol.push_back(Date(1,May,2006));
expectedHol.push_back(Date(5,May,2006));
expectedHol.push_back(Date(31,May,2006)); // election
expectedHol.push_back(Date(6,June,2006));
expectedHol.push_back(Date(17,July,2006));
expectedHol.push_back(Date(15,August,2006));
expectedHol.push_back(Date(3,October,2006));
expectedHol.push_back(Date(5,October,2006));
expectedHol.push_back(Date(6,October,2006));
// expectedHol.push_back(Date(7,October,2006)); // Saturday
expectedHol.push_back(Date(25,December,2006));
expectedHol.push_back(Date(1,January,2007));
// expectedHol.push_back(Date(17,February,2007)); // Saturday
// expectedHol.push_back(Date(18,February,2007)); // Sunday
expectedHol.push_back(Date(19,February,2007));
expectedHol.push_back(Date(1,March,2007));
expectedHol.push_back(Date(1,May,2007));
// expectedHol.push_back(Date(5,May,2007)); // Saturday
expectedHol.push_back(Date(24,May,2007));
expectedHol.push_back(Date(6,June,2007));
expectedHol.push_back(Date(17,July,2007));
expectedHol.push_back(Date(15,August,2007));
expectedHol.push_back(Date(24,September,2007));
expectedHol.push_back(Date(25,September,2007));
expectedHol.push_back(Date(26,September,2007));
expectedHol.push_back(Date(3,October,2007));
expectedHol.push_back(Date(19,December,2007)); // election
expectedHol.push_back(Date(25,December,2007));
Calendar c = SouthKorea(SouthKorea::Settlement);
std::vector<Date> hol = Calendar::holidayList(c, Date( 1, January, 2004),
Date(31,December, 2007));
for (Size i=0; i<std::min<Size>(hol.size(), expectedHol.size()); i++) {
if (hol[i]!=expectedHol[i])
BOOST_FAIL("expected holiday was " << expectedHol[i]
<< " while calculated holiday is " << hol[i]);
}
if (hol.size()!=expectedHol.size())
BOOST_FAIL("there were " << expectedHol.size()
<< " expected holidays, while there are " << hol.size()
<< " calculated holidays");
}
void CalendarPatchTest::testKoreaStockExchange() {
BOOST_MESSAGE("Testing New York Stock Exchange holiday list...");
std::vector<Date> expectedHol;
expectedHol.push_back(Date(1,January,2004));
expectedHol.push_back(Date(21,January,2004));
expectedHol.push_back(Date(22,January,2004));
expectedHol.push_back(Date(23,January,2004));
expectedHol.push_back(Date(1,March,2004));
expectedHol.push_back(Date(5,April,2004));
expectedHol.push_back(Date(15,April,2004)); //election day
// expectedHol.push_back(Date(1,May,2004)); // Saterday
expectedHol.push_back(Date(5,May,2004));
expectedHol.push_back(Date(26,May,2004));
// expectedHol.push_back(Date(6,June,2004)); // Sunday
// expectedHol.push_back(Date(17,July,2004)); // Saturday
// expectedHol.push_back(Date(15,August,2004)); // Sunday
expectedHol.push_back(Date(27,September,2004));
expectedHol.push_back(Date(28,September,2004));
expectedHol.push_back(Date(29,September,2004));
// expectedHol.push_back(Date(3,October,2004)); // Sunday
// expectedHol.push_back(Date(25,December,2004)); // Saturday
expectedHol.push_back(Date(31,December,2004));
// expectedHol.push_back(Date(1,January,2005)); // Saturday
expectedHol.push_back(Date(8,February,2005));
expectedHol.push_back(Date(9,February,2005));
expectedHol.push_back(Date(10,February,2005));
expectedHol.push_back(Date(1,March,2005));
expectedHol.push_back(Date(5,April,2005));
expectedHol.push_back(Date(5,May,2005));
// expectedHol.push_back(Date(15,May,2005)); // Sunday
expectedHol.push_back(Date(6,June,2005));
// expectedHol.push_back(Date(17,July,2005)); // Sunday
expectedHol.push_back(Date(15,August,2005));
// expectedHol.push_back(Date(17,September,2005)); // Saturday
// expectedHol.push_back(Date(18,September,2005)); // Sunday
expectedHol.push_back(Date(19,September,2005));
expectedHol.push_back(Date(3,October,2005));
// expectedHol.push_back(Date(25,December,2005)); // Sunday
expectedHol.push_back(Date(30,December,2005));
// expectedHol.push_back(Date(1,January,2006)); // Sunday
// expectedHol.push_back(Date(28,January,2006)); // Saturday
// expectedHol.push_back(Date(29,January,2006)); // Sunday
expectedHol.push_back(Date(30,January,2006));
expectedHol.push_back(Date(1,March,2006));
expectedHol.push_back(Date(1,May,2006));
expectedHol.push_back(Date(5,May,2006));
expectedHol.push_back(Date(31,May,2006)); // election
expectedHol.push_back(Date(6,June,2006));
expectedHol.push_back(Date(17,July,2006));
expectedHol.push_back(Date(15,August,2006));
expectedHol.push_back(Date(3,October,2006));
expectedHol.push_back(Date(5,October,2006));
expectedHol.push_back(Date(6,October,2006));
// expectedHol.push_back(Date(7,October,2006)); // Saturday
expectedHol.push_back(Date(25,December,2006));
expectedHol.push_back(Date(29,December,2006));
expectedHol.push_back(Date(1,January,2007));
// expectedHol.push_back(Date(17,February,2007)); // Saturday
// expectedHol.push_back(Date(18,February,2007)); // Sunday
expectedHol.push_back(Date(19,February,2007));
expectedHol.push_back(Date(1,March,2007));
expectedHol.push_back(Date(1,May,2007));
// expectedHol.push_back(Date(5,May,2007)); // Saturday
expectedHol.push_back(Date(24,May,2007));
expectedHol.push_back(Date(6,June,2007));
expectedHol.push_back(Date(17,July,2007));
expectedHol.push_back(Date(15,August,2007));
expectedHol.push_back(Date(24,September,2007));
expectedHol.push_back(Date(25,September,2007));
expectedHol.push_back(Date(26,September,2007));
expectedHol.push_back(Date(3,October,2007));
expectedHol.push_back(Date(19,December,2007)); // election
expectedHol.push_back(Date(25,December,2007));
expectedHol.push_back(Date(31,December,2007));
Calendar c = SouthKorea(SouthKorea::KRX);
std::vector<Date> hol = Calendar::holidayList(c, Date(1,January,2004),
Date(31,December,2007));
Size i;
for (i=0; i<std::min<Size>(hol.size(), expectedHol.size()); i++) {
if (hol[i]!=expectedHol[i])
BOOST_FAIL("expected holiday was " << expectedHol[i]
<< " while calculated holiday is " << hol[i]);
}
if (hol.size()!=expectedHol.size())
BOOST_FAIL("there were " << expectedHol.size()
<< " expected holidays, while there are " << hol.size()
<< " calculated holidays");
}
test_suite* CalendarPatchTest::suite() {
test_suite* suite = BOOST_TEST_SUITE("South Korean calendar tests");
suite->add(BOOST_TEST_CASE(&CalendarPatchTest::testSouthKoreanSettlement));
suite->add(BOOST_TEST_CASE(&CalendarPatchTest::testKoreaStockExchange));
return suite;
}
-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
Don't miss this year's exciting event. There's still time to save $100.
Use priority code J8TL2D2.
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone_______________________________________________
QuantLib-dev mailing list
QuantLib-dev@...
https://lists.sourceforge.net/lists/listinfo/quantlib-dev