-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Supply MakeVanillaSwap
builder to SwapRateHelper
#1932
Changes from all commits
b0235a6
88e743f
c371d16
4da4569
3119b30
3d4b41a
264d1f9
388ecb5
4fd2c1a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -552,7 +552,7 @@ namespace QuantLib { | |
fixedConvention_(fixedConvention), fixedFrequency_(fixedFrequency), | ||
fixedDayCount_(std::move(fixedDayCount)), spread_(std::move(spread)), endOfMonth_(endOfMonth), | ||
fwdStart_(fwdStart), discountHandle_(std::move(discount)), | ||
useIndexedCoupons_(useIndexedCoupons) { | ||
useIndexedCoupons_(useIndexedCoupons), swapBuiltViaGivenBuilder(false) { | ||
|
||
// take fixing into account | ||
iborIndex_ = iborIndex->clone(termStructureHandle_); | ||
|
@@ -600,24 +600,49 @@ namespace QuantLib { | |
std::move(fixedDayCount), iborIndex, std::move(spread), fwdStart, std::move(discount), settlementDays, | ||
pillarChoice, customPillarDate, endOfMonth, useIndexedCoupons) {} | ||
|
||
void SwapRateHelper::initializeDates() { | ||
SwapRateHelper::SwapRateHelper(const Handle<Quote>& rate, | ||
const MakeVanillaSwap& swapBuilder, | ||
Handle<Quote> spread, | ||
Pillar::Choice pillar, | ||
Date customPillarDate) | ||
: RelativeDateRateHelper(rate), pillarChoice_(pillar), spread_(std::move(spread)), | ||
fwdStart_(swapBuilder.forwardStart_), swapBuiltViaGivenBuilder(true) { | ||
registerWith(spread_); | ||
|
||
// 1. do not pass the spread here, as it might be a Quote | ||
// i.e. it can dynamically change | ||
// 2. input discount curve Handle might be empty now but it could | ||
// be assigned a curve later; use a RelinkableHandle here | ||
swap_ = MakeVanillaSwap(tenor_, iborIndex_, 0.0, fwdStart_) | ||
.withSettlementDays(settlementDays_) | ||
.withDiscountingTermStructure(discountRelinkableHandle_) | ||
.withFixedLegDayCount(fixedDayCount_) | ||
.withFixedLegTenor(Period(fixedFrequency_)) | ||
.withFixedLegConvention(fixedConvention_) | ||
.withFixedLegTerminationDateConvention(fixedConvention_) | ||
.withFixedLegCalendar(calendar_) | ||
.withFixedLegEndOfMonth(endOfMonth_) | ||
.withFloatingLegCalendar(calendar_) | ||
.withFloatingLegEndOfMonth(endOfMonth_) | ||
.withIndexedCoupons(useIndexedCoupons_); | ||
pillarDate_ = customPillarDate; | ||
swap_ = swapBuilder; | ||
SwapRateHelper::initializeDates(); | ||
} | ||
|
||
SwapRateHelper::SwapRateHelper(Rate rate, | ||
const MakeVanillaSwap& swapBuilder, | ||
Handle<Quote> spread, | ||
Pillar::Choice pillar, | ||
Date customPillarDate) | ||
: SwapRateHelper(makeQuoteHandle(rate), | ||
swapBuilder, | ||
std::move(spread), | ||
pillar, | ||
customPillarDate) {} | ||
|
||
void SwapRateHelper::initializeDates() { | ||
if (!swapBuiltViaGivenBuilder) | ||
// 1. do not pass the spread here, as it might be a Quote | ||
// i.e. it can dynamically change | ||
// 2. input discount curve Handle might be empty now but it could | ||
// be assigned a curve later; use a RelinkableHandle here | ||
swap_ = MakeVanillaSwap(tenor_, iborIndex_, 0.0, fwdStart_) | ||
.withSettlementDays(settlementDays_) | ||
.withDiscountingTermStructure(discountRelinkableHandle_) | ||
.withFixedLegDayCount(fixedDayCount_) | ||
.withFixedLegTenor(Period(fixedFrequency_)) | ||
.withFixedLegConvention(fixedConvention_) | ||
.withFixedLegTerminationDateConvention(fixedConvention_) | ||
.withFixedLegCalendar(calendar_) | ||
.withFixedLegEndOfMonth(endOfMonth_) | ||
.withFloatingLegCalendar(calendar_) | ||
.withFloatingLegEndOfMonth(endOfMonth_) | ||
.withIndexedCoupons(useIndexedCoupons_); | ||
|
||
simplifyNotificationGraph(*swap_, true); | ||
|
||
|
@@ -655,6 +680,9 @@ namespace QuantLib { | |
} | ||
|
||
void SwapRateHelper::setTermStructure(YieldTermStructure* t) { | ||
if (swapBuiltViaGivenBuilder) | ||
return; | ||
Comment on lines
682
to
+684
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I did not see a straight forward way to access the term structure when the |
||
|
||
// do not set the relinkable handle as an observer - | ||
// force recalculation when needed | ||
bool observer = false; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,7 @@ | |
|
||
#include <ql/termstructures/bootstraphelper.hpp> | ||
#include <ql/instruments/vanillaswap.hpp> | ||
#include <ql/instruments/makevanillaswap.hpp> | ||
#include <ql/instruments/bmaswap.hpp> | ||
#include <ql/instruments/futures.hpp> | ||
#include <ql/time/calendar.hpp> | ||
|
@@ -313,6 +314,16 @@ | |
Date customPillarDate = Date(), | ||
bool endOfMonth = false, | ||
const ext::optional<bool>& useIndexedCoupons = ext::nullopt); | ||
SwapRateHelper(const Handle<Quote>& rate, | ||
const MakeVanillaSwap& swapBuilder, | ||
Handle<Quote> spread = {}, | ||
Pillar::Choice pillar = Pillar::LastRelevantDate, | ||
Date customPillarDate = Date()); | ||
SwapRateHelper(Rate rate, | ||
const MakeVanillaSwap& swapBuilder, | ||
Handle<Quote> spread = {}, | ||
Pillar::Choice pillar = Pillar::LastRelevantDate, | ||
Date customPillarDate = Date()); | ||
Comment on lines
+317
to
+326
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are multiple pairs of ctors which differ only in |
||
//! \name RateHelper interface | ||
//@{ | ||
Real impliedQuote() const override; | ||
|
@@ -347,6 +358,7 @@ | |
Handle<YieldTermStructure> discountHandle_; | ||
RelinkableHandle<YieldTermStructure> discountRelinkableHandle_; | ||
ext::optional<bool> useIndexedCoupons_; | ||
bool swapBuiltViaGivenBuilder; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe this issue "'SwapRateHelper::swapBuiltViaGivenBuilder' is never used" from "Codacy Static Code Analysis" is a false positive. The member is used, e.g. in ratehelpers.cpp:l.681 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We are supporting two different ctor types
Thus, different member variables are used. We could represent this in code (e.g. via |
||
}; | ||
|
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is added to enable access within
SwapRateHelper::SwapRateHelper(const MakeVanillaSwap& swapBuilder)
toswapBuilder.forwardStart_
.