Tokyo Calendar Equinox patch
Posted by KAWANISHI Tomoya on
URL: http://quantlib.414.s1.nabble.com/Tokyo-Calendar-Equinox-patch-tp2359.html
Hi!
I wrote ql/Calendars/tokyo.cpp fix of equinox.
This patch calculates astronomical equinox date not official equinox
date. But astronomical equinox date is a good estimate of official
equinox date.
====
#include <ql/Calendars/tokyo.hpp>
namespace QuantLib {
namespace Calendars {
bool Tokyo::TokCalendarImpl::isBusinessDay(const Date& date) const {
Weekday w = date.weekday();
Day d = date.dayOfMonth();
Month m = date.month();
Year y = date.year();
const double exact_vernal_equinox_time = 20.69115; // at 2000
const double exact_autumnal_equinox_time = 23.09;
const double diff_per_year = 0.242194;
double moving_amount = (y-2000)*diff_per_year;
int number_of_leap_year = (y-2000)/4+(y-2000)/100-(y-2000)/400;
const int ve = // vernal_equinox_day
int(exact_vernal_equinox_time
+ moving_amount - number_of_leap_year);
const int ae = // autumnal_equinox_day
int(exact_autumnal_equinox_time
+ moving_amount - number_of_leap_year);
if ((w == Saturday || w == Sunday)
// New Year's Day
|| (d == 1 && m == January)
// Bank Holiday
|| (d == 2 && m == January)
// Bank Holiday
|| (d == 3 && m == January)
// Coming of Age Day (2nd Monday in January)
|| (w == Monday && (d >= 8 && d <= 14) && m == January)
// National Foundation Day
|| ((d == 11 || (d == 12 && w == Monday)) && m == February)
// Vernal Equinox
|| ((d == ve || (d == (ve+1) && w == Monday)) && m == March)
// Greenery Day
|| ((d == 29 || (d == 30 && w == Monday)) && m == April)
// Constitution Memorial Day
|| (d == 3 && m == May)
// Holiday for a Nation
|| (d == 4 && m == May)
// Children's Day
|| ((d == 5 || (d == 6 && w == Monday)) && m == May)
// Marine Day
|| ((d == 20 || (d == 21 && w == Monday)) && m == July)
// Respect for the Aged Day
|| ((d == 15 || (d == 16 && w == Monday)) && m == September)
// Autumnal Equinox
|| ((d == ae || (d == (ae+1) && w == Monday)) && m == September)
// Health and Sports Day (2nd Monday in October)
|| (w == Monday && (d >= 8 && d <= 14) && m == October)
// National Culture Day
|| ((d == 3 || (d == 4 && w == Monday)) && m == November)
// Labor Thanksgiving Day
|| ((d == 23 || (d == 24 && w == Monday)) && m == November)
// Emperor's Birthday
|| ((d == 23 || (d == 24 && w == Monday)) && m == December)
// Bank Holiday
|| (d == 31 && m == December))
return false;
return true;
}
}
}