QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
simpledaycounter.cpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2003 RiskMap srl
5
6 This file is part of QuantLib, a free-software/open-source library
7 for financial quantitative analysts and developers - http://quantlib.org/
8
9 QuantLib is free software: you can redistribute it and/or modify it
10 under the terms of the QuantLib license. You should have received a
11 copy of the license along with this program; if not, please email
12 <quantlib-dev@lists.sf.net>. The license is also available online at
13 <http://quantlib.org/license.shtml>.
14
15 This program is distributed in the hope that it will be useful, but WITHOUT
16 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17 FOR A PARTICULAR PURPOSE. See the license for more details.
18*/
19
20#include <ql/time/daycounters/simpledaycounter.hpp>
21#include <ql/time/daycounters/thirty360.hpp>
22
23namespace QuantLib {
24
25 namespace { DayCounter fallback = Thirty360(Thirty360::BondBasis); }
26
28 const Date& d2) const {
29 return fallback.dayCount(d1,d2);
30 }
31
33 const Date& d2,
34 const Date&,
35 const Date&) const {
36 Day dm1 = d1.dayOfMonth(),
37 dm2 = d2.dayOfMonth();
38
39 if (dm1 == dm2 ||
40 // e.g., Aug 30 -> Feb 28 ?
41 (dm1 > dm2 && Date::isEndOfMonth(d2)) ||
42 // e.g., Feb 28 -> Aug 30 ?
43 (dm1 < dm2 && Date::isEndOfMonth(d1))) {
44
45 return (d2.year()-d1.year()) +
46 (Integer(d2.month())-Integer(d1.month()))/12.0;
47
48 } else {
49 return fallback.yearFraction(d1,d2);
50 }
51 }
52
53}
54
Concrete date class.
Definition: date.hpp:125
Month month() const
Definition: date.cpp:82
Year year() const
Definition: date.cpp:93
Day dayOfMonth() const
Definition: date.hpp:400
static bool isEndOfMonth(const Date &d)
whether a date is the last day of its month
Definition: date.hpp:434
std::int_fast32_t serial_type
serial number type
Definition: date.hpp:128
Date::serial_type dayCount(const Date &d1, const Date &d2) const override
to be overloaded by more complex day counters
Time yearFraction(const Date &d1, const Date &d2, const Date &, const Date &) const override
Integer Day
Day number.
Definition: date.hpp:53
Real Time
continuous quantity with 1-year units
Definition: types.hpp:62
QL_INTEGER Integer
integer number
Definition: types.hpp:35
Definition: any.hpp:35