Coverage Report

Created: 2026-10-31 06:47

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/quantlib/ql/cashflow.cpp
Line
Count
Source
1
/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3
/*
4
 Copyright (C) 2009 Ferdinando Ametrano
5
 Copyright (C) 2009 StatPro Italia srl
6
7
 This file is part of QuantLib, a free-software/open-source library
8
 for financial quantitative analysts and developers - http://quantlib.org/
9
10
 QuantLib is free software: you can redistribute it and/or modify it
11
 under the terms of the QuantLib license.  You should have received a
12
 copy of the license along with this program; if not, please email
13
 <quantlib-dev@lists.sf.net>. The license is also available online at
14
 <https://www.quantlib.org/license.shtml>.
15
16
 This program is distributed in the hope that it will be useful, but WITHOUT
17
 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18
 FOR A PARTICULAR PURPOSE.  See the license for more details.
19
*/
20
21
#include <ql/cashflow.hpp>
22
#include <ql/settings.hpp>
23
#include <ql/patterns/visitor.hpp>
24
25
namespace QuantLib {
26
27
    bool CashFlow::hasOccurred(const Date& refDate,
28
159k
                               std::optional<bool> includeRefDate) const {
29
30
        // easy and quick handling of most cases
31
159k
        if (refDate != Date()) {
32
159k
            Date cf = date();
33
159k
            if (refDate < cf)
34
159k
                return false;
35
0
            if (cf < refDate)
36
0
                return true;
37
0
        }
38
39
0
        if (refDate == Date() ||
40
0
            refDate == Settings::instance().evaluationDate()) {
41
            // today's date; we override the bool with the one
42
            // specified in the settings (if any)
43
0
            std::optional<bool> includeToday =
44
0
                Settings::instance().includeTodaysCashFlows();
45
0
            if (includeToday.has_value())
46
0
                includeRefDate = includeToday;
47
0
        }
48
0
        return Event::hasOccurred(refDate, includeRefDate);
49
159k
    }
50
51
156k
    bool CashFlow::tradingExCoupon(const Date& refDate) const {
52
53
156k
        Date ecd = exCouponDate();
54
156k
        if (ecd == Date())
55
156k
            return false;
56
57
0
        Date ref =
58
0
            refDate != Date() ? refDate : Settings::instance().evaluationDate();
59
60
0
        return ecd <= ref;
61
156k
    }
62
63
0
    void CashFlow::accept(AcyclicVisitor& v) {
64
0
        auto* v1 = dynamic_cast<Visitor<CashFlow>*>(&v);
65
0
        if (v1 != nullptr)
66
0
            v1->visit(*this);
67
0
        else
68
0
            Event::accept(v);
69
0
    }
70
71
}