/src/quantlib/ql/instruments/callabilityschedule.hpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | |
3 | | /* |
4 | | Copyright (C) 2005 Joseph Wang |
5 | | Copyright (C) 2005, 2006 Theo Boafo |
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 | | /*! \file callabilityschedule.hpp |
22 | | \brief Schedule of put/call dates |
23 | | */ |
24 | | |
25 | | #ifndef quantlib_callability_schedule_hpp |
26 | | #define quantlib_callability_schedule_hpp |
27 | | |
28 | | #include <ql/event.hpp> |
29 | | #include <ql/instruments/bond.hpp> |
30 | | #include <ql/patterns/visitor.hpp> |
31 | | #include <ql/utilities/null.hpp> |
32 | | #include <ql/shared_ptr.hpp> |
33 | | #include <ql/optional.hpp> |
34 | | #include <vector> |
35 | | |
36 | | namespace QuantLib { |
37 | | |
38 | | //! %instrument callability |
39 | | class Callability : public Event { |
40 | | public: |
41 | | //! type of the callability |
42 | | enum Type { Call, Put }; |
43 | | |
44 | | Callability(const Bond::Price& price, Type type, const Date& date) |
45 | 0 | : price_(price), type_(type), date_(date) {} |
46 | 0 | const Bond::Price& price() const { |
47 | 0 | QL_REQUIRE(price_, "no price given"); |
48 | 0 | return *price_; |
49 | 0 | } |
50 | 0 | Type type() const { return type_; } |
51 | | //! \name Event interface |
52 | | //@{ |
53 | 0 | Date date() const override { return date_; } |
54 | | //@} |
55 | | //! \name Visitability |
56 | | //@{ |
57 | | void accept(AcyclicVisitor&) override; |
58 | | //@} |
59 | | private: |
60 | | ext::optional<Bond::Price> price_; |
61 | | Type type_; |
62 | | Date date_; |
63 | | }; |
64 | | |
65 | 0 | inline void Callability::accept(AcyclicVisitor& v){ |
66 | 0 | auto* v1 = dynamic_cast<Visitor<Callability>*>(&v); |
67 | 0 | if (v1 != nullptr) |
68 | 0 | v1->visit(*this); |
69 | 0 | else |
70 | 0 | Event::accept(v); |
71 | 0 | } |
72 | | |
73 | | typedef std::vector<ext::shared_ptr<Callability> > CallabilitySchedule; |
74 | | |
75 | | } |
76 | | |
77 | | #endif |