QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
currency.hpp
Go to the documentation of this file.
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2004 Decillion Pty(Ltd)
5 Copyright (C) 2004, 2005, 2006, 2007 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/*! \file currency.hpp
22 \brief Currency specification
23*/
24
25#ifndef quantlib_currency_hpp
26#define quantlib_currency_hpp
27
28#include <ql/math/rounding.hpp>
29#include <ql/errors.hpp>
30#include <iosfwd>
31#include <set>
32
33namespace QuantLib {
34
35 //! %Currency specification
36 class Currency {
37 public:
38 //! \name Constructors
39 //@{
40 //! default constructor
41 /*! Instances built via this constructor have undefined
42 behavior. Such instances can only act as placeholders
43 and must be reassigned to a valid currency before being
44 used.
45 */
46 Currency() = default;
47 Currency(const std::string& name,
48 const std::string& code,
50 const std::string& symbol,
51 const std::string& fractionSymbol,
53 const Rounding& rounding,
55 const std::set<std::string>& minorUnitCodes = {});
56 /*! \deprecated Use the constructor without formatString.
57 Deprecated in version 1.33.
58 */
60 Currency(const std::string& name,
61 const std::string& code,
63 const std::string& symbol,
64 const std::string& fractionSymbol,
66 const Rounding& rounding,
67 const std::string& formatString,
69 const std::set<std::string>& minorUnitCodes = {});
70 //@}
71 //! \name Inspectors
72 //@{
73 //! currency name, e.g, "U.S. Dollar"
74 const std::string& name() const;
75 //! ISO 4217 three-letter code, e.g, "USD"
76 const std::string& code() const;
77 //! ISO 4217 numeric code, e.g, "840"
78 Integer numericCode() const;
79 //! symbol, e.g, "$"
80 const std::string& symbol() const;
81 //! fraction symbol, e.g, "¢"
82 const std::string& fractionSymbol() const;
83 //! number of fractionary parts in a unit, e.g, 100
85 //! rounding convention
86 const Rounding& rounding() const;
87 //! output format
88 /*! The format will be fed three positional parameters,
89 namely, value, code, and symbol, in this order.
90 */
91 /*! \deprecated Copy the formatting into your project if you need it.
92 Deprecated in version 1.33.
93 */
94 [[deprecated("Copy the formatting into your project if you need it.")]]
95 std::string format() const;
96 //@}
97 //! \name Other information
98 //@{
99 //! is this a usable instance?
100 bool empty() const;
101 //! currency used for triangulated exchange when required
102 const Currency& triangulationCurrency() const;
103 //! minor unit codes, e.g. GBp, GBX for GBP
104 const std::set<std::string>& minorUnitCodes() const;
105 //@}
106 protected:
107 struct Data;
108 ext::shared_ptr<Data> data_;
109 private:
110 void checkNonEmpty() const;
111 };
112
114
116 std::string name, code;
118 std::string symbol, fractionSymbol;
123 std::string formatString;
124 std::set<std::string> minorUnitCodes;
125
126 /*! \deprecated Use the constructor without formatString.
127 Deprecated in version 1.33.
128 */
130 Data(std::string name,
131 std::string code,
133 std::string symbol,
134 std::string fractionSymbol,
136 const Rounding& rounding,
138 std::set<std::string> minorUnitCodes = {});
139
140 Data(std::string name,
141 std::string code,
143 std::string symbol,
144 std::string fractionSymbol,
146 const Rounding& rounding,
147 std::string formatString,
149 std::set<std::string> minorUnitCodes = {});
150 };
151
153
154 /*! \relates Currency */
155 bool operator==(const Currency&,
156 const Currency&);
157
158 /*! \relates Currency */
159 bool operator!=(const Currency&,
160 const Currency&);
161
162 /*! \relates Currency */
163 std::ostream& operator<<(std::ostream&,
164 const Currency&);
165
166
167 // inline definitions
168
169 inline void Currency::checkNonEmpty() const {
170 QL_REQUIRE(data_, "no currency data provided");
171 }
172
173 inline const std::string& Currency::name() const {
175 return data_->name;
176 }
177
178 inline const std::string& Currency::code() const {
180 return data_->code;
181 }
182
185 return data_->numeric;
186 }
187
188 inline const std::string& Currency::symbol() const {
190 return data_->symbol;
191 }
192
193 inline const std::string& Currency::fractionSymbol() const {
195 return data_->fractionSymbol;
196 }
197
200 return data_->fractionsPerUnit;
201 }
202
203 inline const Rounding& Currency::rounding() const {
205 return data_->rounding;
206 }
207
209
210 inline std::string Currency::format() const {
212 return data_->formatString;
213 }
214
216
217 inline bool Currency::empty() const {
218 return !data_;
219 }
220
223 return data_->triangulated;
224 }
225
226 inline const std::set<std::string>& Currency::minorUnitCodes() const {
228 return data_->minorUnitCodes;
229 }
230
231 inline bool operator==(const Currency& c1, const Currency& c2) {
232 return (c1.empty() && c2.empty()) ||
233 (!c1.empty() && !c2.empty() && c1.name() == c2.name());
234 }
235
236 inline bool operator!=(const Currency& c1, const Currency& c2) {
237 return !(c1 == c2);
238 }
239
240}
241
242
243#endif
Currency specification
Definition: currency.hpp:36
const Rounding & rounding() const
rounding convention
Definition: currency.hpp:203
const std::string & code() const
ISO 4217 three-letter code, e.g, "USD".
Definition: currency.hpp:178
const std::string & name() const
currency name, e.g, "U.S. Dollar"
Definition: currency.hpp:173
bool empty() const
is this a usable instance?
Definition: currency.hpp:217
Integer numericCode() const
ISO 4217 numeric code, e.g, "840".
Definition: currency.hpp:183
const std::set< std::string > & minorUnitCodes() const
minor unit codes, e.g. GBp, GBX for GBP
Definition: currency.hpp:226
Integer fractionsPerUnit() const
number of fractionary parts in a unit, e.g, 100
Definition: currency.hpp:198
std::string format() const
output format
Definition: currency.hpp:210
const Currency & triangulationCurrency() const
currency used for triangulated exchange when required
Definition: currency.hpp:221
void checkNonEmpty() const
Definition: currency.hpp:169
ext::shared_ptr< Data > data_
Definition: currency.hpp:108
const std::string & fractionSymbol() const
fraction symbol, e.g, "¢"
Definition: currency.hpp:193
const std::string & symbol() const
symbol, e.g, "$"
Definition: currency.hpp:188
Currency()=default
default constructor
basic rounding class
Definition: rounding.hpp:35
Classes and functions for error handling.
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
Definition: errors.hpp:117
QL_INTEGER Integer
integer number
Definition: types.hpp:35
Definition: any.hpp:35
bool operator==(const Currency &c1, const Currency &c2)
Definition: currency.hpp:231
std::ostream & operator<<(std::ostream &out, GFunctionFactory::YieldCurveModel type)
bool operator!=(const Currency &c1, const Currency &c2)
Definition: currency.hpp:236
#define QL_DEPRECATED
Definition: qldefines.hpp:215
#define QL_DEPRECATED_DISABLE_WARNING
Definition: qldefines.hpp:216
#define QL_DEPRECATED_ENABLE_WARNING
Definition: qldefines.hpp:217
Rounding implementation.
std::string fractionSymbol
Definition: currency.hpp:118
QL_DEPRECATED std::string formatString
Definition: currency.hpp:123
std::set< std::string > minorUnitCodes
Definition: currency.hpp:124