Skip to content

Commit

Permalink
Register floating cash flows with OIS; add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lballabio committed Apr 11, 2024
1 parent daec722 commit f3a2e92
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 2 deletions.
2 changes: 2 additions & 0 deletions ql/instruments/overnightindexedswap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ namespace QuantLib {
floatingSchedule().calendar() :
paymentCalendar)
.withAveragingMethod(averagingMethod_);
for (const auto& c : legs_[1])
registerWith(c);
}

void OvernightIndexedSwap::setupFloatingArguments(arguments* args) const {
Expand Down
4 changes: 2 additions & 2 deletions ql/instruments/vanillaswap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ namespace QuantLib {
.withPaymentAdjustment(this->paymentConvention())
.withSpreads(this->spread())
.withIndexedCoupons(useIndexedCoupons);
for (Leg::const_iterator i = legs_[1].begin(); i < legs_[1].end(); ++i)
registerWith(*i);
for (const auto& c : legs_[1])
registerWith(c);
}

void VanillaSwap::setupFloatingArguments(arguments* args) const {
Expand Down
42 changes: 42 additions & 0 deletions test-suite/overnightindexedswap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include <ql/time/daycounters/simpledaycounter.hpp>
#include <ql/time/schedule.hpp>
#include <ql/indexes/ibor/eonia.hpp>
#include <ql/indexes/ibor/estr.hpp>
#include <ql/indexes/ibor/euribor.hpp>
#include <ql/indexes/ibor/fedfunds.hpp>
#include <ql/cashflows/iborcoupon.hpp>
Expand Down Expand Up @@ -631,6 +632,47 @@ BOOST_AUTO_TEST_CASE(testConstructorsAndNominals) {
BOOST_CHECK_EQUAL(ois_4.overnightNominals()[3], nominal/2);
}

BOOST_AUTO_TEST_CASE(testNotifications) {
BOOST_TEST_MESSAGE("Testing cash-flow notifications for OIS...");

CommonVars vars;

Date spot = vars.calendar.advance(vars.today, 2*Days);
Real nominal = 100000.0;

Schedule schedule = MakeSchedule()
.from(spot)
.to(vars.calendar.advance(spot, 2*Years))
.withCalendar(vars.calendar)
.withFrequency(Annual);

RelinkableHandle<YieldTermStructure> forecast_handle;
forecast_handle.linkTo(flatRate(0.02, Actual360()));

RelinkableHandle<YieldTermStructure> discount_handle;
discount_handle.linkTo(flatRate(0.02, Actual360()));

auto index = ext::make_shared<Estr>(forecast_handle);

auto ois = ext::make_shared<OvernightIndexedSwap>(Swap::Payer,
nominal,
schedule,
0.03,
Actual360(),
index);
ois->setPricingEngine(ext::make_shared<DiscountingSwapEngine>(discount_handle));
ois->NPV();

Flag flag;
flag.registerWith(ois);
flag.lower();

forecast_handle.linkTo(flatRate(0.03, Actual360()));

if (!flag.isUp())
BOOST_FAIL("OIS was not notified of curve change");
}

BOOST_AUTO_TEST_SUITE_END()

BOOST_AUTO_TEST_SUITE_END()
44 changes: 44 additions & 0 deletions test-suite/swap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,50 @@ BOOST_AUTO_TEST_CASE(testThirdWednesdayAdjustment) {
}
}

BOOST_AUTO_TEST_CASE(testNotifications) {
BOOST_TEST_MESSAGE("Testing cash-flow notifications for vanilla swap...");

CommonVars vars;

Date spot = vars.calendar.advance(vars.today, 2*Days);
Real nominal = 100000.0;

Schedule schedule = MakeSchedule()
.from(spot)
.to(vars.calendar.advance(spot, 2*Years))
.withCalendar(vars.calendar)
.withFrequency(Semiannual);

RelinkableHandle<YieldTermStructure> forecast_handle;
forecast_handle.linkTo(flatRate(0.02, Actual365Fixed()));

RelinkableHandle<YieldTermStructure> discount_handle;
discount_handle.linkTo(flatRate(0.02, Actual365Fixed()));

auto index = ext::make_shared<Euribor6M>(forecast_handle);

auto swap = ext::make_shared<VanillaSwap>(Swap::Payer,
nominal,
schedule,
0.03,
Actual365Fixed(),
schedule,
index,
0.0,
Actual365Fixed());
swap->setPricingEngine(ext::make_shared<DiscountingSwapEngine>(discount_handle));
swap->NPV();

Flag flag;
flag.registerWith(swap);
flag.lower();

forecast_handle.linkTo(flatRate(0.03, Actual365Fixed()));

if (!flag.isUp())
BOOST_FAIL("swap was not notified of curve change");
}

BOOST_AUTO_TEST_SUITE_END()

BOOST_AUTO_TEST_SUITE_END()

0 comments on commit f3a2e92

Please sign in to comment.