Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
Functions
cpileg.cpp File Reference
#include "toplevelfixture.hpp"
#include <boost/test/unit_test.hpp>
#include <ql/indexes/inflation/ukrpi.hpp>
#include <ql/termstructures/yield/flatforward.hpp>
#include <ql/time/calendars/all.hpp>
#include <ql/time/daycounters/actualactual.hpp>
#include <qle/cashflows/cpicoupon.hpp>

Go to the source code of this file.

Functions

 BOOST_AUTO_TEST_CASE (testCpiLegPaymentLag)
 

Function Documentation

◆ BOOST_AUTO_TEST_CASE()

BOOST_AUTO_TEST_CASE ( testCpiLegPaymentLag  )

Definition at line 34 of file cpileg.cpp.

34 {
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}
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
+ Here is the call graph for this function: