Skip to content

Commit

Permalink
GH-1791 add clarifying comment and unit test to confirm result caching (
Browse files Browse the repository at this point in the history
  • Loading branch information
lballabio authored Dec 13, 2023
2 parents 591e3d7 + 279b4d7 commit edac898
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
7 changes: 4 additions & 3 deletions ql/pricingengines/swaption/blackswaptionengine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,10 @@ namespace QuantLib {

Date exerciseDate = arguments_.exercise->date(0);

// the part of the swap preceding exerciseDate should be truncated
// to avoid taking into account unwanted cashflows
// for the moment we add a check avoiding this situation
// The part of the swap preceding exerciseDate should be truncated to avoid taking into
// account unwanted cashflows. For the moment we add a check avoiding this situation.
// Furthermore, we take a copy of the underlying swap. This avoids notifying the swaption
// when we set a pricing engine on the swap below.
VanillaSwap swap = *arguments_.swap;
const Leg& fixedLeg = swap.fixedLeg();
ext::shared_ptr<FixedRateCoupon> firstCoupon =
Expand Down
26 changes: 26 additions & 0 deletions test-suite/swaption.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,32 @@ BOOST_FIXTURE_TEST_SUITE(QuantLibTest, TopLevelFixture)

BOOST_AUTO_TEST_SUITE(SwaptionTest)

BOOST_AUTO_TEST_CASE(testBlackEngineCaching) {

BOOST_TEST_MESSAGE("Testing swaption result caching in Black engine...");

using namespace swaption_test;

CommonVars vars;

Date exerciseDate = vars.calendar.advance(vars.today, 1 * Years);
Date startDate = vars.calendar.advance(exerciseDate, vars.settlementDays, Days);

ext::shared_ptr<VanillaSwap> swap = MakeVanillaSwap(1 * Years, vars.index, 0.03)
.withEffectiveDate(startDate)
.withFixedLegTenor(1 * Years)
.withFixedLegDayCount(vars.fixedDayCount)
.withFloatingLegSpread(0.0)
.withType(Swap::Payer);
ext::shared_ptr<Swaption> swaption = vars.makeSwaption(swap, exerciseDate, 0.12);

BOOST_CHECK(!swaption->isCalculated());

swaption->NPV();

BOOST_CHECK(swaption->isCalculated());
}

BOOST_AUTO_TEST_CASE(testStrikeDependency) {

BOOST_TEST_MESSAGE("Testing swaption dependency on strike...");
Expand Down

0 comments on commit edac898

Please sign in to comment.