Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
Public Member Functions | Private Member Functions | Private Attributes | List of all members
CurrencyParser Class Reference

#include <ored/utilities/currencyparser.hpp>

+ Inheritance diagram for CurrencyParser:
+ Collaboration diagram for CurrencyParser:

Public Member Functions

 CurrencyParser ()
 
QuantLib::Currency parseCurrency (const std::string &name) const
 
QuantLib::Currency parseMinorCurrency (const std::string &name) const
 
QuantLib::Currency parseCurrencyWithMinors (const std::string &name) const
 
std::pair< QuantLib::Currency, QuantLib::Currency > parseCurrencyPair (const std::string &name, const std::string &delimiters) const
 
void addCurrency (const std::string &newName, const QuantLib::Currency &currency)
 
void addMetal (const std::string &newName, const QuantLib::Currency &currency)
 
void addCrypto (const std::string &newName, const QuantLib::Currency &currency)
 
bool isValidCurrency (const std::string &name) const
 
bool isMinorCurrency (const std::string &name) const
 
bool isPseudoCurrency (const std::string &name) const
 
bool isPreciousMetal (const std::string &name) const
 
bool isCryptoCurrency (const std::string &name) const
 
bool hasMinorCurrency (const std::string &name) const
 
std::string getMinorCurrency (const std::string &name) const
 
std::set< std::string > pseudoCurrencyCodes () const
 
QuantLib::Real convertMinorToMajorCurrency (const std::string &s, QuantLib::Real value)
 
void reset ()
 

Private Member Functions

void addMinorCurrencyCodes (const QuantLib::Currency &currency)
 

Private Attributes

boost::shared_mutex mutex_
 
std::map< std::string, QuantLib::Currency > currencies_
 
std::map< std::string, QuantLib::Currency > minorCurrencies_
 
std::map< std::string, QuantLib::Currency > preciousMetals_
 
std::map< std::string, QuantLib::Currency > cryptoCurrencies_
 

Detailed Description

Definition at line 36 of file currencyparser.hpp.

Constructor & Destructor Documentation

◆ CurrencyParser()

Definition at line 43 of file currencyparser.cpp.

+ Here is the call graph for this function:

Member Function Documentation

◆ parseCurrency()

QuantLib::Currency parseCurrency ( const std::string &  name) const

Definition at line 45 of file currencyparser.cpp.

45 {
46 boost::shared_lock<boost::shared_mutex> lock(mutex_);
47 {
48 auto it = currencies_.find(name);
49 if (it != currencies_.end()) {
50 return it->second;
51 }
52 }
53 {
54 auto it = preciousMetals_.find(name);
55 if (it != preciousMetals_.end()) {
56 return it->second;
57 }
58 }
59 {
60 auto it = cryptoCurrencies_.find(name);
61 if (it != cryptoCurrencies_.end()) {
62 return it->second;
63 }
64 }
65 QL_FAIL("Currency \"" << name << "\" not recognized");
66}
std::map< std::string, QuantLib::Currency > cryptoCurrencies_
std::map< std::string, QuantLib::Currency > currencies_
boost::shared_mutex mutex_
std::map< std::string, QuantLib::Currency > preciousMetals_
string name
+ Here is the caller graph for this function:

◆ parseMinorCurrency()

QuantLib::Currency parseMinorCurrency ( const std::string &  name) const

Definition at line 68 of file currencyparser.cpp.

68 {
69 boost::shared_lock<boost::shared_mutex> lock(mutex_);
70 auto it = minorCurrencies_.find(name);
71 if (it != minorCurrencies_.end()) {
72 return it->second;
73 }
74 QL_FAIL("Currency \"" << name << "\" not recognized");
75}
std::map< std::string, QuantLib::Currency > minorCurrencies_
+ Here is the caller graph for this function:

◆ parseCurrencyWithMinors()

QuantLib::Currency parseCurrencyWithMinors ( const std::string &  name) const

Definition at line 77 of file currencyparser.cpp.

77 {
78 try {
79 return parseCurrency(name);
80 } catch (...) {
81 }
83}
QuantLib::Currency parseCurrency(const std::string &name) const
QuantLib::Currency parseMinorCurrency(const std::string &name) const
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parseCurrencyPair()

std::pair< QuantLib::Currency, QuantLib::Currency > parseCurrencyPair ( const std::string &  name,
const std::string &  delimiters 
) const

Definition at line 86 of file currencyparser.cpp.

86 {
87 std::vector<std::string> tokens;
88 tokens = boost::split(tokens, name, boost::is_any_of(delimiters));
89 if (tokens.size() == 1) {
90 if (tokens[0].size() > 6) {
91 QL_FAIL("Failed to parse currency pair (" << tokens[0] << ")");
92 }
93
94 QuantLib::Currency ccy1 = parseCurrency(tokens[0].substr(0, 3));
95 QuantLib::Currency ccy2 = parseCurrency(tokens[0].substr(3));
96 return std::make_pair(ccy1, ccy2);
97 } else if (tokens.size() == 2) {
98 try {
99 QuantLib::Currency ccy1 = parseCurrency(tokens[0]);
100 QuantLib::Currency ccy2 = parseCurrency(tokens[1]);
101 return std::make_pair(ccy1, ccy2);
102 } catch (const std::exception& e) {
103 QL_FAIL("Failed to parse currency pair (" << name << "): " << e.what());
104 }
105 } else {
106 QL_FAIL("Failed to parse currency pair (" << name << ")");
107 }
108}
Size size(const ValueType &v)
Definition: value.cpp:145
+ Here is the call graph for this function:

◆ addCurrency()

void addCurrency ( const std::string &  newName,
const QuantLib::Currency &  currency 
)

Definition at line 175 of file currencyparser.cpp.

175 {
176 boost::unique_lock<boost::shared_mutex> lock(mutex_);
177 if (currencies_.find(newName) != currencies_.end() || preciousMetals_.find(newName) != preciousMetals_.end() ||
178 cryptoCurrencies_.find(newName) != cryptoCurrencies_.end())
179 return;
180 currencies_[newName] = currency;
181 addMinorCurrencyCodes(currency);
182}
void addMinorCurrencyCodes(const QuantLib::Currency &currency)
+ Here is the call graph for this function:

◆ addMetal()

void addMetal ( const std::string &  newName,
const QuantLib::Currency &  currency 
)

Definition at line 184 of file currencyparser.cpp.

184 {
185 boost::unique_lock<boost::shared_mutex> lock(mutex_);
186 if (currencies_.find(newName) != currencies_.end() || preciousMetals_.find(newName) != preciousMetals_.end() ||
187 cryptoCurrencies_.find(newName) != cryptoCurrencies_.end())
188 return;
189 preciousMetals_[newName] = currency;
190}

◆ addCrypto()

void addCrypto ( const std::string &  newName,
const QuantLib::Currency &  currency 
)

Definition at line 192 of file currencyparser.cpp.

192 {
193 boost::unique_lock<boost::shared_mutex> lock(mutex_);
194 if (currencies_.find(newName) != currencies_.end() || preciousMetals_.find(newName) != preciousMetals_.end() ||
195 cryptoCurrencies_.find(newName) != cryptoCurrencies_.end())
196 return;
197 cryptoCurrencies_[newName] = currency;
198}

◆ isValidCurrency()

bool isValidCurrency ( const std::string &  name) const

Definition at line 110 of file currencyparser.cpp.

110 {
111 try {
113 return true;
114 } catch (...) {
115 }
116 return false;
117}
QuantLib::Currency parseCurrencyWithMinors(const std::string &name) const
+ Here is the call graph for this function:

◆ isMinorCurrency()

bool isMinorCurrency ( const std::string &  name) const

Definition at line 119 of file currencyparser.cpp.

119 {
120 boost::shared_lock<boost::shared_mutex> lock(mutex_);
121 return minorCurrencies_.find(name) != minorCurrencies_.end();
122}
+ Here is the caller graph for this function:

◆ isPseudoCurrency()

bool isPseudoCurrency ( const std::string &  name) const

Definition at line 124 of file currencyparser.cpp.

124 {
126}
bool isCryptoCurrency(const std::string &name) const
bool isPreciousMetal(const std::string &name) const
+ Here is the call graph for this function:

◆ isPreciousMetal()

bool isPreciousMetal ( const std::string &  name) const

Definition at line 128 of file currencyparser.cpp.

128 {
129 boost::shared_lock<boost::shared_mutex> lock(mutex_);
130 return preciousMetals_.find(name) != preciousMetals_.end();
131}
+ Here is the caller graph for this function:

◆ isCryptoCurrency()

bool isCryptoCurrency ( const std::string &  name) const

Definition at line 133 of file currencyparser.cpp.

133 {
134 boost::shared_lock<boost::shared_mutex> lock(mutex_);
135 return cryptoCurrencies_.find(name) != cryptoCurrencies_.end();
136}
+ Here is the caller graph for this function:

◆ hasMinorCurrency()

bool hasMinorCurrency ( const std::string &  name) const

Definition at line 138 of file currencyparser.cpp.

138 {
139 boost::shared_lock<boost::shared_mutex> lock(mutex_);
140 for (auto const& c : minorCurrencies_) {
141 if (c.second.code() == name)
142 return true;
143 }
144 return false;
145}

◆ getMinorCurrency()

std::string getMinorCurrency ( const std::string &  name) const

Definition at line 147 of file currencyparser.cpp.

147 {
148 boost::shared_lock<boost::shared_mutex> lock(mutex_);
149 for (auto const& c : minorCurrencies_) {
150 if (c.second.code() == name)
151 return c.first;
152 }
153 QL_FAIL("no minor currency found for '" << name << "'");
154}

◆ pseudoCurrencyCodes()

std::set< std::string > pseudoCurrencyCodes ( ) const

Definition at line 156 of file currencyparser.cpp.

156 {
157 boost::shared_lock<boost::shared_mutex> lock(mutex_);
158 std::set<std::string> tmp;
159 for (auto const& c : preciousMetals_)
160 tmp.insert(c.first);
161 for (auto const& c : cryptoCurrencies_)
162 tmp.insert(c.first);
163 return tmp;
164}

◆ convertMinorToMajorCurrency()

QuantLib::Real convertMinorToMajorCurrency ( const std::string &  s,
QuantLib::Real  value 
)

Definition at line 166 of file currencyparser.cpp.

166 {
167 if (isMinorCurrency(s)) {
168 QuantLib::Currency ccy = parseMinorCurrency(s);
169 return value / ccy.fractionsPerUnit();
170 } else {
171 return value;
172 }
173}
bool isMinorCurrency(const std::string &name) const
SafeStack< ValueType > value
+ Here is the call graph for this function:

◆ reset()

void reset ( )

Definition at line 206 of file currencyparser.cpp.

206 {
207 boost::unique_lock<boost::shared_mutex> lock(mutex_);
208
209 currencies_ = {{"AED", AEDCurrency()}, {"AOA", AOACurrency()}, {"ARS", ARSCurrency()}, {"ATS", ATSCurrency()},
210 {"AUD", AUDCurrency()}, {"BEF", BEFCurrency()}, {"BGN", BGNCurrency()}, {"BHD", BHDCurrency()},
211 {"BRL", BRLCurrency()}, {"BWP", BWPCurrency()}, {"CAD", CADCurrency()}, {"CHF", CHFCurrency()},
212 {"CLF", CLFCurrency()}, {"CLP", CLPCurrency()}, {"CNH", CNHCurrency()}, {"CNY", CNYCurrency()},
213 {"COP", COPCurrency()}, {"COU", COUCurrency()}, {"CZK", CZKCurrency()}, {"DEM", DEMCurrency()},
214 {"DKK", DKKCurrency()}, {"EGP", EGPCurrency()}, {"ESP", ESPCurrency()}, {"ETB", ETBCurrency()},
215 {"EUR", EURCurrency()}, {"FIM", FIMCurrency()}, {"FRF", FRFCurrency()}, {"GBP", GBPCurrency()},
216 {"GEL", GELCurrency()}, {"GHS", GHSCurrency()}, {"GRD", GRDCurrency()}, {"HKD", HKDCurrency()},
217 {"HRK", HRKCurrency()}, {"HUF", HUFCurrency()}, {"IDR", IDRCurrency()}, {"IEP", IEPCurrency()},
218 {"ILS", ILSCurrency()}, {"INR", INRCurrency()}, {"ISK", ISKCurrency()}, {"ITL", ITLCurrency()},
219 {"JOD", JODCurrency()}, {"JPY", JPYCurrency()}, {"KES", KESCurrency()}, {"KRW", KRWCurrency()},
220 {"KWD", KWDCurrency()}, {"KZT", KZTCurrency()}, {"LKR", LKRCurrency()}, {"LUF", LUFCurrency()},
221 {"MAD", MADCurrency()}, {"MUR", MURCurrency()}, {"MXN", MXNCurrency()}, {"MXV", MXVCurrency()},
222 {"MYR", MYRCurrency()}, {"NGN", NGNCurrency()}, {"NLG", NLGCurrency()}, {"NOK", NOKCurrency()},
223 {"NZD", NZDCurrency()}, {"OMR", OMRCurrency()}, {"PEN", PENCurrency()}, {"PHP", PHPCurrency()},
224 {"PKR", PKRCurrency()}, {"PLN", PLNCurrency()}, {"PTE", PTECurrency()}, {"QAR", QARCurrency()},
225 {"RON", RONCurrency()}, {"RSD", RSDCurrency()}, {"RUB", RUBCurrency()}, {"SAR", SARCurrency()},
226 {"SEK", SEKCurrency()}, {"SGD", SGDCurrency()}, {"THB", THBCurrency()}, {"TND", TNDCurrency()},
227 {"TRY", TRYCurrency()}, {"TWD", TWDCurrency()}, {"UAH", UAHCurrency()}, {"UGX", UGXCurrency()},
228 {"USD", USDCurrency()}, {"UYU", UYUCurrency()}, {"VND", VNDCurrency()}, {"XOF", XOFCurrency()},
229 {"ZAR", ZARCurrency()}, {"ZMW", ZMWCurrency()}};
230
231 minorCurrencies_ = {{"GBp", GBPCurrency()}, {"GBX", GBPCurrency()}, {"ILa", ILSCurrency()}, {"ILX", ILSCurrency()},
232 {"ILs", ILSCurrency()}, {"KWf", KWDCurrency()}, {"ILA", ILSCurrency()}, {"ZAc", ZARCurrency()},
233 {"ZAC", ZARCurrency()}, {"ZAX", ZARCurrency()}};
234
235 preciousMetals_ = {{"XAG", XAGCurrency()}, {"XAU", XAUCurrency()}, {"XPT", XPTCurrency()}, {"XPD", XPDCurrency()}};
236
237 cryptoCurrencies_ = {{"XBT", BTCCurrency()}, {"BTC", BTCCurrency()}, {"ETH", ETHCurrency()}, {"ETC", ETCCurrency()},
238 {"BCH", BCHCurrency()}, {"XRP", XRPCurrency()}, {"LTC", LTCCurrency()}};
239
240 for (auto const& c : currencies_) {
241 addMinorCurrencyCodes(c.second);
242 }
243}
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ addMinorCurrencyCodes()

void addMinorCurrencyCodes ( const QuantLib::Currency &  currency)
private

Definition at line 200 of file currencyparser.cpp.

200 {
201 for (auto const& c : currency.minorUnitCodes()) {
202 minorCurrencies_[c] = currency;
203 }
204}
+ Here is the caller graph for this function:

Member Data Documentation

◆ mutex_

boost::shared_mutex mutex_
mutableprivate

Definition at line 68 of file currencyparser.hpp.

◆ currencies_

std::map<std::string, QuantLib::Currency> currencies_
private

Definition at line 69 of file currencyparser.hpp.

◆ minorCurrencies_

std::map<std::string, QuantLib::Currency> minorCurrencies_
private

Definition at line 70 of file currencyparser.hpp.

◆ preciousMetals_

std::map<std::string, QuantLib::Currency> preciousMetals_
private

Definition at line 71 of file currencyparser.hpp.

◆ cryptoCurrencies_

std::map<std::string, QuantLib::Currency> cryptoCurrencies_
private

Definition at line 72 of file currencyparser.hpp.