19#include <ql/cashflows/iborcoupon.hpp>
20#include <ql/indexes/ibor/libor.hpp>
21#include <ql/pricingengines/swap/discountingswapengine.hpp>
22#include <ql/utilities/null_deleter.hpp>
28 const QuantLib::ext::shared_ptr<IborIndex> payIndex,
29 const QuantLib::ext::shared_ptr<IborIndex> receiveIndex,
30 const Handle<YieldTermStructure>& discountingCurve,
bool spreadOnRec,
31 bool includeSpread,
const Period& payFrequency,
const Period& recFrequency,
34 spreadOnRec_(spreadOnRec), includeSpread_(includeSpread), payFrequency_(payFrequency),
35 recFrequency_(recFrequency), telescopicValueDates_(telescopicValueDates), type_(type),
36 discountHandle_(discountingCurve) {
67 bool payGiven = !
payIndex_->forwardingTermStructure().empty();
68 bool recGiven = !
receiveIndex_->forwardingTermStructure().empty();
71 QuantLib::ext::shared_ptr<OvernightIndex> payIndexON = QuantLib::ext::dynamic_pointer_cast<OvernightIndex>(
payIndex_);
72 QuantLib::ext::shared_ptr<OvernightIndex> recIndexON = QuantLib::ext::dynamic_pointer_cast<OvernightIndex>(
receiveIndex_);
74 if (!payGiven && !recGiven && !discountGiven) {
76 QL_FAIL(
"no curve given");
77 }
else if (!payGiven && !recGiven && discountGiven) {
79 QL_FAIL(
"no index curve given");
80 }
else if (!payGiven && recGiven && !discountGiven) {
84 if (!payIndexON && recIndexON)
88 }
else if (!payGiven && recGiven && discountGiven) {
92 }
else if (payGiven && !recGiven && !discountGiven) {
96 if (payIndexON && !recIndexON)
100 }
else if (payGiven && !recGiven && discountGiven) {
104 }
else if (payGiven && recGiven && !discountGiven) {
107 }
else if (payGiven && recGiven && discountGiven) {
109 QL_FAIL(
"Both Index and the Discount curves are all given");
124 QuantLib::ext::shared_ptr<Libor> payIndexAsLibor = QuantLib::ext::dynamic_pointer_cast<Libor>(
payIndex_);
125 Calendar spotCalendar = payIndexAsLibor != NULL ? payIndexAsLibor->jointCalendar() :
payIndex_->fixingCalendar();
126 Natural spotDays =
payIndex_->fixingDays();
128 Date valuationDate = Settings::instance().evaluationDate();
131 valuationDate = spotCalendar.adjust(valuationDate);
133 Date effectiveDate = spotCalendar.advance(valuationDate, spotDays * Days);
140 swap_->setPricingEngine(engine);
142 earliestDate_ =
swap_->startDate();
143 latestDate_ =
swap_->maturityDate();
145 QuantLib::ext::shared_ptr<FloatingRateCoupon> lastFloating = QuantLib::ext::dynamic_pointer_cast<FloatingRateCoupon>(
147 :
swap_->payLeg().back());
148 if (IborCoupon::Settings::instance().usingAtParCoupons()) {
150 if (QuantLib::ext::dynamic_pointer_cast<QuantExt::SubPeriodsCoupon1>(lastFloating)) {
151 Date fixingValueDate =
receiveIndex_->valueDate(lastFloating->fixingDate());
152 Date endValueDate =
receiveIndex_->maturityDate(fixingValueDate);
153 latestDate_ = std::max(latestDate_, endValueDate);
158 Date fixingValueDate =
receiveIndex_->valueDate(lastFloating->fixingDate());
159 Date endValueDate =
receiveIndex_->maturityDate(fixingValueDate);
160 latestDate_ = std::max(latestDate_, endValueDate);
166 bool observer =
false;
168 QuantLib::ext::shared_ptr<YieldTermStructure> temp(t, null_deleter());
176 RelativeDateRateHelper::setTermStructure(t);
180 QL_REQUIRE(termStructure_ != 0,
"Termstructure not set");
187 Visitor<TenorBasisSwapHelper>* v1 =
dynamic_cast<Visitor<TenorBasisSwapHelper>*
>(&v);
191 RateHelper::accept(v);
QuantLib::ext::shared_ptr< IborIndex > payIndex_
RelinkableHandle< YieldTermStructure > discountRelinkableHandle_
void setTermStructure(YieldTermStructure *) override
QuantLib::ext::shared_ptr< IborIndex > receiveIndex_
TenorBasisSwapHelper(Handle< Quote > spread, const Period &swapTenor, const QuantLib::ext::shared_ptr< IborIndex > payIndex, const QuantLib::ext::shared_ptr< IborIndex > receiveIndex, const Handle< YieldTermStructure > &discountingCurve=Handle< YieldTermStructure >(), bool spreadOnRec=true, bool includeSpread=false, const Period &payFrequency=Period(), const Period &recFrequency=Period(), const bool telescopicValueDates=false, QuantExt::SubPeriodsCoupon1::Type type=QuantExt::SubPeriodsCoupon1::Compounding)
bool telescopicValueDates_
RelinkableHandle< YieldTermStructure > termStructureHandle_
bool setDiscountRelinkableHandle_
Handle< YieldTermStructure > discountHandle_
void accept(AcyclicVisitor &) override
void initializeDates() override
Real impliedQuote() const override
QuantLib::ext::shared_ptr< TenorBasisSwap > swap_
QuantExt::SubPeriodsCoupon1::Type type_
Single currency tenor basis swap.
Single currency tenor basis swap helper.