@@ -62,7 +62,7 @@ TenorBasisSwapHelper::TenorBasisSwapHelper(Handle<Quote> spread, const Period& s
6262
6363 */
6464
65- setDiscountRelinkableHandle_ = false ;
65+ automaticDiscountRelinkableHandle_ = false ;
6666
6767 bool payGiven = !payIndex_->forwardingTermStructure ().empty ();
6868 bool recGiven = !receiveIndex_->forwardingTermStructure ().empty ();
@@ -71,6 +71,9 @@ TenorBasisSwapHelper::TenorBasisSwapHelper(Handle<Quote> spread, const Period& s
7171 QuantLib::ext::shared_ptr<OvernightIndex> payIndexON = QuantLib::ext::dynamic_pointer_cast<OvernightIndex>(payIndex_);
7272 QuantLib::ext::shared_ptr<OvernightIndex> recIndexON = QuantLib::ext::dynamic_pointer_cast<OvernightIndex>(receiveIndex_);
7373
74+ if (discountGiven)
75+ discountRelinkableHandle_.linkTo (*discountHandle_);
76+
7477 if (!payGiven && !recGiven && !discountGiven) {
7578 // case 0
7679 QL_FAIL (" no curve given" );
@@ -81,10 +84,11 @@ TenorBasisSwapHelper::TenorBasisSwapHelper(Handle<Quote> spread, const Period& s
8184 // case 2
8285 payIndex_ = QuantLib::ext::static_pointer_cast<IborIndex>(payIndex_->clone (termStructureHandle_));
8386 payIndex_->unregisterWith (termStructureHandle_);
84- if (!payIndexON && recIndexON)
87+ if (!payIndexON && recIndexON) {
8588 discountRelinkableHandle_.linkTo (*receiveIndex_->forwardingTermStructure ());
86- else
87- setDiscountRelinkableHandle_ = true ;
89+ } else {
90+ automaticDiscountRelinkableHandle_ = true ;
91+ }
8892 } else if (!payGiven && recGiven && discountGiven) {
8993 // case 3
9094 payIndex_ = QuantLib::ext::static_pointer_cast<IborIndex>(payIndex_->clone (termStructureHandle_));
@@ -93,17 +97,18 @@ TenorBasisSwapHelper::TenorBasisSwapHelper(Handle<Quote> spread, const Period& s
9397 // case 4
9498 receiveIndex_ = QuantLib::ext::static_pointer_cast<IborIndex>(receiveIndex_->clone (termStructureHandle_));
9599 receiveIndex_->unregisterWith (termStructureHandle_);
96- if (payIndexON && !recIndexON)
100+ if (payIndexON && !recIndexON) {
97101 discountRelinkableHandle_.linkTo (*payIndex_->forwardingTermStructure ());
98- else
99- setDiscountRelinkableHandle_ = true ;
102+ } else {
103+ automaticDiscountRelinkableHandle_ = true ;
104+ }
100105 } else if (payGiven && !recGiven && discountGiven) {
101106 // case 5
102107 receiveIndex_ = QuantLib::ext::static_pointer_cast<IborIndex>(receiveIndex_->clone (termStructureHandle_));
103108 receiveIndex_->unregisterWith (termStructureHandle_);
104109 } else if (payGiven && recGiven && !discountGiven) {
105110 // case 6
106- setDiscountRelinkableHandle_ = true ;
111+ automaticDiscountRelinkableHandle_ = true ;
107112 } else if (payGiven && recGiven && discountGiven) {
108113 // case 7
109114 QL_FAIL (" Both Index and the Discount curves are all given" );
@@ -120,7 +125,6 @@ TenorBasisSwapHelper::TenorBasisSwapHelper(Handle<Quote> spread, const Period& s
120125
121126void TenorBasisSwapHelper::initializeDates () {
122127
123- // CHECK : should the spot shift be based on pay ore receive, here we have the pay leg...
124128 QuantLib::ext::shared_ptr<Libor> payIndexAsLibor = QuantLib::ext::dynamic_pointer_cast<Libor>(payIndex_);
125129 Calendar spotCalendar = payIndexAsLibor != NULL ? payIndexAsLibor->jointCalendar () : payIndex_->fixingCalendar ();
126130 Natural spotDays = payIndex_->fixingDays ();
@@ -132,11 +136,11 @@ void TenorBasisSwapHelper::initializeDates() {
132136
133137 Date effectiveDate = spotCalendar.advance (valuationDate, spotDays * Days);
134138
135- swap_ = QuantLib::ext::shared_ptr <TenorBasisSwap>(new TenorBasisSwap (
136- effectiveDate, 1.0 , swapTenor_, payIndex_, 0.0 , payFrequency_, receiveIndex_, 0.0 , recFrequency_,
137- DateGeneration::Backward, includeSpread_, spreadOnRec_, type_, telescopicValueDates_) );
139+ swap_ = QuantLib::ext::make_shared <TenorBasisSwap>(effectiveDate, 1.0 , swapTenor_, payIndex_, 0.0 , payFrequency_,
140+ receiveIndex_, 0.0 , recFrequency_, DateGeneration::Backward ,
141+ includeSpread_, spreadOnRec_, type_, telescopicValueDates_);
138142
139- QuantLib::ext::shared_ptr<PricingEngine> engine ( new DiscountingSwapEngine ( discountRelinkableHandle_) );
143+ auto engine = QuantLib::ext::make_shared<DiscountingSwapEngine>( discountRelinkableHandle_);
140144 swap_->setPricingEngine (engine);
141145
142146 earliestDate_ = swap_->startDate ();
@@ -168,10 +172,8 @@ void TenorBasisSwapHelper::setTermStructure(YieldTermStructure* t) {
168172 QuantLib::ext::shared_ptr<YieldTermStructure> temp (t, null_deleter ());
169173 termStructureHandle_.linkTo (temp, observer);
170174
171- if (setDiscountRelinkableHandle_ )
175+ if (automaticDiscountRelinkableHandle_ )
172176 discountRelinkableHandle_.linkTo (temp, observer);
173- else
174- discountRelinkableHandle_.linkTo (*discountHandle_, observer);
175177
176178 RelativeDateRateHelper::setTermStructure (t);
177179}
0 commit comments