QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
cashflow.cpp
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
25namespace 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 =
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
69 }
70
71}
degenerate base class for the Acyclic Visitor pattern
Definition: visitor.hpp:33
virtual Date exCouponDate() const
returns the date that the cash flow trades exCoupon
Definition: cashflow.hpp:66
Date date() const override=0
Concrete date class.
Definition: date.hpp:125
virtual void accept(AcyclicVisitor &)
Definition: event.cpp:41
virtual bool hasOccurred(const Date &refDate=Date(), ext::optional< bool > includeRefDate=ext::nullopt) const
returns true if an event has already occurred before a date
Definition: event.cpp:28
DateProxy & evaluationDate()
the date at which pricing is to be performed.
Definition: settings.hpp:147
ext::optional< bool > & includeTodaysCashFlows()
Definition: settings.hpp:163
static Settings & instance()
access to the unique instance
Definition: singleton.hpp:104
Visitor for a specific class
Definition: visitor.hpp:40
virtual void visit(T &)=0
Definition: any.hpp:35