Skip to content
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

Remove redundant arguments from SofrFutureRateHelper constructor #1242

Merged
merged 4 commits into from
Nov 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 45 additions & 1 deletion ql/termstructures/yield/overnightindexfutureratehelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@
*/

#include <ql/termstructures/yield/overnightindexfutureratehelper.hpp>
#include <ql/indexes/ibor/sofr.hpp>
#include <ql/utilities/null_deleter.hpp>

namespace QuantLib {

namespace {

Date getValidSofrStart(Month month, Year year, Frequency freq) {
return freq == Monthly ?
return freq == Monthly ?
UnitedStates(UnitedStates::GovernmentBond).adjust(Date(1, month, year)) :
Date::nthWeekday(3, Wednesday, month, year);
}
Expand Down Expand Up @@ -92,6 +93,7 @@ namespace QuantLib {
return future_->convexityAdjustment();
}


SofrFutureRateHelper::SofrFutureRateHelper(
const Handle<Quote>& price,
Month referenceMonth,
Expand Down Expand Up @@ -139,4 +141,46 @@ namespace QuantLib {
}
}

SofrFutureRateHelper::SofrFutureRateHelper(
const Handle<Quote>& price,
Month referenceMonth,
Year referenceYear,
Frequency referenceFreq,
const Handle<Quote>& convexityAdjustment)
: OvernightIndexFutureRateHelper(price,
getValidSofrStart(referenceMonth, referenceYear, referenceFreq),
getValidSofrEnd(referenceMonth, referenceYear, referenceFreq),
ext::make_shared<Sofr>(),
convexityAdjustment,
referenceFreq == Quarterly ? RateAveraging::Compound : RateAveraging::Simple) {
QL_REQUIRE(referenceFreq == Quarterly || referenceFreq == Monthly,
"only monthly and quarterly SOFR futures accepted");
if (referenceFreq == Quarterly) {
QL_REQUIRE(referenceMonth == Mar || referenceMonth == Jun || referenceMonth == Sep ||
referenceMonth == Dec,
"quarterly SOFR futures can only start in Mar,Jun,Sep,Dec");
}
}

SofrFutureRateHelper::SofrFutureRateHelper(
Real price,
Month referenceMonth,
Year referenceYear,
Frequency referenceFreq,
Real convexityAdjustment)
: OvernightIndexFutureRateHelper(
Handle<Quote>(ext::make_shared<SimpleQuote>(price)),
getValidSofrStart(referenceMonth, referenceYear, referenceFreq),
getValidSofrEnd(referenceMonth, referenceYear, referenceFreq),
ext::make_shared<Sofr>(),
Handle<Quote>(ext::make_shared<SimpleQuote>(convexityAdjustment)),
referenceFreq == Quarterly ? RateAveraging::Compound : RateAveraging::Simple) {
QL_REQUIRE(referenceFreq == Quarterly || referenceFreq == Monthly,
"only monthly and quarterly SOFR futures accepted");
if (referenceFreq == Quarterly) {
QL_REQUIRE(referenceMonth == Mar || referenceMonth == Jun || referenceMonth == Sep ||
referenceMonth == Dec,
"quarterly SOFR futures can only start in Mar,Jun,Sep,Dec");
}
}
}
29 changes: 25 additions & 4 deletions ql/termstructures/yield/overnightindexfutureratehelper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,20 +67,41 @@ namespace QuantLib {
*/
class SofrFutureRateHelper : public OvernightIndexFutureRateHelper {
public:
/*! \deprecated Use the constructor without index and averaging method.
Deprecated in version 1.25.
*/
QL_DEPRECATED
SofrFutureRateHelper(const Handle<Quote>& price,
Month referenceMonth,
Year referenceYear,
Frequency referenceFreq,
const ext::shared_ptr<OvernightIndex>& overnightIndex,
const Handle<Quote>& convexityAdjustment = Handle<Quote>(),
RateAveraging::Type averagingMethod = RateAveraging::Compound);
const Handle<Quote>& convexityAdjustment,
RateAveraging::Type averagingMethod);

/*! \deprecated Use the constructor without index and averaging method.
Deprecated in version 1.25.
*/
QL_DEPRECATED
SofrFutureRateHelper(Real price,
Month referenceMonth,
Year referenceYear,
Frequency referenceFreq,
const ext::shared_ptr<OvernightIndex>& overnightIndex,
Real convexityAdjustment = 0,
RateAveraging::Type averagingMethod = RateAveraging::Compound);
Real convexityAdjustment,
RateAveraging::Type averagingMethod);

SofrFutureRateHelper(const Handle<Quote>& price,
Month referenceMonth,
Year referenceYear,
Frequency referenceFreq,
const Handle<Quote>& convexityAdjustment = Handle<Quote>());

SofrFutureRateHelper(Real price,
Month referenceMonth,
Year referenceYear,
Frequency referenceFreq,
Real convexityAdjustment = 0);
};

}
Expand Down
3 changes: 1 addition & 2 deletions test-suite/sofrfutures.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,7 @@ void SofrFuturesTest::testBootstrap() {
std::vector<ext::shared_ptr<RateHelper> > helpers;
for (const auto& sofrQuote : sofrQuotes) {
helpers.push_back(ext::make_shared<SofrFutureRateHelper>(
sofrQuote.price, sofrQuote.month, sofrQuote.year, sofrQuote.freq,
index, 0.0, sofrQuote.averagingMethod));
sofrQuote.price, sofrQuote.month, sofrQuote.year, sofrQuote.freq));
}

ext::shared_ptr<PiecewiseYieldCurve<Discount, Linear> > curve =
Expand Down