21#include <ql/cashflows/couponpricer.hpp>
22#include <ql/cashflows/fixedratecoupon.hpp>
23#include <ql/cashflows/iborcoupon.hpp>
25#include <boost/make_shared.hpp>
32 const std::vector<Real>& floatingNominal,
const Schedule& fixedSchedule,
33 const std::vector<Real>& fixedRate,
const DayCounter& fixedDayCount,
34 const Schedule& floatingSchedule,
const QuantLib::ext::shared_ptr<IborIndex>& iborIndex,
35 const std::vector<Real>& gearing,
const std::vector<Spread>& spread,
36 const std::vector<Real>& cappedRate,
const std::vector<Real>& flooredRate,
37 const DayCounter& floatingDayCount,
const std::vector<Real>& lowerNotionalBound,
38 const QuantLib::Position::Type optionPosition,
const std::vector<bool>& notionalCanBeDecreased,
39 boost::optional<BusinessDayConvention> paymentConvention)
40 : Swap(2), type_(type), fixedNominal_(fixedNominal), floatingNominal_(floatingNominal),
41 fixedSchedule_(fixedSchedule), fixedRate_(fixedRate), fixedDayCount_(fixedDayCount),
42 floatingSchedule_(floatingSchedule), iborIndex_(iborIndex), gearing_(gearing),
spread_(spread),
43 cappedRate_(cappedRate), flooredRate_(flooredRate), floatingDayCount_(floatingDayCount),
44 lowerNotionalBound_(lowerNotionalBound), optionPosition_(optionPosition),
45 notionalCanBeDecreased_(notionalCanBeDecreased) {
53 QL_REQUIRE(
fixedNominal.size() > 0,
"FixedNominal size is zero");
55 "Fixed nominal size (" <<
fixedNominal.size() <<
") must divide floating nominal size ("
58 <<
") does not match fixed rate size ("
61 "Fixed nominal size (" <<
fixedNominal_.size() <<
") does not match schedule size ("
64 "Fixed nominal size (" <<
fixedNominal_.size() <<
") does not match lowerNotionalBound size ("
68 "Floating nominal size (" <<
floatingNominal_.size() <<
") does not match schedule size ("
72 "Floating nominal size (" <<
floatingNominal_.size() <<
") does not match gearing size ("
75 <<
") does not match spread size ("
78 "Floating nominal size (" <<
floatingNominal_.size() <<
") does not match spread size ("
81 "Floating nominal size (" <<
floatingNominal_.size() <<
") does not match spread size ("
94 std::vector<Real> gearingTmp(
gearing_);
95 for (Size i = 0; i < gearingTmp.size(); ++i) {
96 if (close(gearingTmp[i], 0.0))
97 gearingTmp[i] = QL_EPSILON;
110 .withGearings(gearingTmp)
114 for (Leg::const_iterator i = legs_[1].begin(); i < legs_[1].end(); ++i)
117 auto cpnPricer = QuantLib::ext::make_shared<BlackIborCouponPricer>();
121 case VanillaSwap::Payer:
125 case VanillaSwap::Receiver:
130 QL_FAIL(
"Unknown vanilla swap type");
135 Swap::setupArguments(args);
156 const Leg& fixedCoupons =
fixedLeg();
161 for (Size i = 0; i < fixedCoupons.size(); ++i) {
162 auto coupon = QuantLib::ext::dynamic_pointer_cast<FixedRateCoupon>(fixedCoupons[i]);
163 QL_REQUIRE(coupon !=
nullptr,
"FlexiSwap::setupArguments(): expected fixed rate coupon");
172 std::vector<Date>(floatingCoupons.size());
178 for (Size i = 0; i < floatingCoupons.size(); ++i) {
179 auto coupon = QuantLib::ext::dynamic_pointer_cast<FloatingRateCoupon>(floatingCoupons[i]);
180 QL_REQUIRE(coupon !=
nullptr,
"FlexiSwap::setupArguments(): expected fixed rate coupon");
189 }
catch (
const std::exception&) {
197 QL_REQUIRE(
underlyingValue_ != Null<Real>(),
"FlexiSwap: underlying value not provided");
202 Swap::setupExpired();
207 Swap::fetchResults(r);
220 Swap::arguments::validate();
222 bool hasOptionality =
false;
223 Date today = Settings::instance().evaluationDate();
225 for (Size j = 0; j < ratio; ++j) {
227 "FlexiSwap::arguments::validate(): fixedNominal["
228 << i <<
"] = " <<
fixedNominal[i] <<
" does not match floatingNominal[" << i * ratio + j
229 <<
"] = " <<
floatingNominal[i * ratio + j] <<
", ratio is " << ratio);
233 "FlexiSwap::arguments::validate(): lowerNotionalBound[" << i <<
"] = " <<
lowerNotionalBound[i]
234 <<
" must be leq fixedNominal[" << i
238 if (i > 0 && hasOptionality) {
241 "FlexiSwap::arguments::validate(): lowerNotionalBound["
242 << i - 1 <<
"] = " <<
lowerNotionalBound[i - 1] <<
" < lowerNotionalBound[" << i <<
"] = "
243 <<
lowerNotionalBound[i] <<
", not allowed, since optionality has kicked in already");
246 "FlexiSwap::arguments::validate(): fixedNominal["
247 << i - 1 <<
"] = " <<
fixedNominal[i - 1] <<
" < fixedNominal[" << i
248 <<
"] = " <<
fixedNominal[i] <<
", not allowed, since optionality has kicked in already");
254 Swap::results::reset();
std::vector< Real > cappedRate
std::vector< Date > floatingResetDates
QuantLib::ext::shared_ptr< IborIndex > iborIndex
std::vector< Real > floatingGearings
std::vector< Real > floatingSpreads
std::vector< Date > floatingFixingDates
std::vector< Real > flooredRate
std::vector< Date > fixedPayDates
std::vector< Real > fixedNominal
std::vector< Date > fixedResetDates
std::vector< Real > floatingNominal
QuantLib::Position::Type optionPosition
void validate() const override
std::vector< Real > floatingCoupons
std::vector< bool > notionalCanBeDecreased
std::vector< Real > lowerNotionalBound
std::vector< Real > fixedRate
std::vector< Time > floatingAccrualTimes
std::vector< Real > fixedCoupons
std::vector< Date > floatingPayDates
void fetchResults(const QuantLib::PricingEngine::results *) const override
const std::vector< bool > & notionalCanBeDecreased() const
const std::vector< Real > & fixedNominal() const
const std::vector< Real > fixedRate_
FlexiSwap(const VanillaSwap::Type type, const std::vector< Real > &fixedNominal, const std::vector< Real > &floatingNominal, const Schedule &fixedSchedule, const std::vector< Real > &fixedRate, const DayCounter &fixedDayCount, const Schedule &floatingSchedule, const QuantLib::ext::shared_ptr< IborIndex > &iborIndex, const std::vector< Real > &gearing, const std::vector< Real > &spread, const std::vector< Real > &cappedRate, const std::vector< Real > &flooredRate, const DayCounter &floatingDayCount, const std::vector< Real > &lowerNotionalBound, const QuantLib::Position::Type optionPosition, const std::vector< bool > ¬ionalCanBeDecreased=std::vector< bool >(), boost::optional< BusinessDayConvention > paymentConvention=boost::none)
BusinessDayConvention paymentConvention() const
const Schedule & fixedSchedule() const
const Schedule fixedSchedule_
const std::vector< Real > lowerNotionalBound_
const Leg & floatingLeg() const
Real underlyingValue() const
const std::vector< Real > cappedRate_
const std::vector< Real > fixedNominal_
const QuantLib::ext::shared_ptr< IborIndex > & iborIndex() const
const QuantLib::Position::Type optionPosition_
const DayCounter fixedDayCount_
const std::vector< bool > notionalCanBeDecreased_
const std::vector< Real > flooredRate_
const Schedule floatingSchedule_
BusinessDayConvention paymentConvention_
const VanillaSwap::Type type_
const Leg & fixedLeg() const
void setupExpired() const override
const std::vector< Real > gearing_
void setupArguments(QuantLib::PricingEngine::arguments *) const override
const DayCounter floatingDayCount_
const std::vector< Real > floatingNominal_
const QuantLib::ext::shared_ptr< IborIndex > iborIndex_
const std::vector< Real > spread_
const std::vector< Real > & floatingNominal() const
Flexi-Swap instrument with global notional bounds.
void setCouponPricer(const Leg &leg, const QuantLib::ext::shared_ptr< FloatingRateCouponPricer > &pricer)
Set Coupon Pricer.