Skip to content

Commit

Permalink
Add a couple of rarely used day count conventions.
Browse files Browse the repository at this point in the history
  • Loading branch information
lballabio committed Aug 31, 2020
1 parent a043273 commit 2d40629
Show file tree
Hide file tree
Showing 10 changed files with 189 additions and 2 deletions.
3 changes: 3 additions & 0 deletions QuantLib.vcxproj
Expand Up @@ -1784,13 +1784,15 @@
<ClInclude Include="ql\time\dategenerationrule.hpp" />
<ClInclude Include="ql\time\daycounter.hpp" />
<ClInclude Include="ql\time\daycounters\actual360.hpp" />
<ClInclude Include="ql\time\daycounters\actual364.hpp" />
<ClInclude Include="ql\time\daycounters\actual365fixed.hpp" />
<ClInclude Include="ql\time\daycounters\actualactual.hpp" />
<ClInclude Include="ql\time\daycounters\all.hpp" />
<ClInclude Include="ql\time\daycounters\business252.hpp" />
<ClInclude Include="ql\time\daycounters\one.hpp" />
<ClInclude Include="ql\time\daycounters\simpledaycounter.hpp" />
<ClInclude Include="ql\time\daycounters\thirty360.hpp" />
<ClInclude Include="ql\time\daycounters\thirty365.hpp" />
<ClInclude Include="ql\time\ecb.hpp" />
<ClInclude Include="ql\time\frequency.hpp" />
<ClInclude Include="ql\time\imm.hpp" />
Expand Down Expand Up @@ -2726,6 +2728,7 @@
<ClCompile Include="ql\time\daycounters\business252.cpp" />
<ClCompile Include="ql\time\daycounters\simpledaycounter.cpp" />
<ClCompile Include="ql\time\daycounters\thirty360.cpp" />
<ClCompile Include="ql\time\daycounters\thirty365.cpp" />
<ClCompile Include="ql\time\ecb.cpp" />
<ClCompile Include="ql\time\frequency.cpp" />
<ClCompile Include="ql\time\imm.cpp" />
Expand Down
9 changes: 9 additions & 0 deletions QuantLib.vcxproj.filters
Expand Up @@ -2823,6 +2823,9 @@
<ClInclude Include="ql\time\daycounters\actual360.hpp">
<Filter>time\daycounters</Filter>
</ClInclude>
<ClInclude Include="ql\time\daycounters\actual364.hpp">
<Filter>time\daycounters</Filter>
</ClInclude>
<ClInclude Include="ql\time\daycounters\actual365fixed.hpp">
<Filter>time\daycounters</Filter>
</ClInclude>
Expand All @@ -2844,6 +2847,9 @@
<ClInclude Include="ql\time\daycounters\thirty360.hpp">
<Filter>time\daycounters</Filter>
</ClInclude>
<ClInclude Include="ql\time\daycounters\thirty365.hpp">
<Filter>time\daycounters</Filter>
</ClInclude>
<ClInclude Include="ql\legacy\all.hpp">
<Filter>legacy</Filter>
</ClInclude>
Expand Down Expand Up @@ -5898,6 +5904,9 @@
<ClCompile Include="ql\time\daycounters\thirty360.cpp">
<Filter>time\daycounters</Filter>
</ClCompile>
<ClCompile Include="ql\time\daycounters\thirty365.cpp">
<Filter>time\daycounters</Filter>
</ClCompile>
<ClCompile Include="ql\legacy\libormarketmodels\lfmcovarparam.cpp">
<Filter>legacy\libormarketmodels</Filter>
</ClCompile>
Expand Down
3 changes: 3 additions & 0 deletions ql/CMakeLists.txt
Expand Up @@ -889,6 +889,7 @@ set(QuantLib_SRC
time/daycounters/business252.cpp
time/daycounters/simpledaycounter.cpp
time/daycounters/thirty360.cpp
time/daycounters/thirty365.cpp
time/ecb.cpp
time/frequency.cpp
time/imm.cpp
Expand Down Expand Up @@ -2230,13 +2231,15 @@ set(QuantLib_HDR
time/dategenerationrule.hpp
time/daycounter.hpp
time/daycounters/actual360.hpp
time/daycounters/actual364.hpp
time/daycounters/actual365fixed.hpp
time/daycounters/actualactual.hpp
time/daycounters/all.hpp
time/daycounters/business252.hpp
time/daycounters/one.hpp
time/daycounters/simpledaycounter.hpp
time/daycounters/thirty360.hpp
time/daycounters/thirty365.hpp
time/ecb.hpp
time/frequency.hpp
time/imm.hpp
Expand Down
7 changes: 5 additions & 2 deletions ql/time/daycounters/Makefile.am
Expand Up @@ -5,19 +5,22 @@ this_includedir=${includedir}/${subdir}
this_include_HEADERS = \
all.hpp \
actual360.hpp \
actual364.hpp \
actual365fixed.hpp \
actualactual.hpp \
business252.hpp \
one.hpp \
simpledaycounter.hpp \
thirty360.hpp
thirty360.hpp \
thirty365.hpp

cpp_files = \
actual365fixed.cpp \
actualactual.cpp \
business252.cpp \
simpledaycounter.cpp \
thirty360.cpp
thirty360.cpp \
thirty365.cpp

if UNITY_BUILD

Expand Down
52 changes: 52 additions & 0 deletions ql/time/daycounters/actual364.hpp
@@ -0,0 +1,52 @@
/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */

/*
Copyright (C) 2014 StatPro Italia srl
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@lists.sf.net>. 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 actual364.hpp
\brief Actual/364 day counter
*/

#ifndef quantlib_actual364_day_counter_hpp
#define quantlib_actual364_day_counter_hpp

#include <ql/time/daycounter.hpp>

namespace QuantLib {

//! Actual/364 day count convention
/*! \ingroup daycounters */
class Actual364 : public DayCounter {
private:
class Impl : public DayCounter::Impl {
public:
std::string name() const { return std::string("Actual/364"); }
Time yearFraction(const Date& d1,
const Date& d2,
const Date&,
const Date&) const {
return dayCount(d1,d2)/364.0;
}
};
public:
Actual364()
: DayCounter(ext::shared_ptr<DayCounter::Impl>(new Actual364::Impl)) {}
};

}

#endif
2 changes: 2 additions & 0 deletions ql/time/daycounters/all.hpp
Expand Up @@ -2,10 +2,12 @@
/* Add the files to be included into Makefile.am instead. */

#include <ql/time/daycounters/actual360.hpp>
#include <ql/time/daycounters/actual364.hpp>
#include <ql/time/daycounters/actual365fixed.hpp>
#include <ql/time/daycounters/actualactual.hpp>
#include <ql/time/daycounters/business252.hpp>
#include <ql/time/daycounters/one.hpp>
#include <ql/time/daycounters/simpledaycounter.hpp>
#include <ql/time/daycounters/thirty360.hpp>
#include <ql/time/daycounters/thirty365.hpp>

36 changes: 36 additions & 0 deletions ql/time/daycounters/thirty365.cpp
@@ -0,0 +1,36 @@
/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */

/*
Copyright (C) 2015 StatPro Italia srl
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@lists.sf.net>. 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 <ql/time/daycounters/thirty365.hpp>

namespace QuantLib {

Date::serial_type Thirty365::Impl::dayCount(const Date& d1,
const Date& d2) const {
Day dd1 = d1.dayOfMonth(), dd2 = d2.dayOfMonth();
Integer mm1 = d1.month(), mm2 = d2.month();
Year yy1 = d1.year(), yy2 = d2.year();

return 360*(yy2-yy1) + 30*(mm2-mm1) + (dd2-dd1);
}

Thirty365::Thirty365()
: DayCounter(ext::shared_ptr<DayCounter::Impl>(new Thirty365::Impl)) {}

}
52 changes: 52 additions & 0 deletions ql/time/daycounters/thirty365.hpp
@@ -0,0 +1,52 @@
/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */

/*
Copyright (C) 2015 StatPro Italia srl
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@lists.sf.net>. 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 thirty365.hpp
\brief 30/365 day counters
*/

#ifndef quantlib_thirty_365_day_counter_hpp
#define quantlib_thirty_365_day_counter_hpp

#include <ql/time/daycounter.hpp>

namespace QuantLib {

//! 30/365 day count convention
/*! \ingroup daycounters */
class Thirty365 : public DayCounter {
private:
class Impl : public DayCounter::Impl {
public:
std::string name() const { return std::string("30/365"); }
Date::serial_type dayCount(const Date& d1,
const Date& d2) const;
Time yearFraction(const Date& d1,
const Date& d2,
const Date&,
const Date&) const {
return dayCount(d1,d2)/365.0; }
};
public:
Thirty365();
};

}

#endif
26 changes: 26 additions & 0 deletions test-suite/daycounters.cpp
Expand Up @@ -30,6 +30,7 @@
#include <ql/time/daycounters/simpledaycounter.hpp>
#include <ql/time/daycounters/business252.hpp>
#include <ql/time/daycounters/thirty360.hpp>
#include <ql/time/daycounters/thirty365.hpp>
#include <ql/time/calendars/brazil.hpp>
#include <ql/time/calendars/canada.hpp>
#include <ql/time/calendars/unitedstates.hpp>
Expand Down Expand Up @@ -640,6 +641,30 @@ void DayCounterTest::testBusiness252() {
}
}

void DayCounterTest::testThirty365() {

BOOST_TEST_MESSAGE("Testing 30/365 day counter...");

Date d1(17,June,2011), d2(30,December,2012);
DayCounter dayCounter = Thirty365();

BigInteger days = dayCounter.dayCount(d1,d2);
if (days != 553) {
BOOST_FAIL("from " << d1 << " to " << d2 << ":\n"
<< " calculated: " << days << "\n"
<< " expected: " << 553);
}

Time t = dayCounter.yearFraction(d1,d2);
Time expected = 553/365.0;
if (std::fabs(t-expected) > 1.0e-12) {
BOOST_FAIL("from " << d1 << " to " << d2 << ":\n"
<< std::setprecision(12)
<< " calculated: " << t << "\n"
<< " expected: " << expected);
}
}

void DayCounterTest::testThirty360_BondBasis() {

BOOST_TEST_MESSAGE("Testing thirty/360 day counter (Bond Basis)...");
Expand Down Expand Up @@ -866,6 +891,7 @@ test_suite* DayCounterTest::suite() {
suite->add(QUANTLIB_TEST_CASE(&DayCounterTest::testSimple));
suite->add(QUANTLIB_TEST_CASE(&DayCounterTest::testOne));
suite->add(QUANTLIB_TEST_CASE(&DayCounterTest::testBusiness252));
suite->add(QUANTLIB_TEST_CASE(&DayCounterTest::testThirty365));
suite->add(QUANTLIB_TEST_CASE(&DayCounterTest::testThirty360_BondBasis));
suite->add(QUANTLIB_TEST_CASE(&DayCounterTest::testThirty360_EurobondBasis));
suite->add(QUANTLIB_TEST_CASE(&DayCounterTest::testThirty360_German));
Expand Down
1 change: 1 addition & 0 deletions test-suite/daycounters.hpp
Expand Up @@ -34,6 +34,7 @@ class DayCounterTest {
static void testSimple();
static void testOne();
static void testBusiness252();
static void testThirty365();
static void testThirty360_BondBasis();
static void testThirty360_EurobondBasis();
static void testThirty360_German();
Expand Down

0 comments on commit 2d40629

Please sign in to comment.