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

Serializable object holding premium data. More...

#include <ored/portfolio/premiumdata.hpp>

+ Inheritance diagram for PremiumData:
+ Collaboration diagram for PremiumData:

Classes

struct  PremiumDatum
 

Public Member Functions

 PremiumData ()
 
 PremiumData (double amount, const string &ccy, const QuantLib::Date &payDate)
 
 PremiumData (const std::vector< PremiumDatum > &premiumData)
 
QuantLib::Date latestPremiumDate () const
 
Inspectors
const std::vector< PremiumDatum > & premiumData () 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< PremiumDatumpremiumData_
 
virtual void fromXML (XMLNode *node) override
 
virtual XMLNodetoXML (XMLDocument &doc) const override
 

Detailed Description

Serializable object holding premium data.

Definition at line 37 of file premiumdata.hpp.

Constructor & Destructor Documentation

◆ PremiumData() [1/3]

Definition at line 48 of file premiumdata.hpp.

48{}

◆ PremiumData() [2/3]

PremiumData ( double  amount,
const string &  ccy,
const QuantLib::Date &  payDate 
)

Definition at line 49 of file premiumdata.hpp.

50 : premiumData_(1, PremiumDatum(amount, ccy, payDate)) {}
std::vector< PremiumDatum > premiumData_
Definition: premiumdata.hpp:67

◆ PremiumData() [3/3]

PremiumData ( const std::vector< PremiumDatum > &  premiumData)
explicit

Definition at line 51 of file premiumdata.hpp.

const std::vector< PremiumDatum > & premiumData() const
Definition: premiumdata.hpp:57

Member Function Documentation

◆ latestPremiumDate()

QuantLib::Date latestPremiumDate ( ) const

Definition at line 28 of file premiumdata.cpp.

28 {
29 QuantLib::Date latestPaymentDate = Date::minDate();
30
31 for (const PremiumDatum& d : premiumData_)
32 latestPaymentDate = std::max(latestPaymentDate, d.payDate);
33
34 return latestPaymentDate;
35}
+ Here is the caller graph for this function:

◆ premiumData()

const std::vector< PremiumDatum > & premiumData ( ) const

Definition at line 57 of file premiumdata.hpp.

57{ return premiumData_; }
+ Here is the caller graph for this function:

◆ fromXML()

void fromXML ( XMLNode node)
overridevirtual

Implements XMLSerializable.

Definition at line 37 of file premiumdata.cpp.

37 {
38
39 // support deprecated variant, where data is given in single fields under the root node
40
41 auto depr_amount_node = XMLUtils::getChildNode(node, "PremiumAmount");
42 auto depr_ccy_node = XMLUtils::getChildNode(node, "PremiumCurrency");
43 auto depr_date_node = XMLUtils::getChildNode(node, "PremiumPayDate");
44
45 if (depr_amount_node != nullptr) {
46 std::string amountStr = XMLUtils::getNodeValue(depr_amount_node);
47 if (!amountStr.empty()) {
48 double amount = parseReal(amountStr);
49 if (!close_enough(amount, 0.0)) {
50 QL_REQUIRE(depr_ccy_node, "PremiumAmount (" << amount << ") given, but no PremiumCurrency");
51 QL_REQUIRE(depr_date_node, "PremiumAmount (" << amount << ") given, but no PremiumPayDate");
52 std::string ccyStr = XMLUtils::getNodeValue(depr_ccy_node);
53 std::string dateStr = XMLUtils::getNodeValue(depr_date_node);
54 QL_REQUIRE(!ccyStr.empty(), "PremiumAmount (" << amount << ") given, but no PremiumCurrency");
55 QL_REQUIRE(!dateStr.empty(), "PremiumAmount (" << amount << ") given, but no PremiumPayDate");
56 premiumData_.emplace_back(amount, ccyStr, parseDate(dateStr));
57 }
58 }
59 }
60
61 // standard variant, data is given in Premium nodes under Premiums root node
62
63 if (auto p = XMLUtils::getChildNode(node, "Premiums")) {
64 QL_REQUIRE(premiumData_.empty(), "Single PremiumAmount and Premiums node are not allowed simultaneously. Move "
65 "the single premium to the Premiums node instead.");
66 for (auto n : XMLUtils::getChildrenNodes(p, "Premium")) {
67 PremiumDatum d;
68 d.amount = XMLUtils::getChildValueAsDouble(n, "Amount", true);
69 d.ccy = XMLUtils::getChildValue(n, "Currency", true);
70 d.payDate = parseDate(XMLUtils::getChildValue(n, "PayDate", true));
71 premiumData_.push_back(d);
72 }
73 }
74}
static vector< XMLNode * > getChildrenNodes(XMLNode *node, const string &name)
Returns all the children with a given name.
Definition: xmlutils.cpp:428
static Real getChildValueAsDouble(XMLNode *node, const string &name, bool mandatory=false, double defaultValue=0.0)
Definition: xmlutils.cpp:286
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 string getNodeValue(XMLNode *node)
Get a node's value.
Definition: xmlutils.cpp:489
Date parseDate(const string &s)
Convert std::string to QuantLib::Date.
Definition: parsers.cpp:51
Real parseReal(const string &s)
Convert text to Real.
Definition: parsers.cpp:112
Filter close_enough(const RandomVariable &x, const RandomVariable &y)
+ 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 76 of file premiumdata.cpp.

76 {
77 XMLNode* node = doc.allocNode("Premiums");
78 for (auto const& d : premiumData_) {
79 XMLNode* p = XMLUtils::addChild(doc, node, "Premium");
80 XMLUtils::addChild(doc, p, "Amount", d.amount);
81 XMLUtils::addChild(doc, p, "Currency", d.ccy);
82 XMLUtils::addChild(doc, p, "PayDate", ore::data::to_string(d.payDate));
83 }
84 return node;
85}
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:
+ Here is the caller graph for this function:

Member Data Documentation

◆ premiumData_

std::vector<PremiumDatum> premiumData_
private

Definition at line 67 of file premiumdata.hpp.