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

Currency configuration. More...

#include <ored/configuration/currencyconfig.hpp>

+ Inheritance diagram for CurrencyConfig:
+ Collaboration diagram for CurrencyConfig:

Public Member Functions

 CurrencyConfig ()
 
const vector< ConfigurableCurrency > & getCurrencies () const
 check out any configured currencies More...
 
void fromXML (XMLNode *node) override
 
XMLNodetoXML (XMLDocument &doc) const override
 
- Public Member Functions inherited from XMLSerializable
virtual ~XMLSerializable ()
 
virtual void fromXML (XMLNode *node)=0
 
virtual XMLNodetoXML (XMLDocument &doc) const =0
 
void fromFile (const std::string &filename)
 
void toFile (const std::string &filename) const
 
void fromXMLString (const std::string &xml)
 Parse from XML string. More...
 
std::string toXMLString () const
 Parse from XML string. More...
 

Private Attributes

vector< ConfigurableCurrencycurrencies_
 

Detailed Description

Currency configuration.

Allows reading a list of currency specifications from XML rather than hard coding each in QuantExt/QuantLib

Definition at line 49 of file currencyconfig.hpp.

Constructor & Destructor Documentation

◆ CurrencyConfig()

Definition at line 30 of file currencyconfig.cpp.

30{}

Member Function Documentation

◆ getCurrencies()

const vector< ConfigurableCurrency > & getCurrencies ( ) const

check out any configured currencies

Definition at line 55 of file currencyconfig.hpp.

55{ return currencies_; }
vector< ConfigurableCurrency > currencies_

◆ fromXML()

void fromXML ( XMLNode node)
overridevirtual

Implements XMLSerializable.

Definition at line 32 of file currencyconfig.cpp.

32 {
33 currencies_.clear();
34 XMLUtils::checkNode(baseNode, "CurrencyConfig");
35
36 for (auto node : XMLUtils::getChildrenNodes(baseNode, "Currency")) {
37 string name = XMLUtils::getChildValue(node, "Name", false);
38 string isoCode = XMLUtils::getChildValue(node, "ISOCode", false);
39 auto tmp = parseListOfValues(XMLUtils::getChildValue(node, "MinorUnitCodes", false));
40 std::set<std::string> minorUnitCodes(tmp.begin(), tmp.end());
41 try {
42 DLOG("Loading external currency configuration for " << isoCode);
43 Integer numericCode = parseInteger(XMLUtils::getChildValue(node, "NumericCode", false));
44 string symbol = XMLUtils::getChildValue(node, "Symbol", false);
45 string fractionSymbol = XMLUtils::getChildValue(node, "Symbol", false);
46 Integer fractionsPerUnit = parseInteger(XMLUtils::getChildValue(node, "FractionsPerUnit", false));
47 Rounding::Type roundingType = parseRoundingType(XMLUtils::getChildValue(node, "RoundingType", false));
48 Integer precision = parseInteger(XMLUtils::getChildValue(node, "RoundingPrecision", false));
49 // the digit where we switch form roundng down to rounding up, typically 5 and used across all
50 // Integer digit = parseInteger(XMLUtils::getChildValue(node, "Digit", false));
51 string format = XMLUtils::getChildValue(node, "Format", false);
52 QuantExt::ConfigurableCurrency::Type currencyType = parseCurrencyType(XMLUtils::getChildValue(node, "CurrencyType", false, "Major"));
53 Rounding rounding(precision, roundingType);
54 QuantExt::ConfigurableCurrency c(name, isoCode, numericCode, symbol, fractionSymbol, fractionsPerUnit,
55 rounding, format, minorUnitCodes, currencyType);
56 DLOG("loading configuration for currency code " << isoCode);
57
58 switch (currencyType) {
59 case QuantExt::ConfigurableCurrency::Type::Crypto:
60 CurrencyParser::instance().addCrypto(c.code(), c);
61 break;
62 case QuantExt::ConfigurableCurrency::Type::Metal:
63 CurrencyParser::instance().addMetal(c.code(), c);
64 break;
65 default:
66 CurrencyParser::instance().addCurrency(c.code(), c);
67 break;
68 }
69 currencies_.push_back(c);
70
71 } catch (std::exception&) {
72 ALOG("error loading currency config for name " << name << " iso code " << isoCode);
73 }
74 }
75}
static void checkNode(XMLNode *n, const string &expectedName)
Definition: xmlutils.cpp:175
static vector< XMLNode * > getChildrenNodes(XMLNode *node, const string &name)
Returns all the children with a given name.
Definition: xmlutils.cpp:428
static string getChildValue(XMLNode *node, const string &name, bool mandatory=false, const string &defaultValue=string())
Definition: xmlutils.cpp:277
QuantExt::ConfigurableCurrency::Type parseCurrencyType(const string &s)
Convert text to QuantExt::ConfigurableCurrency::Type (Major, Minor, Metal, Crypto)
Definition: parsers.cpp:292
QuantLib::Rounding::Type parseRoundingType(const std::string &s)
Convert text to QuantLib::Rounding.
Definition: parsers.cpp:1027
Integer parseInteger(const string &s)
Convert text to QuantLib::Integer.
Definition: parsers.cpp:136
#define DLOG(text)
Logging Macro (Level = Debug)
Definition: log.hpp:554
#define ALOG(text)
Logging Macro (Level = Alert)
Definition: log.hpp:544
std::vector< string > parseListOfValues(string s, const char escape, const char delim, const char quote)
Definition: parsers.cpp:639
string name
+ Here is the call graph for this function:

◆ toXML()

XMLNode * toXML ( XMLDocument doc) const
overridevirtual

Implements XMLSerializable.

Definition at line 77 of file currencyconfig.cpp.

77 {
78 XMLNode* node = doc.allocNode("CurrencyConfig");
79 for (auto ccy : currencies_) {
80 XMLNode* ccyNode = XMLUtils::addChild(doc, node, "Currency");
81 XMLUtils::addChild(doc, ccyNode, "Name", ccy.name());
82 XMLUtils::addChild(doc, ccyNode, "ISOCode", ccy.code());
84 doc, ccyNode, "MinorUnitCodes",
85 std::vector<std::string>(ccy.minorUnitCodes().begin(), ccy.minorUnitCodes().end()));
86 XMLUtils::addChild(doc, ccyNode, "NumericCode", to_string(ccy.numericCode()));
87 XMLUtils::addChild(doc, ccyNode, "Symbol", ccy.symbol());
88 XMLUtils::addChild(doc, ccyNode, "FractionSymbol", ccy.fractionSymbol());
89 XMLUtils::addChild(doc, ccyNode, "RoundingType", to_string(ccy.rounding().type()));
90 XMLUtils::addChild(doc, ccyNode, "RoundingPrecision", to_string(ccy.rounding().precision()));
91 // XMLUtils::addChild(doc, ccyNode, "Digit", to_string(ccy.rounding().roundingDigit()));
92 XMLUtils::addChild(doc, ccyNode, "Format", ccy.format());
93 XMLUtils::addChild(doc, ccyNode, "CurrencyType", to_string(ccy.currencyType()));
94 }
95 return node;
96}
static void addGenericChildAsList(XMLDocument &doc, XMLNode *n, const string &name, const vector< T > &values, const string &attrName="", const string &attr="")
Definition: xmlutils.hpp:144
static XMLNode * addChild(XMLDocument &doc, XMLNode *n, const string &name)
Definition: xmlutils.cpp:181
rapidxml::xml_node< char > XMLNode
Definition: xmlutils.hpp:60
std::string to_string(const LocationInfo &l)
Definition: ast.cpp:28
+ Here is the call graph for this function:

Member Data Documentation

◆ currencies_

vector<ConfigurableCurrency> currencies_
private

Definition at line 61 of file currencyconfig.hpp.