25#include <ql/cashflows/simplecashflow.hpp>
28#include <boost/algorithm/string/predicate.hpp>
29#include <boost/make_shared.hpp>
42using QuantLib::Natural;
61 QL_REQUIRE(equityNode,
"no equityLegData provided");
63 QuantLib::ext::shared_ptr<ore::data::EquityLegData> ld = QuantLib::ext::make_shared<EquityLegData>();
64 ld->fromXML(equityNode);
80 const QuantLib::ext::shared_ptr<QuantExt::FxIndex>& fxIndex,
81 const QuantLib::Date& openEndDateReplacement) {
82 QuantLib::ext::shared_ptr<EquityMarginLegData> eqMarginLegData = QuantLib::ext::dynamic_pointer_cast<EquityMarginLegData>(
data.concreteLegData());
83 QL_REQUIRE(eqMarginLegData,
"Wrong LegType, expected EquityMargin, got " <<
data.legType());
84 QuantLib::ext::shared_ptr<ore::data::EquityLegData> eqLegData = eqMarginLegData->equityLegData();
85 QL_REQUIRE(eqLegData,
"expected equityLegData");
86 QuantExt::Schedule schedule =
makeSchedule(
data.schedule(), openEndDateReplacement);
89 bool isTotalReturn = eqLegData->returnType() == EquityReturnType::Total;
90 Real dividendFactor = eqLegData->dividendFactor();
91 Real initialPrice = eqLegData->initialPrice();
92 bool initialPriceIsInTargetCcy =
false;
94 if (!eqLegData->initialPriceCurrency().empty()) {
100 if (!equityCurve->currency().empty())
101 eqCurrency = equityCurve->currency();
103 TLOG(
"Cannot find currency for equity " << equityCurve->name());
106 QL_REQUIRE(initialPriceCurrency == dataCurrency ||
107 initialPriceCurrency == eqCurrency || eqCurrency.empty(),
108 "initial price ccy (" << initialPriceCurrency <<
") must match either leg ccy ("
109 << dataCurrency <<
") or equity ccy (if given, got '"
110 << eqCurrency <<
"')");
111 initialPriceIsInTargetCcy = initialPriceCurrency == dataCurrency;
115 bool notionalReset = eqLegData->notionalReset();
116 Natural fixingDays = eqLegData->fixingDays();
118 ScheduleData valuationData = eqLegData->valuationSchedule();
119 Schedule valuationSchedule;
121 valuationSchedule =
makeSchedule(valuationData, openEndDateReplacement);
123 vector<double> rates =
buildScheduledVector(eqMarginLegData->rates(), eqMarginLegData->rateDates(), schedule);
143 QL_REQUIRE(leg.size() > 0,
"Empty Equity Margin Leg");
EquityMarginLeg & withPaymentLag(Natural paymentLag)
EquityMarginLeg & withQuantity(Real)
EquityMarginLeg & withNotionalReset(bool)
EquityMarginLeg & withNotionals(const std::vector< Real > ¬ionals)
EquityMarginLeg & withFixingDays(Natural)
EquityMarginLeg & withDividendFactor(Real)
EquityMarginLeg & withInitialPrice(Real)
EquityMarginLeg & withInitialPriceIsInTargetCcy(bool)
EquityMarginLeg & withPaymentAdjustment(BusinessDayConvention convention)
EquityMarginLeg & withTotalReturn(bool)
EquityMarginLeg & withPaymentDayCounter(const DayCounter &dayCounter)
EquityMarginLeg & withMultiplier(Real)
EquityMarginLeg & withValuationSchedule(const Schedule &valuationSchedule)
EquityMarginLeg & withInitialMarginFactor(const Real &marginFactor)
EquityMarginLeg & withCouponRates(Rate, const DayCounter &paymentDayCounter, Compounding comp=Simple, Frequency freq=Annual)
virtual void fromXML(ore::data::XMLNode *node) override
QuantLib::ext::shared_ptr< ore::data::EquityLegData > equityLegData_
double initialMarginFactor_
vector< string > rateDates_
virtual ore::data::XMLNode * toXML(ore::data::XMLDocument &doc) const override
const string & legNodeName() const
Serializable object holding leg data.
Serializable schedule data.
bool hasData() const
Check if has any dates/rules/derived schedules.
Small XML Document wrapper class.
XMLNode * allocNode(const string &nodeName)
util functions that wrap rapidxml
static void checkNode(XMLNode *n, const string &expectedName)
static Real getChildValueAsDouble(XMLNode *node, const string &name, bool mandatory=false, double defaultValue=0.0)
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 XMLNode * addChild(XMLDocument &doc, XMLNode *n, const string &name)
static void appendNode(XMLNode *parent, XMLNode *child)
leg data for equityfx leg types
Currency parseCurrencyWithMinors(const string &s)
Convert text to QuantLib::Currency.
QuantLib::Real convertMinorToMajorCurrency(const std::string &s, QuantLib::Real value)
Convert a value from a minor ccy to major.
BusinessDayConvention parseBusinessDayConvention(const string &s)
Convert text to QuantLib::BusinessDayConvention.
bool parseBool(const string &s)
Convert text to bool.
PaymentLag parsePaymentLag(const string &s)
Convert text to PaymentLag.
Real parseReal(const string &s)
Convert text to Real.
DayCounter parseDayCounter(const string &s)
Convert text to QuantLib::DayCounter.
leg data model and serialization
Classes and functions for log message handling.
#define TLOG(text)
Logging Macro (Level = Data)
void applyAmortization(std::vector< Real > ¬ionals, const LegData &data, const Schedule &schedule, const bool annuityAllowed, const std::vector< Real > &rates)
QuantExt::Leg makeEquityMarginLeg(const LegData &data, const QuantLib::ext::shared_ptr< EquityIndex2 > &equityCurve, const QuantLib::ext::shared_ptr< QuantExt::FxIndex > &fxIndex, const QuantLib::Date &openEndDateReplacement)
std::string to_string(const LocationInfo &l)
vector< T > buildScheduledVector(const vector< T > &values, const vector< string > &dates, const Schedule &schedule, const bool checkAllValuesAppearInResult=false)
boost::variant< QuantLib::Period, QuantLib::Natural > PaymentLag
Schedule makeSchedule(const ScheduleDates &data)
Serializable Credit Default Swap.
Map text representations to QuantLib/QuantExt types.
string conversion utilities