| 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 | <http://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 | ext::optional<bool> includeRefDate) const { |
| 29 | |
| 30 | // easy and quick handling of most cases |
| 31 | if (refDate != Date()) { |
| 32 | Date cf = date(); |
| 33 | if (refDate < cf) |
| 34 | return false; |
| 35 | if (cf < refDate) |
| 36 | return true; |
| 37 | } |
| 38 | |
| 39 | if (refDate == Date() || |
| 40 | refDate == Settings::instance().evaluationDate()) { |
| 41 | // today's date; we override the bool with the one |
| 42 | // specified in the settings (if any) |
| 43 | ext::optional<bool> includeToday = |
| 44 | Settings::instance().includeTodaysCashFlows(); |
| 45 | if (includeToday) // NOLINT(readability-implicit-bool-conversion) |
| 46 | includeRefDate = *includeToday; |
| 47 | } |
| 48 | return Event::hasOccurred(refDate, includeRefDate); |
| 49 | } |
| 50 | |
| 51 | bool CashFlow::tradingExCoupon(const Date& refDate) const { |
| 52 | |
| 53 | Date ecd = exCouponDate(); |
| 54 | if (ecd == Date()) |
| 55 | return false; |
| 56 | |
| 57 | Date ref = |
| 58 | refDate != Date() ? refDate : Settings::instance().evaluationDate(); |
| 59 | |
| 60 | return ecd <= ref; |
| 61 | } |
| 62 | |
| 63 | void CashFlow::accept(AcyclicVisitor& v) { |
| 64 | auto* v1 = dynamic_cast<Visitor<CashFlow>*>(&v); |
| 65 | if (v1 != nullptr) |
| 66 | v1->visit(*this); |
| 67 | else |
| 68 | Event::accept(v); |
| 69 | } |
| 70 | |
| 71 | } |
| 72 |
