/src/quantlib/ql/experimental/commodities/paymentterm.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) 2008 J. Erik Radmall |
5 | | |
6 | | This file is part of QuantLib, a free-software/open-source library |
7 | | for financial quantitative analysts and developers - http://quantlib.org/ |
8 | | |
9 | | QuantLib is free software: you can redistribute it and/or modify it |
10 | | under the terms of the QuantLib license. You should have received a |
11 | | copy of the license along with this program; if not, please email |
12 | | <quantlib-dev@lists.sf.net>. The license is also available online at |
13 | | <http://quantlib.org/license.shtml>. |
14 | | |
15 | | This program is distributed in the hope that it will be useful, but WITHOUT |
16 | | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
17 | | FOR A PARTICULAR PURPOSE. See the license for more details. |
18 | | */ |
19 | | |
20 | | /*! \file paymentterm.hpp |
21 | | \brief Payment term |
22 | | */ |
23 | | |
24 | | #ifndef quantlib_payment_term_hpp |
25 | | #define quantlib_payment_term_hpp |
26 | | |
27 | | #include <ql/time/calendar.hpp> |
28 | | #include <map> |
29 | | #include <utility> |
30 | | |
31 | | namespace QuantLib { |
32 | | |
33 | | class PaymentTerm { |
34 | | public: |
35 | | enum EventType { TradeDate, PricingDate }; |
36 | | |
37 | | PaymentTerm() = default; |
38 | | PaymentTerm(const std::string& name, |
39 | | EventType eventType, |
40 | | Integer offsetDays, |
41 | | const Calendar& calendar); |
42 | | //! \name Inspectors |
43 | | //@{ |
44 | | //! name, e.g, "Pricing end + 5 days" |
45 | | const std::string& name() const; |
46 | | EventType eventType() const; |
47 | | Integer offsetDays() const; |
48 | | const Calendar& calendar() const; |
49 | | |
50 | | bool empty() const; |
51 | | //@} |
52 | | Date getPaymentDate(const Date& date) const; |
53 | | protected: |
54 | | struct Data; |
55 | | ext::shared_ptr<Data> data_; |
56 | | |
57 | | struct Data { |
58 | | std::string name; |
59 | | EventType eventType; |
60 | | Integer offsetDays; |
61 | | Calendar calendar; |
62 | | |
63 | | Data(std::string name, EventType eventType, Integer offsetDays, Calendar calendar); |
64 | | }; |
65 | | |
66 | | static std::map<std::string, ext::shared_ptr<Data> > paymentTerms_; |
67 | | }; |
68 | | |
69 | | /*! \relates PaymentTerm */ |
70 | | bool operator==(const PaymentTerm&, |
71 | | const PaymentTerm&); |
72 | | |
73 | | /*! \relates PaymentTerm */ |
74 | | bool operator!=(const PaymentTerm&, |
75 | | const PaymentTerm&); |
76 | | |
77 | | /*! \relates PaymentTerm */ |
78 | | std::ostream& operator<<(std::ostream&, |
79 | | const PaymentTerm&); |
80 | | |
81 | | |
82 | | inline PaymentTerm::Data::Data(std::string name, |
83 | | PaymentTerm::EventType eventType, |
84 | | Integer offsetDays, |
85 | | Calendar calendar) |
86 | 0 | : name(std::move(name)), eventType(eventType), offsetDays(offsetDays), |
87 | 0 | calendar(std::move(calendar)) {} |
88 | | |
89 | 0 | inline const std::string& PaymentTerm::name() const { |
90 | 0 | return data_->name; |
91 | 0 | } |
92 | | |
93 | 0 | inline PaymentTerm::EventType PaymentTerm::eventType() const { |
94 | 0 | return data_->eventType; |
95 | 0 | } |
96 | | |
97 | 0 | inline Integer PaymentTerm::offsetDays() const { |
98 | 0 | return data_->offsetDays; |
99 | 0 | } |
100 | | |
101 | 0 | inline const Calendar& PaymentTerm::calendar() const { |
102 | 0 | return data_->calendar; |
103 | 0 | } |
104 | | |
105 | 0 | inline Date PaymentTerm::getPaymentDate(const Date& date) const { |
106 | 0 | return data_->calendar.adjust(date + data_->offsetDays); |
107 | 0 | } |
108 | | |
109 | 0 | inline bool PaymentTerm::empty() const { |
110 | 0 | return !data_; |
111 | 0 | } |
112 | | |
113 | 0 | inline bool operator==(const PaymentTerm& c1, const PaymentTerm& c2) { |
114 | 0 | return c1.name() == c2.name(); |
115 | 0 | } |
116 | | |
117 | 0 | inline bool operator!=(const PaymentTerm& c1, const PaymentTerm& c2) { |
118 | 0 | return !(c1 == c2); |
119 | 0 | } |
120 | | |
121 | | } |
122 | | |
123 | | |
124 | | #endif |