Skip to content

Commit

Permalink
Allow creating a swap helper with frequency "Once"
Browse files Browse the repository at this point in the history
  • Loading branch information
lballabio committed Sep 23, 2024
1 parent b2ef988 commit 946d29c
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
2 changes: 1 addition & 1 deletion ql/termstructures/yield/ratehelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,7 @@ namespace QuantLib {
.withSettlementDays(settlementDays_)
.withDiscountingTermStructure(discountRelinkableHandle_)
.withFixedLegDayCount(fixedDayCount_)
.withFixedLegTenor(Period(fixedFrequency_))
.withFixedLegTenor(fixedFrequency_ == Once ? tenor_ : Period(fixedFrequency_))
.withFixedLegConvention(fixedConvention_)
.withFixedLegTerminationDateConvention(fixedConvention_)
.withFixedLegCalendar(calendar_)
Expand Down
19 changes: 19 additions & 0 deletions test-suite/piecewiseyieldcurve.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "utilities.hpp"
#include <ql/cashflows/iborcoupon.hpp>
#include <ql/indexes/bmaindex.hpp>
#include <ql/indexes/ibor/estr.hpp>
#include <ql/indexes/ibor/euribor.hpp>
#include <ql/indexes/ibor/jpylibor.hpp>
#include <ql/indexes/ibor/usdlibor.hpp>
Expand All @@ -40,12 +41,14 @@
#include <ql/termstructures/globalbootstrap.hpp>
#include <ql/termstructures/yield/bondhelpers.hpp>
#include <ql/termstructures/yield/flatforward.hpp>
#include <ql/termstructures/yield/oisratehelper.hpp>
#include <ql/termstructures/yield/piecewiseyieldcurve.hpp>
#include <ql/termstructures/yield/ratehelpers.hpp>
#include <ql/time/asx.hpp>
#include <ql/time/calendars/canada.hpp>
#include <ql/time/calendars/japan.hpp>
#include <ql/time/calendars/jointcalendar.hpp>
#include <ql/time/calendars/mexico.hpp>
#include <ql/time/calendars/target.hpp>
#include <ql/time/calendars/weekendsonly.hpp>
#include <ql/time/daycounters/actual360.hpp>
Expand Down Expand Up @@ -1544,6 +1547,22 @@ BOOST_AUTO_TEST_CASE(testCustomFuturesHelpers) {
}
}


BOOST_AUTO_TEST_CASE(testSwapHelpersWithOnceFrequency) {
BOOST_TEST_MESSAGE("Testing single-coupon swap rate helpers...");

auto index = ext::make_shared<IborIndex>(
"TestIndex", 4*Weeks, 1, MXNCurrency(),
Mexico(), Following, false, Actual360());

Handle<Quote> r(ext::make_shared<SimpleQuote>(0.02));

BOOST_CHECK_NO_THROW(SwapRateHelper(r, 4*Weeks, Mexico(), Once, Following, Actual360(), index));

BOOST_CHECK_NO_THROW(OISRateHelper(2, 4*Weeks, r, ext::make_shared<Estr>(), {}, false, 0, Following, Once));
}


BOOST_AUTO_TEST_SUITE_END()

BOOST_AUTO_TEST_SUITE_END()
15 changes: 15 additions & 0 deletions test-suite/schedule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -943,6 +943,21 @@ BOOST_AUTO_TEST_CASE(testFourWeeksTenor) {
}
}

BOOST_AUTO_TEST_CASE(testOnceFrequency) {
BOOST_TEST_MESSAGE(
"Testing that Once frequency works...");

Schedule s =
MakeSchedule().from(Date(13,January,2016))
.to(Date(13,January,2019))
.withFrequency(Once)
.forwards();

BOOST_CHECK(s.size() == 2);
BOOST_CHECK(s[0] == Date(13,January,2016));
BOOST_CHECK(s[1] == Date(13,January,2019));
}

BOOST_AUTO_TEST_CASE(testScheduleAlwaysHasAStartDate) {
BOOST_TEST_MESSAGE("Testing that variations of MakeSchedule "
"always produce a schedule with a start date...");
Expand Down

0 comments on commit 946d29c

Please sign in to comment.