QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
currency.hpp
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
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
36 class Currency {
37 public:
39
40
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,
54 const std::string& formatString,
56 const std::set<std::string>& minorUnitCodes = {});
58
60
61 const std::string& name() const;
63 const std::string& code() const;
65 Integer numericCode() const;
67 const std::string& symbol() const;
69 const std::string& fractionSymbol() const;
73 const Rounding& rounding() const;
75
78 std::string format() const;
80
82
83 bool empty() const;
85 const Currency& triangulationCurrency() const;
87 const std::set<std::string>& minorUnitCodes() const;
89 protected:
90 struct Data;
91 ext::shared_ptr<Data> data_;
92 private:
93 void checkNonEmpty() const;
94 };
95
97 std::string name, code;
99 std::string symbol, fractionSymbol;
103 std::string formatString;
104 std::set<std::string> minorUnitCodes;
105
106 Data(std::string name,
107 std::string code,
109 std::string symbol,
110 std::string fractionSymbol,
112 const Rounding& rounding,
113 std::string formatString,
115 std::set<std::string> minorUnitCodes = {});
116 };
117
119 bool operator==(const Currency&,
120 const Currency&);
121
123 bool operator!=(const Currency&,
124 const Currency&);
125
127 std::ostream& operator<<(std::ostream&,
128 const Currency&);
129
130
131 // inline definitions
132
133 inline void Currency::checkNonEmpty() const {
134 QL_REQUIRE(data_, "no currency data provided");
135 }
136
137 inline const std::string& Currency::name() const {
139 return data_->name;
140 }
141
142 inline const std::string& Currency::code() const {
144 return data_->code;
145 }
146
149 return data_->numeric;
150 }
151
152 inline const std::string& Currency::symbol() const {
154 return data_->symbol;
155 }
156
157 inline const std::string& Currency::fractionSymbol() const {
159 return data_->fractionSymbol;
160 }
161
164 return data_->fractionsPerUnit;
165 }
166
167 inline const Rounding& Currency::rounding() const {
169 return data_->rounding;
170 }
171
172 inline std::string Currency::format() const {
174 return data_->formatString;
175 }
176
177 inline bool Currency::empty() const {
178 return !data_;
179 }
180
183 return data_->triangulated;
184 }
185
186 inline const std::set<std::string>& Currency::minorUnitCodes() const {
188 return data_->minorUnitCodes;
189 }
190
191 inline bool operator==(const Currency& c1, const Currency& c2) {
192 return (c1.empty() && c2.empty()) ||
193 (!c1.empty() && !c2.empty() && c1.name() == c2.name());
194 }
195
196 inline bool operator!=(const Currency& c1, const Currency& c2) {
197 return !(c1 == c2);
198 }
199
200}
201
202
203#endif
Currency specification
Definition: currency.hpp:36
const Rounding & rounding() const
rounding convention
Definition: currency.hpp:167
const std::string & code() const
ISO 4217 three-letter code, e.g, "USD".
Definition: currency.hpp:142
const std::string & name() const
currency name, e.g, "U.S. Dollar"
Definition: currency.hpp:137
bool empty() const
is this a usable instance?
Definition: currency.hpp:177
Integer numericCode() const
ISO 4217 numeric code, e.g, "840".
Definition: currency.hpp:147
const std::set< std::string > & minorUnitCodes() const
minor unit codes, e.g. GBp, GBX for GBP
Definition: currency.hpp:186
std::string format() const
output format
Definition: currency.hpp:172
Integer fractionsPerUnit() const
number of fractionary parts in a unit, e.g, 100
Definition: currency.hpp:162
const Currency & triangulationCurrency() const
currency used for triangulated exchange when required
Definition: currency.hpp:181
void checkNonEmpty() const
Definition: currency.hpp:133
ext::shared_ptr< Data > data_
Definition: currency.hpp:91
const std::string & fractionSymbol() const
fraction symbol, e.g, "ยข"
Definition: currency.hpp:157
const std::string & symbol() const
symbol, e.g, "$"
Definition: currency.hpp:152
Currency()=default
default constructor
basic rounding class
Definition: rounding.hpp:35
QL_INTEGER Integer
integer number
Definition: types.hpp:35
Definition: any.hpp:35
bool operator==(const Currency &c1, const Currency &c2)
Definition: currency.hpp:191
std::ostream & operator<<(std::ostream &out, GFunctionFactory::YieldCurveModel type)
bool operator!=(const Currency &c1, const Currency &c2)
Definition: currency.hpp:196
std::string fractionSymbol
Definition: currency.hpp:99
std::string formatString
Definition: currency.hpp:103
std::set< std::string > minorUnitCodes
Definition: currency.hpp:104