26#include <ql/cashflows/simplecashflow.hpp>
29#include <boost/algorithm/string/predicate.hpp>
30#include <boost/make_shared.hpp>
42using QuantLib::Natural;
53 if (iequals(s,
"CalculationPeriodEndDate")) {
55 }
else if (iequals(s,
"CalculationPeriodStartDate")) {
57 }
else if (iequals(s,
"TerminationDate")) {
59 }
else if (iequals(s,
"FutureExpiryDate")) {
62 QL_FAIL(
"Could not parse " << s <<
" to CommodityPayRelativeTo");
68 return out <<
"CalculationPeriodEndDate";
70 return out <<
"CalculationPeriodStartDate";
72 return out <<
"TerminationDate";
74 return out <<
"FutureExpiryDate";
76 QL_FAIL(
"Do not recognise CommodityPayRelativeTo " <<
static_cast<int>(cprt));
81 if (iequals(s,
"Spot")) {
83 }
else if (iequals(s,
"FutureSettlement")) {
86 QL_FAIL(
"Could not parse " << s <<
" to CommodityPriceType");
94 return out <<
"FutureSettlement";
96 QL_FAIL(
"Do not recognise CommodityPriceType " <<
static_cast<int>(cpt));
101 if (iequals(s,
"FutureExpiryDate")) {
103 }
else if (iequals(s,
"None")) {
106 QL_FAIL(
"Could not parse " << s <<
" to CommodityPricingDateRule");
112 return out <<
"FutureExpiryDate";
114 return out <<
"None";
116 QL_FAIL(
"Do not recognise CommodityPricingDateRule " <<
static_cast<int>(cpdr));
125 const vector<Real>& prices,
const vector<string>& priceDates,
127 :
LegAdditionalData(
"CommodityFixed"), quantities_(quantities), quantityDates_(quantityDates), prices_(prices),
128 priceDates_(priceDates), commodityPayRelativeTo_(commodityPayRelativeTo), tag_(tag) {}
141 quantities_ = XMLUtils::getChildrenValuesWithAttributes<Real>(node,
"Quantities",
"Quantity",
145 prices_ = XMLUtils::getChildrenValuesWithAttributes<Real>(node,
"Prices",
"Price",
"startDate",
priceDates_,
177 pricingLag_(0), isAveraged_(false), isInArrears_(true), futureMonthOffset_(0),
178 deliveryRollDays_(0), includePeriodEnd_(true), excludePeriodStart_(true),
179 hoursPerDay_(Null<Natural>()), useBusinessDays_(true), dailyExpiryOffset_(0),
180 unrealisedQuantity_(false), lastNDays_(Null<Natural>()), fxIndex_(
"") {}
185 CommodityPayRelativeTo commodityPayRelativeTo,
const vector<Real>& spreads,
const vector<string>& spreadDates,
187 const string& pricingCalendar, Natural pricingLag,
const vector<string>&
pricingDates,
bool isAveraged,
188 bool isInArrears, Natural futureMonthOffset, Natural deliveryRollDays,
bool includePeriodEnd,
189 bool excludePeriodStart, Natural hoursPerDay,
bool useBusinessDays,
const string& tag,
190 Natural dailyExpiryOffset,
bool unrealisedQuantity, QuantLib::Natural lastNDays, std::string fxIndex)
191 :
LegAdditionalData(
"CommodityFloating"), name_(
name), priceType_(priceType), quantities_(quantities),
192 quantityDates_(quantityDates), commodityQuantityFrequency_(commodityQuantityFrequency),
193 commodityPayRelativeTo_(commodityPayRelativeTo), spreads_(spreads), spreadDates_(spreadDates),
194 gearings_(gearings), gearingDates_(gearingDates), pricingDateRule_(pricingDateRule),
195 pricingCalendar_(pricingCalendar), pricingLag_(pricingLag), pricingDates_(
pricingDates), isAveraged_(isAveraged),
196 isInArrears_(isInArrears), futureMonthOffset_(futureMonthOffset), deliveryRollDays_(deliveryRollDays),
197 includePeriodEnd_(includePeriodEnd), excludePeriodStart_(excludePeriodStart), hoursPerDay_(hoursPerDay),
198 useBusinessDays_(useBusinessDays), tag_(tag), dailyExpiryOffset_(dailyExpiryOffset),
199 unrealisedQuantity_(unrealisedQuantity), lastNDays_(lastNDays), fxIndex_(fxIndex) {
210 quantities_ = XMLUtils::getChildrenValuesWithAttributes<Real>(node,
"Quantities",
"Quantity",
"startDate",
223 spreads_ = XMLUtils::getChildrenValuesWithAttributes<Real>(node,
"Spreads",
"Spread",
"startDate",
spreadDates_,
225 gearings_ = XMLUtils::getChildrenValuesWithAttributes<Real>(node,
"Gearings",
"Gearing",
"startDate",
gearingDates_,
CommodityFixedLegData()
Default constructor.
void setQuantities(const std::vector< QuantLib::Real > &quantities)
Set the fixed leg data quantities.
std::vector< std::string > priceDates_
void fromXML(ore::data::XMLNode *node) override
std::vector< std::string > quantityDates_
ore::data::XMLNode * toXML(ore::data::XMLDocument &doc) const override
std::vector< QuantLib::Real > prices_
std::vector< QuantLib::Real > quantities_
CommodityPayRelativeTo commodityPayRelativeTo_
const std::vector< QuantLib::Real > & quantities() const
CommodityFloatingLegData()
Default constructor.
QuantExt::CommodityQuantityFrequency commodityQuantityFrequency_
QuantLib::Natural lastNDays_
void fromXML(ore::data::XMLNode *node) override
CommodityPriceType priceType_
std::vector< std::string > pricingDates_
CommodityPricingDateRule pricingDateRule_
std::vector< std::string > gearingDates_
QuantLib::Natural futureMonthOffset_
QuantLib::Natural hoursPerDay_
QuantLib::Natural dailyExpiryOffset_
std::vector< std::string > quantityDates_
ore::data::XMLNode * toXML(ore::data::XMLDocument &doc) const override
std::vector< QuantLib::Real > quantities_
std::string pricingCalendar_
std::vector< std::string > spreadDates_
CommodityPayRelativeTo commodityPayRelativeTo_
std::vector< QuantLib::Real > spreads_
std::vector< QuantLib::Real > gearings_
QuantLib::Natural deliveryRollDays_
QuantLib::Natural pricingLag_
Serializable Additional Leg Data.
std::set< std::string > indices_
Small XML Document wrapper class.
XMLNode * allocNode(const string &nodeName)
util functions that wrap rapidxml
static void addChildren(XMLDocument &doc, XMLNode *n, const string &names, const string &name, const vector< T > &values)
static void checkNode(XMLNode *n, const string &expectedName)
static string getChildValue(XMLNode *node, const string &name, bool mandatory=false, const string &defaultValue=string())
static XMLNode * getChildNode(XMLNode *n, const string &name="")
static void addChildrenWithOptionalAttributes(XMLDocument &doc, XMLNode *n, const string &names, const string &name, const vector< T > &values, const string &attrName, const vector< string > &attrs)
static string getNodeValue(XMLNode *node)
Get a node's value.
static int getChildValueAsInt(XMLNode *node, const string &name, bool mandatory=false, int defaultValue=0)
static vector< string > getChildrenValues(XMLNode *node, const string &names, const string &name, bool mandatory=false)
static XMLNode * addChild(XMLDocument &doc, XMLNode *n, const string &name)
leg data for commodity leg types
bool parseBool(const string &s)
Convert text to bool.
Real parseReal(const string &s)
Convert text to Real.
Integer parseInteger(const string &s)
Convert text to QuantLib::Integer.
leg data model and serialization
Classes and functions for log message handling.
CommodityQuantityFrequency
std::ostream & operator<<(std::ostream &out, EquityReturnType t)
set< Date > pricingDates(const Date &s, const Date &e, const Calendar &pricingCalendar, bool excludeStart, bool includeEnd, bool useBusinessDays)
CommodityPricingDateRule parseCommodityPricingDateRule(const string &s)
@ CalculationPeriodStartDate
@ CalculationPeriodEndDate
CommodityPriceType parseCommodityPriceType(const string &s)
CommodityPayRelativeTo parseCommodityPayRelativeTo(const string &s)
std::string to_string(const LocationInfo &l)
CommodityQuantityFrequency parseCommodityQuantityFrequency(const string &s)
Convert text to QuantExt::CommodityQuantityFrequency.
Serializable Credit Default Swap.
Map text representations to QuantLib/QuantExt types.
string conversion utilities