32#include <ql/currencies/all.hpp>
33#include <ql/errors.hpp>
35#include <boost/algorithm/string.hpp>
46 boost::shared_lock<boost::shared_mutex> lock(
mutex_);
65 QL_FAIL(
"Currency \"" <<
name <<
"\" not recognized");
69 boost::shared_lock<boost::shared_mutex> lock(
mutex_);
74 QL_FAIL(
"Currency \"" <<
name <<
"\" not recognized");
85std::pair<QuantLib::Currency, QuantLib::Currency>
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] <<
")");
94 QuantLib::Currency ccy1 =
parseCurrency(tokens[0].substr(0, 3));
96 return std::make_pair(ccy1, ccy2);
97 }
else if (tokens.size() == 2) {
101 return std::make_pair(ccy1, ccy2);
102 }
catch (
const std::exception& e) {
103 QL_FAIL(
"Failed to parse currency pair (" <<
name <<
"): " << e.what());
106 QL_FAIL(
"Failed to parse currency pair (" <<
name <<
")");
120 boost::shared_lock<boost::shared_mutex> lock(
mutex_);
129 boost::shared_lock<boost::shared_mutex> lock(
mutex_);
134 boost::shared_lock<boost::shared_mutex> lock(
mutex_);
139 boost::shared_lock<boost::shared_mutex> lock(
mutex_);
141 if (c.second.code() ==
name)
148 boost::shared_lock<boost::shared_mutex> lock(
mutex_);
150 if (c.second.code() ==
name)
153 QL_FAIL(
"no minor currency found for '" <<
name <<
"'");
157 boost::shared_lock<boost::shared_mutex> lock(
mutex_);
158 std::set<std::string> tmp;
169 return value / ccy.fractionsPerUnit();
176 boost::unique_lock<boost::shared_mutex> lock(
mutex_);
185 boost::unique_lock<boost::shared_mutex> lock(
mutex_);
193 boost::unique_lock<boost::shared_mutex> lock(
mutex_);
201 for (
auto const& c : currency.minorUnitCodes()) {
207 boost::unique_lock<boost::shared_mutex> lock(
mutex_);
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()}};
231 minorCurrencies_ = {{
"GBp", GBPCurrency()}, {
"GBX", GBPCurrency()}, {
"ILa", ILSCurrency()}, {
"ILX", ILSCurrency()},
232 {
"ILs", ILSCurrency()}, {
"KWf", KWDCurrency()}, {
"ILA", ILSCurrency()}, {
"ZAc", ZARCurrency()},
233 {
"ZAC", ZARCurrency()}, {
"ZAX", ZARCurrency()}};
237 cryptoCurrencies_ = {{
"XBT", BTCCurrency()}, {
"BTC", BTCCurrency()}, {
"ETH", ETHCurrency()}, {
"ETC", ETCCurrency()},
238 {
"BCH", BCHCurrency()}, {
"XRP", XRPCurrency()}, {
"LTC", LTCCurrency()}};
std::set< std::string > pseudoCurrencyCodes() const
void addCrypto(const std::string &newName, const QuantLib::Currency ¤cy)
void addMinorCurrencyCodes(const QuantLib::Currency ¤cy)
std::map< std::string, QuantLib::Currency > minorCurrencies_
bool isCryptoCurrency(const std::string &name) const
std::string getMinorCurrency(const std::string &name) const
bool isPreciousMetal(const std::string &name) const
QuantLib::Real convertMinorToMajorCurrency(const std::string &s, QuantLib::Real value)
std::map< std::string, QuantLib::Currency > cryptoCurrencies_
std::map< std::string, QuantLib::Currency > currencies_
bool isPseudoCurrency(const std::string &name) const
bool isMinorCurrency(const std::string &name) const
std::pair< QuantLib::Currency, QuantLib::Currency > parseCurrencyPair(const std::string &name, const std::string &delimiters) const
QuantLib::Currency parseCurrency(const std::string &name) const
QuantLib::Currency parseCurrencyWithMinors(const std::string &name) const
bool isValidCurrency(const std::string &name) const
QuantLib::Currency parseMinorCurrency(const std::string &name) const
boost::shared_mutex mutex_
std::map< std::string, QuantLib::Currency > preciousMetals_
void addCurrency(const std::string &newName, const QuantLib::Currency ¤cy)
void addMetal(const std::string &newName, const QuantLib::Currency ¤cy)
bool hasMinorCurrency(const std::string &name) const
SafeStack< ValueType > value
currency parser singleton class
Size size(const ValueType &v)
Serializable Credit Default Swap.