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
31namespace 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 : name(std::move(name)), eventType(eventType), offsetDays(offsetDays),
87 calendar(std::move(calendar)) {}
88
89 inline const std::string& PaymentTerm::name() const {
90 return data_->name;
91 }
92
93 inline PaymentTerm::EventType PaymentTerm::eventType() const {
94 return data_->eventType;
95 }
96
97 inline Integer PaymentTerm::offsetDays() const {
98 return data_->offsetDays;
99 }
100
101 inline const Calendar& PaymentTerm::calendar() const {
102 return data_->calendar;
103 }
104
105 inline Date PaymentTerm::getPaymentDate(const Date& date) const {
106 return data_->calendar.adjust(date + data_->offsetDays);
107 }
108
109 inline bool PaymentTerm::empty() const {
110 return !data_;
111 }
112
113 inline bool operator==(const PaymentTerm& c1, const PaymentTerm& c2) {
114 return c1.name() == c2.name();
115 }
116
117 inline bool operator!=(const PaymentTerm& c1, const PaymentTerm& c2) {
118 return !(c1 == c2);
119 }
120
121}
122
123
124#endif
125

source code of quantlib/ql/experimental/commodities/paymentterm.hpp