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
27 Date::serial_type SimpleDayCounter::Impl::dayCount(const Date& d1,
28 const Date& d2) const {
29 return fallback.dayCount(d1,d2);
30 }
31
32 Time SimpleDayCounter::Impl::yearFraction(const Date& d1,
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(d: d2)) ||
42 // e.g., Feb 28 -> Aug 30 ?
43 (dm1 < dm2 && Date::isEndOfMonth(d: 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
55

source code of quantlib/ql/time/daycounters/simpledaycounter.cpp