QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
event.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) 2005 Joseph Wang
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/event.hpp>
22#include <ql/patterns/visitor.hpp>
23#include <ql/optional.hpp>
24#include <ql/settings.hpp>
25
26namespace QuantLib {
27
28 bool Event::hasOccurred(const Date& d, // refDate
29 ext::optional<bool> includeRefDate) const {
30 Date refDate =
31 d != Date() ? d : Settings::instance().evaluationDate();
32 bool includeRefDateEvent = includeRefDate ? // NOLINT(readability-implicit-bool-conversion)
33 *includeRefDate :
35 if (includeRefDateEvent)
36 return date() < refDate;
37 else
38 return date() <= refDate;
39 }
40
42 auto* v1 = dynamic_cast<Visitor<Event>*>(&v);
43 if (v1 != nullptr)
44 v1->visit(*this);
45 else
46 QL_FAIL("not an event visitor");
47 }
48
49}
degenerate base class for the Acyclic Visitor pattern
Definition: visitor.hpp:33
Concrete date class.
Definition: date.hpp:125
virtual void accept(AcyclicVisitor &)
Definition: event.cpp:41
virtual Date date() const =0
returns the date at which the event occurs
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
bool & includeReferenceDateEvents()
Definition: settings.hpp:155
DateProxy & evaluationDate()
the date at which pricing is to be performed.
Definition: settings.hpp:147
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