Skip to content

Commit cda19ae

Browse files
committed
Add test for payment lag on CPI legs
1 parent e9654fe commit cda19ae

1 file changed

Lines changed: 74 additions & 0 deletions

File tree

QuantExt/test/cpileg.cpp

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/*
2+
Copyright (C) 2023 Skandinaviska Enskilda Banken AB (publ)
3+
All rights reserved.
4+
5+
This file is part of ORE, a free-software/open-source library
6+
for transparent pricing and risk analysis - http://opensourcerisk.org
7+
8+
ORE is free software: you can redistribute it and/or modify it
9+
under the terms of the Modified BSD License. You should have received a
10+
copy of the license along with this program.
11+
The license is also available online at <http://opensourcerisk.org>
12+
13+
This program is distributed on the basis that it will form a useful
14+
contribution to risk analytics and model standardisation, but WITHOUT
15+
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16+
FITNESS FOR A PARTICULAR PURPOSE. See the license for more details.
17+
*/
18+
19+
#include "toplevelfixture.hpp"
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>
25+
#include <qle/cashflows/cpicoupon.hpp>
26+
27+
using namespace QuantLib;
28+
using namespace boost::unit_test_framework;
29+
30+
BOOST_FIXTURE_TEST_SUITE(QuantExtTestSuite, qle::test::TopLevelFixture)
31+
32+
BOOST_AUTO_TEST_SUITE(CpiLegTest)
33+
34+
BOOST_AUTO_TEST_CASE(testCpiLegPaymentLag) {
35+
36+
BOOST_TEST_MESSAGE("Testing QuantExt::CPILeg for payment lag...");
37+
38+
Date evaluationDate(6, October, 2023);
39+
Settings::instance().evaluationDate() = evaluationDate;
40+
Calendar calendar = WeekendsOnly();
41+
DayCounter dayCounter = ActualActual(ActualActual::ISDA);
42+
43+
Date startDate(6, October, 2023);
44+
Date endDate(6, October, 2026);
45+
Schedule fixedSchedule = MakeSchedule()
46+
.from(startDate)
47+
.to(endDate)
48+
.withTenor(Period(6, Months))
49+
.withCalendar(calendar)
50+
.withConvention(ModifiedFollowing)
51+
.backwards();
52+
53+
auto flatYts = ext::shared_ptr<YieldTermStructure>(new FlatForward(evaluationDate, 0.025, dayCounter));
54+
RelinkableHandle<YieldTermStructure> yTS(flatYts);
55+
56+
auto ukrpi = ext::make_shared<UKRPI>();
57+
Leg cpiLeg = QuantExt::CPILeg(fixedSchedule, ukrpi, yTS, 100, Period(3, Months))
58+
.withNotionals(1e6)
59+
.withPaymentCalendar(calendar)
60+
.withPaymentLag(2);
61+
62+
for (auto& coupon : cpiLeg) {
63+
if (auto cpiCoupon = ext::dynamic_pointer_cast<CPICoupon>(coupon))
64+
// The setup leg will have six regular coupons
65+
BOOST_CHECK_EQUAL(cpiCoupon->date(), cpiCoupon->accrualEndDate() + 2 * Days);
66+
else if (auto cpiNotionalCashflow = ext::dynamic_pointer_cast<CPICashFlow>(coupon))
67+
// and one of these flows
68+
BOOST_CHECK_EQUAL(cpiNotionalCashflow->date(), fixedSchedule.endDate() + 2 * Days);
69+
}
70+
}
71+
72+
BOOST_AUTO_TEST_SUITE_END()
73+
74+
BOOST_AUTO_TEST_SUITE_END()

0 commit comments

Comments
 (0)