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

#include <ored/model/calibrationbasket.hpp>

+ Inheritance diagram for CalibrationBasket:
+ Collaboration diagram for CalibrationBasket:

Public Member Functions

 CalibrationBasket ()
 Default constructor, empty calibration basket. More...
 
 CalibrationBasket (const std::vector< QuantLib::ext::shared_ptr< CalibrationInstrument > > &instruments)
 Detailed constructor. More...
 
Inspectors
const std::string & instrumentType () const
 
const std::vector< QuantLib::ext::shared_ptr< CalibrationInstrument > > & instruments () const
 
const std::string & parameter () 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

std::vector< QuantLib::ext::shared_ptr< CalibrationInstrument > > instruments_
 
std::string instrumentType_
 
std::string parameter_
 The parameter tag may be given so that builders know how to use the calibration basket. More...
 
void fromXML (XMLNode *node) override
 
XMLNodetoXML (XMLDocument &doc) const override
 
bool empty () const
 Returns true if the calibration basket is empty. More...
 

Detailed Description

Class for holding calibration instruments of the same type for a model.

If you need to calibrate a model to instruments of different types, use multiple calibration baskets.

Definition at line 59 of file calibrationbasket.hpp.

Constructor & Destructor Documentation

◆ CalibrationBasket() [1/2]

Default constructor, empty calibration basket.

Definition at line 35 of file calibrationbasket.cpp.

35{}

◆ CalibrationBasket() [2/2]

CalibrationBasket ( const std::vector< QuantLib::ext::shared_ptr< CalibrationInstrument > > &  instruments)

Detailed constructor.

Definition at line 37 of file calibrationbasket.cpp.

39
40 // Check that all instruments in the basket, if any, are the same type.
41 for (const auto& instrument : instruments_) {
42 string instType = instrument->instrumentType();
43 if (instrumentType_.empty()) {
44 instrumentType_ = instType;
45 } else {
46 QL_REQUIRE(instrumentType_ == instType, "All instruments in CalibrationBasket should have the same " <<
47 "instrument type. Have " << instrumentType_ << " but current instrument is " << instType << ".");
48 }
49 }
50
51}
std::vector< QuantLib::ext::shared_ptr< CalibrationInstrument > > instruments_
const std::vector< QuantLib::ext::shared_ptr< CalibrationInstrument > > & instruments() const

Member Function Documentation

◆ instrumentType()

const string & instrumentType ( ) const

Definition at line 53 of file calibrationbasket.cpp.

53 {
54 return instrumentType_;
55}
+ Here is the caller graph for this function:

◆ instruments()

const vector< QuantLib::ext::shared_ptr< CalibrationInstrument > > & instruments ( ) const

Definition at line 57 of file calibrationbasket.cpp.

57 {
58 return instruments_;
59}
+ Here is the caller graph for this function:

◆ parameter()

const string & parameter ( ) const

Definition at line 61 of file calibrationbasket.cpp.

61 {
62 return parameter_;
63}
std::string parameter_
The parameter tag may be given so that builders know how to use the calibration basket.

◆ fromXML()

void fromXML ( XMLNode node)
overridevirtual

Implements XMLSerializable.

Definition at line 65 of file calibrationbasket.cpp.

65 {
66
67 QL_REQUIRE(empty(), "The calibration basket should be empty before calling fromXML.");
68 XMLUtils::checkNode(node, "CalibrationBasket");
69
70 for (XMLNode* cn = XMLUtils::getChildNode(node); cn; cn = XMLUtils::getNextSibling(cn)) {
71
72 // Take the instrument type from the first node name.
73 // All subsequent nodes should have the same instrument type.
74 string name = XMLUtils::getNodeName(cn);
75 if (instrumentType_.empty()) {
77 } else {
78 QL_REQUIRE(instrumentType_ == name, "All instruments in CalibrationBasket should have " <<
79 "the same instrument type. Have " << instrumentType_ << " but current node is " << name << ".");
80 }
81
82 // Create an instance of the calibration instrument and read it from XML.
83 auto instrument = CalibrationInstrumentFactory::instance().build(instrumentType_);
84 QL_REQUIRE(instrument, "Calibration instrument type " << instrumentType_ <<
85 " has not been registered with the calibration instrument factory.");
86 instrument->fromXML(cn);
87
88 // Add the instrument to the basket.
89 instruments_.push_back(instrument);
90 }
91
92 QL_REQUIRE(!empty(), "The calibration basket should have at least one calibration instrument.");
93
94 parameter_ = XMLUtils::getAttribute(node, "parameter");
95}
bool empty() const
Returns true if the calibration basket is empty.
static string getAttribute(XMLNode *node, const string &attrName)
Definition: xmlutils.cpp:419
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 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
rapidxml::xml_node< char > XMLNode
Definition: xmlutils.hpp:60
string name
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ toXML()

XMLNode * toXML ( XMLDocument doc) const
overridevirtual

Implements XMLSerializable.

Definition at line 97 of file calibrationbasket.cpp.

97 {
98
99 XMLNode* node = doc.allocNode("CalibrationBasket");
100
101 if (!parameter_.empty())
102 XMLUtils::addAttribute(doc, node, "parameter", parameter_);
103
104 for (const auto& instrument : instruments_) {
105 XMLUtils::appendNode(node, instrument->toXML(doc));
106 }
107
108 return node;
109}
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
+ Here is the call graph for this function:

◆ empty()

bool empty ( ) const

Returns true if the calibration basket is empty.

Definition at line 111 of file calibrationbasket.cpp.

111 {
112 return instruments_.empty();
113}
+ Here is the caller graph for this function:

Member Data Documentation

◆ instruments_

std::vector<QuantLib::ext::shared_ptr<CalibrationInstrument> > instruments_
private

Definition at line 84 of file calibrationbasket.hpp.

◆ instrumentType_

std::string instrumentType_
private

Definition at line 85 of file calibrationbasket.hpp.

◆ parameter_

std::string parameter_
private

The parameter tag may be given so that builders know how to use the calibration basket.

Definition at line 87 of file calibrationbasket.hpp.