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

Repository for currency dependent market conventions. More...

#include <ored/configuration/conventions.hpp>

+ Inheritance diagram for Conventions:
+ Collaboration diagram for Conventions:

Public Member Functions

 Conventions ()
 Default constructor. More...
 
QuantLib::ext::shared_ptr< Conventionget (const string &id) const
 
std::pair< bool, QuantLib::ext::shared_ptr< Convention > > get (const std::string &id, const Convention::Type &type) const
 
std::set< QuantLib::ext::shared_ptr< Convention > > get (const Convention::Type &type) const
 
QuantLib::ext::shared_ptr< ConventiongetFxConvention (const string &ccy1, const string &ccy2) const
 
bool has (const std::string &id) const
 Checks if we have a convention with the given id. More...
 
bool has (const std::string &id, const Convention::Type &type) const
 Checks if we have a convention with the given id and type. More...
 
void clear () const
 
void add (const QuantLib::ext::shared_ptr< Convention > &convention) const
 
- 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...
 

Serialisation

map< string, QuantLib::ext::shared_ptr< Convention > > data_
 
map< string, std::pair< string, string > > unparsed_
 
std::set< string > used_
 
boost::shared_mutex mutex_
 
virtual void fromXML (XMLNode *node) override
 
virtual XMLNodetoXML (XMLDocument &doc) const override
 

Detailed Description

Repository for currency dependent market conventions.

Definition at line 113 of file conventions.hpp.

Constructor & Destructor Documentation

◆ Conventions()

Default constructor.

Definition at line 116 of file conventions.hpp.

116{}

Member Function Documentation

◆ get() [1/3]

QuantLib::ext::shared_ptr< Convention > get ( const string &  id) const

Returns the convention if found and throws if not

Definition at line 2585 of file conventions.cpp.

2585 {
2586
2587 {
2588 boost::shared_lock<boost::shared_mutex> lock(mutex_);
2589 if (auto it = data_.find(id); it != data_.end()) {
2590 used_.insert(id);
2591 return it->second;
2592 }
2593 if (auto it = data_.find(flip(id)); it != data_.end()) {
2594 used_.insert(flip(id));
2595 return it->second;
2596 }
2597 }
2598
2599 std::string type, unparsed;
2600 {
2601 boost::unique_lock<boost::shared_mutex> lock(mutex_);
2602 if (auto it = unparsed_.find(id); it != unparsed_.end()) {
2603 std::tie(type, unparsed) = it->second;
2604 unparsed_.erase(id);
2605 } else if (auto it = unparsed_.find(flip(id)); it != unparsed_.end()) {
2606 std::tie(type, unparsed) = it->second;
2607 unparsed_.erase(flip(id));
2608 }
2609 }
2610
2611 if (unparsed.empty()) {
2612 QL_FAIL("Convention '" << id << "' not found.");
2613 }
2614
2615 QuantLib::ext::shared_ptr<Convention> convention;
2616 if (type == "Zero") {
2617 convention = QuantLib::ext::make_shared<ZeroRateConvention>();
2618 } else if (type == "Deposit") {
2619 convention = QuantLib::ext::make_shared<DepositConvention>();
2620 } else if (type == "Future") {
2621 convention = QuantLib::ext::make_shared<FutureConvention>();
2622 } else if (type == "FRA") {
2623 convention = QuantLib::ext::make_shared<FraConvention>();
2624 } else if (type == "OIS") {
2625 convention = QuantLib::ext::make_shared<OisConvention>();
2626 } else if (type == "Swap") {
2627 convention = QuantLib::ext::make_shared<IRSwapConvention>();
2628 } else if (type == "AverageOIS") {
2629 convention = QuantLib::ext::make_shared<AverageOisConvention>();
2630 } else if (type == "TenorBasisSwap") {
2631 convention = QuantLib::ext::make_shared<TenorBasisSwapConvention>();
2632 } else if (type == "TenorBasisTwoSwap") {
2633 convention=QuantLib::ext::make_shared<TenorBasisTwoSwapConvention>();
2634 } else if (type == "BMABasisSwap") {
2635 convention = QuantLib::ext::make_shared<BMABasisSwapConvention>();
2636 } else if (type == "CrossCurrencyBasis") {
2637 convention=QuantLib::ext::make_shared<CrossCcyBasisSwapConvention>();
2638 } else if (type == "CrossCurrencyFixFloat") {
2639 convention=QuantLib::ext::make_shared<CrossCcyFixFloatSwapConvention>();
2640 } else if (type == "CDS") {
2641 convention=QuantLib::ext::make_shared<CdsConvention>();
2642 } else if (type == "SwapIndex") {
2643 convention=QuantLib::ext::make_shared<SwapIndexConvention>();
2644 } else if (type == "InflationSwap") {
2645 convention=QuantLib::ext::make_shared<InflationSwapConvention>();
2646 } else if (type == "CmsSpreadOption") {
2647 convention=QuantLib::ext::make_shared<CmsSpreadOptionConvention>();
2648 } else if (type == "CommodityForward") {
2649 convention = QuantLib::ext::make_shared<CommodityForwardConvention>();
2650 } else if (type == "CommodityFuture") {
2651 convention = QuantLib::ext::make_shared<CommodityFutureConvention>();
2652 } else if (type == "FxOption") {
2653 convention = QuantLib::ext::make_shared<FxOptionConvention>();
2654 } else if (type == "ZeroInflationIndex") {
2655 convention = QuantLib::ext::make_shared<ZeroInflationIndexConvention>();
2656 } else if (type == "BondYield") {
2657 convention = QuantLib::ext::make_shared<BondYieldConvention>();
2658 } else {
2659 QL_FAIL("Convention '" << id << "' has unknown type '" + type + "' not recognized.");
2660 }
2661
2662 try {
2663 DLOG("Building Convention " << id);
2664 convention->fromXMLString(unparsed);
2665 add(convention);
2666 used_.insert(id);
2667 } catch (exception& e) {
2668 WLOG("Convention '" << id << "' could not be built: " << e.what());
2669 QL_FAIL("Convention '" << id << "' could not be built: " << e.what());
2670 }
2671
2672 return convention;
2673}
map< string, QuantLib::ext::shared_ptr< Convention > > data_
std::set< string > used_
map< string, std::pair< string, string > > unparsed_
boost::shared_mutex mutex_
void add(const QuantLib::ext::shared_ptr< Convention > &convention) const
#define DLOG(text)
Logging Macro (Level = Debug)
Definition: log.hpp:554
#define WLOG(text)
Logging Macro (Level = Warning)
Definition: log.hpp:550
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ get() [2/3]

pair< bool, QuantLib::ext::shared_ptr< Convention > > get ( const std::string &  id,
const Convention::Type type 
) const

Get a convention with the given id and type. If no convention of the given type with the given id is found, the first element of the returned pair is false and the second element is a nullptr. If a convention is found, the first element of the returned pair is true and the second element holds the convention.

Definition at line 2691 of file conventions.cpp.

2691 {
2692 try {
2693 auto c = get(id);
2694 if (c->type() == type) {
2695 used_.insert(id);
2696 return std::make_pair(true, c);
2697 }
2698 } catch (const std::exception& e) {
2699 }
2700 return make_pair(false, nullptr);
2701}
QuantLib::ext::shared_ptr< Convention > get(const string &id) const
+ Here is the call graph for this function:

◆ get() [3/3]

std::set< QuantLib::ext::shared_ptr< Convention > > get ( const Convention::Type type) const

Get all conventions of a given type

Definition at line 2703 of file conventions.cpp.

2703 {
2704 std::set<QuantLib::ext::shared_ptr<Convention>> result;
2705 std::set<std::string> unparsedIds;
2706 std::string typeStr = ore::data::to_string(type);
2707 {
2708 boost::shared_lock<boost::shared_mutex> lock(mutex_);
2709 for (auto const& d : data_) {
2710 if (d.second->type() == type) {
2711 used_.insert(d.first);
2712 result.insert(d.second);
2713 }
2714 }
2715 for (auto const& u : unparsed_) {
2716 if (u.second.first == typeStr)
2717 unparsedIds.insert(u.first);
2718 }
2719 }
2720 for (auto const& id : unparsedIds) {
2721 result.insert(get(id));
2722 }
2723 return result;
2724}
std::string to_string(const LocationInfo &l)
Definition: ast.cpp:28
+ Here is the call graph for this function:

◆ getFxConvention()

QuantLib::ext::shared_ptr< Convention > getFxConvention ( const string &  ccy1,
const string &  ccy2 
) const

Find a convention for an FX pair

Definition at line 2675 of file conventions.cpp.

2675 {
2676 boost::shared_lock<boost::shared_mutex> lock(mutex_);
2677 for (auto c : data_) {
2678 auto fxCon = QuantLib::ext::dynamic_pointer_cast<FXConvention>(c.second);
2679 if (fxCon) {
2680 string source = fxCon->sourceCurrency().code();
2681 string target = fxCon->targetCurrency().code();
2682 if ((source == ccy1 && target == ccy2) || (target == ccy1 && source == ccy2)) {
2683 used_.insert(c.first);
2684 return fxCon;
2685 }
2686 }
2687 }
2688 QL_FAIL("FX convention for ccys '" << ccy1 << "' and '" << ccy2 << "' not found.");
2689}

◆ has() [1/2]

bool has ( const std::string &  id) const

Checks if we have a convention with the given id.

Definition at line 2726 of file conventions.cpp.

2726 {
2727 try {
2728 get(id);
2729 } catch (const std::exception& e) {
2730 return false;
2731 }
2732 boost::shared_lock<boost::shared_mutex> lock(mutex_);
2733 return data_.find(id) != data_.end() || unparsed_.find(id) != unparsed_.end() ||
2734 data_.find(flip(id)) != data_.end() || unparsed_.find(flip(id)) != unparsed_.end();
2735}
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ has() [2/2]

bool has ( const std::string &  id,
const Convention::Type type 
) const

Checks if we have a convention with the given id and type.

Definition at line 2737 of file conventions.cpp.

2737 {
2738 return get(id, type).first;
2739}
+ Here is the call graph for this function:

◆ clear()

void clear ( ) const

Clear all conventions

Definition at line 2558 of file conventions.cpp.

2558 {
2559 boost::unique_lock<boost::shared_mutex> lock(mutex_);
2560 data_.clear();
2561}

◆ add()

void add ( const QuantLib::ext::shared_ptr< Convention > &  convention) const

Add a convention. This will overwrite an existing convention with the same id

Definition at line 2741 of file conventions.cpp.

2741 {
2742 boost::unique_lock<boost::shared_mutex> lock(mutex_);
2743 const string& id = convention->id();
2744 QL_REQUIRE(data_.find(id) == data_.end(), "Convention already exists for id " << id);
2745 data_[id] = convention;
2746}
+ Here is the caller graph for this function:

◆ fromXML()

void fromXML ( XMLNode node)
overridevirtual

Implements XMLSerializable.

Definition at line 2493 of file conventions.cpp.

2493 {
2494 XMLUtils::checkNode(node, "Conventions");
2495
2496 for (XMLNode* child = XMLUtils::getChildNode(node); child; child = XMLUtils::getNextSibling(child)) {
2497
2498 string type = XMLUtils::getNodeName(child);
2499 QuantLib::ext::shared_ptr<Convention> convention;
2500
2501 /* we need to build conventions of type
2502
2503 - IborIndex
2504 - OvernightIndex
2505 - FX
2506
2507 immediately because
2508
2509 - for IborIndex other conventions depend on it via parseIborIndex() calls
2510 - the id of IborIndex convention is changed during build (period is normalized)
2511 - FX conventions are searched by currencies, not id */
2512
2513 if (type == "IborIndex") {
2514 convention = QuantLib::ext::make_shared<IborIndexConvention>();
2515 } else if (type == "FX") {
2516 convention = QuantLib::ext::make_shared<FXConvention>();
2517 } else if (type == "OvernightIndex") {
2518 convention = QuantLib::ext::make_shared<OvernightIndexConvention>();
2519 }
2520
2521 string id = "unknown";
2522 if (convention) {
2523 try {
2524 id = XMLUtils::getChildValue(child, "Id", true);
2525 DLOG("Building Convention " << id);
2526 convention->fromXML(child);
2527 add(convention);
2528 } catch (const std::exception& e) {
2529 WLOG("Exception parsing convention "
2530 << id << ": " << e.what() << ". This is only a problem if this convention is used later on.");
2531 }
2532 } else {
2533 try {
2534 id = XMLUtils::getChildValue(child, "Id", true);
2535 DLOG("Reading Convention " << id);
2536 unparsed_[id] = std::make_pair(type, XMLUtils::toString(child));
2537 } catch (const std::exception& e) {
2538 WLOG("Exception during retrieval of convention "
2539 << id << ": " << e.what() << ". This is only a problem if this convention is used later on.");
2540 }
2541 }
2542 }
2543}
static void checkNode(XMLNode *n, const string &expectedName)
Definition: xmlutils.cpp:175
static string getNodeName(XMLNode *n)
Get and set a node's name.
Definition: xmlutils.cpp:473
static string getChildValue(XMLNode *node, const string &name, bool mandatory=false, const string &defaultValue=string())
Definition: xmlutils.cpp:277
static XMLNode * getChildNode(XMLNode *n, const string &name="")
Definition: xmlutils.cpp:387
static XMLNode * getNextSibling(XMLNode *node, const string &name="")
Get a node's next sibling node.
Definition: xmlutils.cpp:484
static string toString(XMLNode *node)
Write a node out as a string.
Definition: xmlutils.cpp:714
rapidxml::xml_node< char > XMLNode
Definition: xmlutils.hpp:60
+ Here is the call graph for this function:

◆ toXML()

XMLNode * toXML ( XMLDocument doc) const
overridevirtual

Implements XMLSerializable.

Definition at line 2545 of file conventions.cpp.

2545 {
2546 boost::unique_lock<boost::shared_mutex> lock(mutex_);
2547
2548 XMLNode* conventionsNode = doc.allocNode("Conventions");
2549
2550 map<string, QuantLib::ext::shared_ptr<Convention>>::const_iterator it;
2551 for (it = data_.begin(); it != data_.end(); ++it) {
2552 if (used_.find(it->first) != used_.end())
2553 XMLUtils::appendNode(conventionsNode, it->second->toXML(doc));
2554 }
2555 return conventionsNode;
2556}
static void appendNode(XMLNode *parent, XMLNode *child)
Definition: xmlutils.cpp:406
+ Here is the call graph for this function:

Member Data Documentation

◆ data_

map<string, QuantLib::ext::shared_ptr<Convention> > data_
mutableprivate

Definition at line 154 of file conventions.hpp.

◆ unparsed_

map<string, std::pair<string, string> > unparsed_
mutableprivate

Definition at line 155 of file conventions.hpp.

◆ used_

std::set<string> used_
mutableprivate

Definition at line 156 of file conventions.hpp.

◆ mutex_

boost::shared_mutex mutex_
mutableprivate

Definition at line 157 of file conventions.hpp.