Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
List of all members
InstantaneousCorrelations Class Reference

InstantaneousCorrelations. More...

#include <ored/model/crossassetmodeldata.hpp>

+ Inheritance diagram for InstantaneousCorrelations:
+ Collaboration diagram for InstantaneousCorrelations:

Public Member Functions

Constructors
 InstantaneousCorrelations ()
 Default constructor. More...
 
 InstantaneousCorrelations (const std::map< CorrelationKey, QuantLib::Handle< QuantLib::Quote > > &correlations)
 Detailed constructor. More...
 
Serialisation
virtual void fromXML (XMLNode *node) override
 Populate members from XML. More...
 
virtual XMLNodetoXML (XMLDocument &doc) const override
 Write class members to XML. More...
 
Getters
const std::map< CorrelationKey, QuantLib::Handle< QuantLib::Quote > > & correlations () const
 
void clear ()
 Clear all vectors and maps. More...
 
Setters
void correlations (const std::map< CorrelationKey, QuantLib::Handle< QuantLib::Quote > > &corrs)
 
- 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...
 

Operators

std::map< CorrelationKey, QuantLib::Handle< QuantLib::Quote > > correlations_
 
bool operator== (const InstantaneousCorrelations &rhs)
 
bool operator!= (const InstantaneousCorrelations &rhs)
 

Detailed Description

InstantaneousCorrelations.

InstantaneousCorrelations is a class to store the correlations required by the CrossAssetModelData class

Definition at line 59 of file crossassetmodeldata.hpp.

Constructor & Destructor Documentation

◆ InstantaneousCorrelations() [1/2]

Default constructor.

Definition at line 64 of file crossassetmodeldata.hpp.

64{}

◆ InstantaneousCorrelations() [2/2]

InstantaneousCorrelations ( const std::map< CorrelationKey, QuantLib::Handle< QuantLib::Quote > > &  correlations)

Detailed constructor.

Definition at line 67 of file crossassetmodeldata.hpp.

std::map< CorrelationKey, QuantLib::Handle< QuantLib::Quote > > correlations_
const std::map< CorrelationKey, QuantLib::Handle< QuantLib::Quote > > & correlations() const

Member Function Documentation

◆ fromXML()

void fromXML ( XMLNode node)
overridevirtual

Populate members from XML.

Implements XMLSerializable.

Definition at line 72 of file crossassetmodeldata.cpp.

72 {
73 // Configure correlation structure
74 LOG("CrossAssetModelData: adding correlations.");
75 XMLNode* correlationNode = XMLUtils::locateNode(node, "InstantaneousCorrelations");
76 CorrelationMatrixBuilder cmb;
77 if (correlationNode) {
78 vector<XMLNode*> nodes = XMLUtils::getChildrenNodes(correlationNode, "Correlation");
79 for (Size i = 0; i < nodes.size(); ++i) {
80 CorrelationFactor factor_1 = fromNode(nodes[i], true);
81 CorrelationFactor factor_2 = fromNode(nodes[i], false);
82 Real corr = parseReal(XMLUtils::getNodeValue(nodes[i]));
83 cmb.addCorrelation(factor_1, factor_2, corr);
84 }
85 } else {
86 QL_FAIL("No InstantaneousCorrelations found in model configuration XML");
87 }
88
89 correlations_ = cmb.correlations();
90}
static vector< XMLNode * > getChildrenNodes(XMLNode *node, const string &name)
Returns all the children with a given name.
Definition: xmlutils.cpp:428
static XMLNode * locateNode(XMLNode *n, const string &name="")
Definition: xmlutils.cpp:393
static string getNodeValue(XMLNode *node)
Get a node's value.
Definition: xmlutils.cpp:489
Real parseReal(const string &s)
Convert text to Real.
Definition: parsers.cpp:112
#define LOG(text)
Logging Macro (Level = Notice)
Definition: log.hpp:552
rapidxml::xml_node< char > XMLNode
Definition: xmlutils.hpp:60
+ Here is the call graph for this function:

◆ toXML()

XMLNode * toXML ( XMLDocument doc) const
overridevirtual

Write class members to XML.

Implements XMLSerializable.

Definition at line 92 of file crossassetmodeldata.cpp.

92 {
93
94 XMLNode* instantaneousCorrelationsNode = doc.allocNode("InstantaneousCorrelations");
95
96 for (auto it = correlations_.begin(); it != correlations_.end(); it++) {
97
98 XMLNode* node = doc.allocNode("Correlation", to_string(it->second->value()));
99 XMLUtils::appendNode(instantaneousCorrelationsNode, node);
100
101 CorrelationFactor f_1 = it->first.first;
102 XMLUtils::addAttribute(doc, node, "factor1", to_string(f_1.type) + ":" + f_1.name);
103 if (f_1.index != Null<Size>())
104 XMLUtils::addAttribute(doc, node, "index1", to_string(f_1.index));
105
106 CorrelationFactor f_2 = it->first.second;
107 XMLUtils::addAttribute(doc, node, "factor2", to_string(f_2.type) + ":" + f_2.name);
108 if (f_2.index != Null<Size>())
109 XMLUtils::addAttribute(doc, node, "index2", to_string(f_2.index));
110 }
111
112 return instantaneousCorrelationsNode;
113}
static void addAttribute(XMLDocument &doc, XMLNode *node, const string &attrName, const string &attrValue)
Definition: xmlutils.cpp:412
static void appendNode(XMLNode *parent, XMLNode *child)
Definition: xmlutils.cpp:406
std::string to_string(const LocationInfo &l)
Definition: ast.cpp:28
+ Here is the call graph for this function:

◆ correlations() [1/2]

const std::map< CorrelationKey, QuantLib::Handle< QuantLib::Quote > > & correlations ( ) const

Definition at line 82 of file crossassetmodeldata.hpp.

82{ return correlations_; }

◆ clear()

void clear ( )

Clear all vectors and maps.

Definition at line 86 of file crossassetmodeldata.hpp.

86{ correlations_.clear(); }

◆ correlations() [2/2]

void correlations ( const std::map< CorrelationKey, QuantLib::Handle< QuantLib::Quote > > &  corrs)

Definition at line 91 of file crossassetmodeldata.hpp.

91 {
92 correlations_ = corrs;
93 }

◆ operator==()

bool operator== ( const InstantaneousCorrelations rhs)

Definition at line 115 of file crossassetmodeldata.cpp.

115 {
116 // compare correlations by value (not the handle links)
117 map<CorrelationKey, Handle<Quote>>::const_iterator corr1, corr2;
118 for (corr1 = correlations_.begin(), corr2 = rhs.correlations_.begin();
119 corr1 != correlations_.end() && corr2 != rhs.correlations_.end(); ++corr1, ++corr2) {
120 if (corr1->first != corr2->first || !close_enough(corr1->second->value(), corr2->second->value()))
121 return false;
122 }
123 if (corr1 != correlations_.end() || corr2 != rhs.correlations_.end())
124 return false;
125
126 return true;
127}
Filter close_enough(const RandomVariable &x, const RandomVariable &y)
+ Here is the call graph for this function:

◆ operator!=()

Definition at line 129 of file crossassetmodeldata.cpp.

129{ return !(*this == rhs); }

Member Data Documentation

◆ correlations_

std::map<CorrelationKey, QuantLib::Handle<QuantLib::Quote> > correlations_
private

Definition at line 103 of file crossassetmodeldata.hpp.