Skip to content

Commit

Permalink
Fixes for a couple of calendars.
Browse files Browse the repository at this point in the history
  • Loading branch information
lballabio committed Aug 10, 2020
1 parent afc6f02 commit 5ed591c
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 10 deletions.
38 changes: 33 additions & 5 deletions ql/time/calendars/romania.cpp
Expand Up @@ -20,17 +20,30 @@
*/

#include <ql/time/calendars/romania.hpp>
#include <ql/errors.hpp>
#include <boost/make_shared.hpp>

namespace QuantLib {

Romania::Romania() {
Romania::Romania(Market market) {
// all calendar instances share the same implementation instance
static ext::shared_ptr<Calendar::Impl> impl(new Romania::Impl);
impl_ = impl;
static ext::shared_ptr<Calendar::Impl> publicImpl =
ext::make_shared<Romania::PublicImpl>();
static ext::shared_ptr<Calendar::Impl> bvbImpl =
ext::make_shared<Romania::BVBImpl>();
switch (market) {
case Public:
impl_ = publicImpl;
break;
case BVB:
impl_ = bvbImpl;
break;
default:
QL_FAIL("unknown market");
}
}


bool Romania::Impl::isBusinessDay(const Date& date) const {
bool Romania::PublicImpl::isBusinessDay(const Date& date) const {
Weekday w = date.weekday();
Day d = date.dayOfMonth(), dd = date.dayOfYear();
Month m = date.month();
Expand Down Expand Up @@ -65,4 +78,19 @@ namespace QuantLib {
return true;
}

bool Romania::BVBImpl::isBusinessDay(const Date& date) const {
if (!PublicImpl::isBusinessDay(date))
return false;
Day d = date.dayOfMonth();
Month m = date.month();
Year y = date.year();
if (// one-off closing days
(d == 24 && m == December && y == 2014) ||
(d == 31 && m == December && y == 2014)
)
return false;
return true;
}

}

17 changes: 14 additions & 3 deletions ql/time/calendars/romania.hpp
Expand Up @@ -50,20 +50,31 @@ namespace QuantLib {
<li>2nd Day of Christmas, December 26th</li>
</ul>
Holidays for the Bucharest stock exchange
(data from <http://www.bvb.ro/Marketplace/TradingCalendar/index.aspx>):
all public holidays, plus a few one-off closing days (2014 only).
\ingroup calendars
*/
class Romania : public Calendar {
private:
class Impl : public Calendar::OrthodoxImpl {
class PublicImpl : public Calendar::OrthodoxImpl {
public:
std::string name() const { return "Romania"; }
bool isBusinessDay(const Date&) const;
};
class BVBImpl : public PublicImpl {
public:
std::string name() const { return "Bucharest stock exchange"; }
bool isBusinessDay(const Date&) const;
};
public:
Romania();
enum Market { Public, //!< Public holidays
BVB //!< Bucharest stock-exchange
};
Romania(Market market = BVB);
};


}


Expand Down
8 changes: 7 additions & 1 deletion ql/time/calendars/russia.cpp
Expand Up @@ -88,7 +88,13 @@ namespace QuantLib {
Year y = date.year();
if (isWeekend(w)
// New Year's holidays
|| (d >= 1 && d <= 8 && m == January)
|| (y <= 2005 && d <= 2 && m == January)
|| (y >= 2005 && d <= 5 && m == January)
// in 2012, the 6th was also a holiday
|| (y == 2012 && d == 6 && m == January)
// Christmas (possibly moved to Monday)
|| ((d == 7 || ((d == 8 || d == 9) && w == Monday)) &&
m == January)
// Defender of the Fatherland Day (possibly moved to Monday)
|| ((d == 23 || ((d == 24 || d == 25) && w == Monday)) &&
m == February)
Expand Down
4 changes: 3 additions & 1 deletion ql/time/calendars/russia.hpp
Expand Up @@ -33,7 +33,9 @@ namespace QuantLib {
<ul>
<li>Saturdays</li>
<li>Sundays</li>
<li>New Year holidays and Christmas, January 1st to 8th</li>
<li>New Year holidays, January 1st to 5th (only 1st and 2nd
until 2005)</li>
<li>Christmas, January 7th (possibly moved to Monday)</li>
<li>Defender of the Fatherland Day, February 23rd (possibly
moved to Monday)</li>
<li>International Women's Day, March 8th (possibly moved to
Expand Down

0 comments on commit 5ed591c

Please sign in to comment.