27#include <qle/cashflows/formulabasedcoupon.hpp>
35#include <ql/cashflows/capflooredcoupon.hpp>
36#include <ql/cashflows/cashflowvectors.hpp>
37#include <ql/cashflows/cmscoupon.hpp>
38#include <ql/cashflows/cpicoupon.hpp>
39#include <ql/cashflows/fixedratecoupon.hpp>
40#include <ql/cashflows/iborcoupon.hpp>
41#include <ql/cashflows/overnightindexedcoupon.hpp>
42#include <ql/cashflows/simplecashflow.hpp>
43#include <ql/cashflows/yoyinflationcoupon.hpp>
44#include <ql/experimental/coupons/strippedcapflooredcoupon.hpp>
46#include <boost/make_shared.hpp>
75 std::vector<std::string> variables;
77 indices_.insert(variables.begin(), variables.end());
81QuantLib::ext::shared_ptr<QuantLib::FloatingRateCouponPricer>
82getFormulaBasedCouponPricer(
const QuantLib::ext::shared_ptr<QuantExt::FormulaBasedIndex>& formulaBasedIndex,
83 const Currency& paymentCurrency,
const QuantLib::ext::shared_ptr<EngineFactory>& engineFactory,
84 const std::map<std::string, QuantLib::ext::shared_ptr<QuantLib::InterestRateIndex>>& indexMaps) {
86 QuantLib::ext::dynamic_pointer_cast<FormulaBasedCouponPricerBuilder>(engineFactory->builder(
"FormulaBasedCoupon"));
87 QL_REQUIRE(builder !=
nullptr,
"makeFormulaBasedLeg(): no builder found for FormulaBasedCoupon");
89 std::map<std::string, QuantLib::ext::shared_ptr<IborCouponPricer>> iborPricers;
90 std::map<std::string, QuantLib::ext::shared_ptr<CmsCouponPricer>> cmsPricers;
91 for (
auto const& i : formulaBasedIndex->indices()) {
93 if (
auto ibor = QuantLib::ext::dynamic_pointer_cast<QuantLib::IborIndex>(i)) {
94 auto iborBuilder = QuantLib::ext::dynamic_pointer_cast<CapFlooredIborLegEngineBuilder>(
95 engineFactory->builder(
"CapFlooredIborLeg"));
96 QL_REQUIRE(iborBuilder !=
nullptr,
"makeFormulaBasedLeg(): No builder found for CapFlooredIborLeg");
97 auto pricerKey = IndexNameTranslator::instance().oreName(ibor->name());
98 auto iborPricer = QuantLib::ext::dynamic_pointer_cast<IborCouponPricer>(iborBuilder->engine(pricerKey));
99 QL_REQUIRE(iborPricer !=
nullptr,
"makeFormulaBasedLeg(): expected ibor coupon pricer");
100 iborPricers[i->name()] = iborPricer;
103 if (
auto cms = QuantLib::ext::dynamic_pointer_cast<QuantLib::SwapIndex>(i)) {
104 auto cmsBuilder = QuantLib::ext::dynamic_pointer_cast<CmsCouponPricerBuilder>(engineFactory->builder(
"CMS"));
105 QL_REQUIRE(cmsBuilder,
"makeFormulaBasedLeg(): No builder found for CmsLeg");
106 auto pricerKey = IndexNameTranslator::instance().oreName(cms->iborIndex()->name());
107 auto cmsPricer = QuantLib::ext::dynamic_pointer_cast<CmsCouponPricer>(cmsBuilder->engine(pricerKey));
108 QL_REQUIRE(cmsPricer !=
nullptr,
"makeFormulaBasedLeg(): expected cms coupon pricer");
109 cmsPricers[cms->iborIndex()->name()] = cmsPricer;
113 return builder->engine(paymentCurrency.code(), iborPricers, cmsPricers, indexMaps);
118 const QuantLib::ext::shared_ptr<EngineFactory>& engineFactory,
119 const std::map<std::string, QuantLib::ext::shared_ptr<QuantLib::InterestRateIndex>>& indexMaps,
120 const QuantLib::Date& openEndDateReplacement) {
121 auto formulaBasedData = QuantLib::ext::dynamic_pointer_cast<FormulaBasedLegData>(
data.concreteLegData());
122 QL_REQUIRE(formulaBasedData,
"Wrong LegType, expected FormulaBased, got " <<
data.legType());
125 if (schedule.size() < 2)
127 Calendar paymentCalendar;
128 if (
data.paymentCalendar().empty())
129 paymentCalendar = schedule.calendar();
134 QL_REQUIRE(
data.dayCounter() !=
"",
"makeFormulaBasedLeg(): day counter must be given");
139 auto formulaBasedLegData = QuantLib::ext::dynamic_pointer_cast<FormulaBasedLegData>(
data.concreteLegData());
144 for (
auto const& amort :
data.amortizationData()) {
145 if (!amort.initialized())
149 "AmortizationType " << amort.type() <<
" not supported for Formula based legs");
152 QuantExt::FormulaBasedLeg formulaBasedLeg =
153 QuantExt::FormulaBasedLeg(paymentCurrency, schedule, formulaBasedIndex)
154 .withNotionals(notionals)
155 .withPaymentCalendar(paymentCalendar)
157 .withPaymentDayCounter(dc)
158 .withPaymentAdjustment(bdc)
159 .withFixingDays(formulaBasedData->fixingDays())
160 .inArrears(formulaBasedData->isInArrears());
162 auto couponPricer = getFormulaBasedCouponPricer(formulaBasedIndex, paymentCurrency, engineFactory, indexMaps);
165 Leg tmp = formulaBasedLeg;
builder that returns an engine to price capped floored ibor legs
std::set< std::string > indices_
const string & legNodeName() const
Serializable object holding leg data.
Small XML Document wrapper class.
XMLNode * allocNode(const string &nodeName)
util functions that wrap rapidxml
static void checkNode(XMLNode *n, const string &expectedName)
static string getChildValue(XMLNode *node, const string &name, bool mandatory=false, const string &defaultValue=string())
static bool getChildValueAsBool(XMLNode *node, const string &name, bool mandatory=false, bool defaultValue=true)
static XMLNode * getChildNode(XMLNode *n, const string &name="")
static int getChildValueAsInt(XMLNode *node, const string &name, bool mandatory=false, int defaultValue=0)
static XMLNode * addChild(XMLDocument &doc, XMLNode *n, const string &name)
builder that returns an engine to price capped floored ibor legs
void setCouponPricer(const Leg &leg, const boost::shared_ptr< FloatingRateCouponPricer > &)
Calendar parseCalendar(const string &s)
Convert text to QuantLib::Calendar.
Currency parseCurrency(const string &s)
Convert text to QuantLib::Currency.
BusinessDayConvention parseBusinessDayConvention(const string &s)
Convert text to QuantLib::BusinessDayConvention.
PaymentLag parsePaymentLag(const string &s)
Convert text to PaymentLag.
DayCounter parseDayCounter(const string &s)
Convert text to QuantLib::DayCounter.
translates between QuantLib::Index::name() and ORE names
leg data model and serialization
Classes and functions for log message handling.
QuantExt::CompiledFormula parseFormula(const std::string &text, std::vector< std::string > &variables)
void applyAmortization(std::vector< Real > ¬ionals, const LegData &data, const Schedule &schedule, const bool annuityAllowed, const std::vector< Real > &rates)
vector< T > buildScheduledVector(const vector< T > &values, const vector< string > &dates, const Schedule &schedule, const bool checkAllValuesAppearInResult=false)
AmortizationType parseAmortizationType(const std::string &s)
boost::variant< QuantLib::Period, QuantLib::Natural > PaymentLag
Leg makeFormulaBasedLeg(const LegData &data, const QuantLib::ext::shared_ptr< QuantExt::FormulaBasedIndex > &formulaBasedIndex, const QuantLib::ext::shared_ptr< EngineFactory > &engineFactory, const std::map< std::string, QuantLib::ext::shared_ptr< QuantLib::InterestRateIndex > > &indexMaps, const QuantLib::Date &openEndDateReplacement)
Schedule makeSchedule(const ScheduleDates &data)
Serializable Credit Default Swap.