Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
cpileg.cpp
Go to the documentation of this file.
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>
26
27using namespace QuantLib;
28using namespace boost::unit_test_framework;
29
30BOOST_FIXTURE_TEST_SUITE(QuantExtTestSuite, qle::test::TopLevelFixture)
31
32BOOST_AUTO_TEST_SUITE(CpiLegTest)
33
34BOOST_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 .withFixedRates(0.01)
60 .withPaymentCalendar(calendar)
62
63 for (auto& coupon : cpiLeg) {
64 if (auto cpiCoupon = ext::dynamic_pointer_cast<CPICoupon>(coupon))
65 // The setup leg will have six regular coupons
66 BOOST_CHECK_EQUAL(cpiCoupon->date(), cpiCoupon->accrualEndDate() + 2 * Days);
67 else if (auto cpiNotionalCashflow = ext::dynamic_pointer_cast<CPICashFlow>(coupon))
68 // and one of these flows
69 BOOST_CHECK_EQUAL(cpiNotionalCashflow->date(), fixedSchedule.endDate() + 2 * Days);
70 }
71}
72
73BOOST_AUTO_TEST_SUITE_END()
74
75BOOST_AUTO_TEST_SUITE_END()
Helper class building a sequence of capped/floored CPI coupons.
Definition: cpicoupon.hpp:138
CPILeg & withNotionals(Real notional)
Definition: cpicoupon.cpp:250
CPILeg & withFixedRates(Real fixedRate)
Definition: cpicoupon.cpp:240
CPILeg & withPaymentCalendar(const Calendar &)
Definition: cpicoupon.cpp:275
CPILeg & withPaymentLag(Natural lag)
Definition: cpicoupon.cpp:280
CPI leg builder extending QuantLib's to handle caps and floors.
BOOST_AUTO_TEST_CASE(testCpiLegPaymentLag)
Definition: cpileg.cpp:34
Fixture that can be used at top level.