QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.38
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 //@}
57 //! \name Inspectors
58 //@{
59 //! currency name, e.g, "U.S. Dollar"
60 const std::string& name() const;
61 //! ISO 4217 three-letter code, e.g, "USD"
62 const std::string& code() const;
63 //! ISO 4217 numeric code, e.g, "840"
64 Integer numericCode() const;
65 //! symbol, e.g, "$"
66 const std::string& symbol() const;
67 //! fraction symbol, e.g, "¢"
68 const std::string& fractionSymbol() const;
69 //! number of fractionary parts in a unit, e.g, 100
71 //! rounding convention
72 const Rounding& rounding() const;
73 //@}
74 //! \name Other information
75 //@{
76 //! is this a usable instance?
77 bool empty() const;
78 //! currency used for triangulated exchange when required
79 const Currency& triangulationCurrency() const;
80 //! minor unit codes, e.g. GBp, GBX for GBP
81 const std::set<std::string>& minorUnitCodes() const;
82 //@}
83 protected:
84 struct Data;
85 ext::shared_ptr<Data> data_;
86 private:
87 void checkNonEmpty() const;
88 };
89
91 std::string name, code;
93 std::string symbol, fractionSymbol;
97 std::set<std::string> minorUnitCodes;
98
99 Data(std::string name,
100 std::string code,
102 std::string symbol,
103 std::string fractionSymbol,
105 const Rounding& rounding,
107 std::set<std::string> minorUnitCodes = {});
108 };
109
110
111 /*! \relates Currency */
112 bool operator==(const Currency&,
113 const Currency&);
114
115 /*! \relates Currency */
116 bool operator!=(const Currency&,
117 const Currency&);
118
119 /*! \relates Currency */
120 std::ostream& operator<<(std::ostream&,
121 const Currency&);
122
123
124 // inline definitions
125
126 inline void Currency::checkNonEmpty() const {
127 QL_REQUIRE(data_, "no currency data provided");
128 }
129
130 inline const std::string& Currency::name() const {
132 return data_->name;
133 }
134
135 inline const std::string& Currency::code() const {
137 return data_->code;
138 }
139
142 return data_->numeric;
143 }
144
145 inline const std::string& Currency::symbol() const {
147 return data_->symbol;
148 }
149
150 inline const std::string& Currency::fractionSymbol() const {
152 return data_->fractionSymbol;
153 }
154
157 return data_->fractionsPerUnit;
158 }
159
160 inline const Rounding& Currency::rounding() const {
162 return data_->rounding;
163 }
164
165 inline bool Currency::empty() const {
166 return !data_;
167 }
168
171 return data_->triangulated;
172 }
173
174 inline const std::set<std::string>& Currency::minorUnitCodes() const {
176 return data_->minorUnitCodes;
177 }
178
179 inline bool operator==(const Currency& c1, const Currency& c2) {
180 return (c1.empty() && c2.empty()) ||
181 (!c1.empty() && !c2.empty() && c1.name() == c2.name());
182 }
183
184 inline bool operator!=(const Currency& c1, const Currency& c2) {
185 return !(c1 == c2);
186 }
187
188}
189
190
191#endif
Currency specification
Definition: currency.hpp:36
const Rounding & rounding() const
rounding convention
Definition: currency.hpp:160
const std::string & code() const
ISO 4217 three-letter code, e.g, "USD".
Definition: currency.hpp:135
const std::string & name() const
currency name, e.g, "U.S. Dollar"
Definition: currency.hpp:130
bool empty() const
is this a usable instance?
Definition: currency.hpp:165
Integer numericCode() const
ISO 4217 numeric code, e.g, "840".
Definition: currency.hpp:140
const std::set< std::string > & minorUnitCodes() const
minor unit codes, e.g. GBp, GBX for GBP
Definition: currency.hpp:174
Integer fractionsPerUnit() const
number of fractionary parts in a unit, e.g, 100
Definition: currency.hpp:155
const Currency & triangulationCurrency() const
currency used for triangulated exchange when required
Definition: currency.hpp:169
void checkNonEmpty() const
Definition: currency.hpp:126
ext::shared_ptr< Data > data_
Definition: currency.hpp:85
const std::string & fractionSymbol() const
fraction symbol, e.g, "¢"
Definition: currency.hpp:150
const std::string & symbol() const
symbol, e.g, "$"
Definition: currency.hpp:145
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:37
bool operator==(const Currency &c1, const Currency &c2)
Definition: currency.hpp:179
std::ostream & operator<<(std::ostream &out, GFunctionFactory::YieldCurveModel type)
bool operator!=(const Currency &c1, const Currency &c2)
Definition: currency.hpp:184
Rounding implementation.
std::string fractionSymbol
Definition: currency.hpp:93
std::set< std::string > minorUnitCodes
Definition: currency.hpp:97