20#include <boost/test/unit_test.hpp>
21#include <ql/indexes/inflation/ukrpi.hpp>
22#include <ql/termstructures/yield/flatforward.hpp>
23#include <ql/time/calendars/all.hpp>
24#include <ql/time/daycounters/actualactual.hpp>
28using namespace boost::unit_test_framework;
32BOOST_AUTO_TEST_SUITE(CpiLegTest)
36 BOOST_TEST_MESSAGE(
"Testing QuantExt::CPILeg for payment lag...");
38 Date evaluationDate(6, October, 2023);
39 Settings::instance().evaluationDate() = evaluationDate;
40 Calendar calendar = WeekendsOnly();
41 DayCounter dayCounter = ActualActual(ActualActual::ISDA);
43 Date startDate(6, October, 2023);
44 Date endDate(6, October, 2026);
45 Schedule fixedSchedule = MakeSchedule()
48 .withTenor(Period(6, Months))
49 .withCalendar(calendar)
50 .withConvention(ModifiedFollowing)
53 auto flatYts = ext::shared_ptr<YieldTermStructure>(
new FlatForward(evaluationDate, 0.025, dayCounter));
54 RelinkableHandle<YieldTermStructure> yTS(flatYts);
56 auto ukrpi = ext::make_shared<UKRPI>();
57 Leg cpiLeg =
QuantExt::CPILeg(fixedSchedule, ukrpi, yTS, 100, Period(3, Months))
63 for (
auto& coupon : cpiLeg) {
64 if (
auto cpiCoupon = ext::dynamic_pointer_cast<CPICoupon>(coupon))
66 BOOST_CHECK_EQUAL(cpiCoupon->date(), cpiCoupon->accrualEndDate() + 2 * Days);
67 else if (
auto cpiNotionalCashflow = ext::dynamic_pointer_cast<CPICashFlow>(coupon))
69 BOOST_CHECK_EQUAL(cpiNotionalCashflow->date(), fixedSchedule.endDate() + 2 * Days);
73BOOST_AUTO_TEST_SUITE_END()
75BOOST_AUTO_TEST_SUITE_END()
Helper class building a sequence of capped/floored CPI coupons.
CPILeg & withNotionals(Real notional)
CPILeg & withFixedRates(Real fixedRate)
CPILeg & withPaymentCalendar(const Calendar &)
CPILeg & withPaymentLag(Natural lag)
CPI leg builder extending QuantLib's to handle caps and floors.
BOOST_AUTO_TEST_CASE(testCpiLegPaymentLag)
Fixture that can be used at top level.