Skip to content

Commit

Permalink
Merge pull request #1242.
Browse files Browse the repository at this point in the history
Remove redundant arguments from `SofrFutureRateHelper` constructor
  • Loading branch information
lballabio authored Nov 17, 2021
2 parents c21fff2 + 7086e1d commit d55b8b1
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 7 deletions.
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

0 comments on commit d55b8b1

Please sign in to comment.