Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
Functions
inflationcurve.cpp File Reference
#include "toplevelfixture.hpp"
#include <boost/test/unit_test.hpp>
#include <ql/termstructures/inflationtermstructure.hpp>
#include <qle/termstructures/inflation/piecewisezeroinflationcurve.hpp>
#include <ql/indexes/inflation/euhicp.hpp>
#include <ql/termstructures/inflation/inflationhelpers.hpp>
#include <ql/termstructures/yield/flatforward.hpp>
#include <ql/time/calendars/nullcalendar.hpp>
#include <ql/time/daycounters/actual365fixed.hpp>
#include <qle/utilities/inflation.hpp>

Go to the source code of this file.

Functions

 BOOST_AUTO_TEST_CASE (testZeroInflationCurveNonInterpolatedLastMonthFixingUnknown)
 
 BOOST_AUTO_TEST_CASE (testZeroInflationCurveNonInterpolatedLastMonthFixing)
 
 BOOST_AUTO_TEST_CASE (testZeroInflationCurveInterpolatedLastMonthFixing)
 
 BOOST_AUTO_TEST_CASE (testZeroInflationCurveNonInterpolatedLastMonthFixingUnknownWithSeasonality)
 
 BOOST_AUTO_TEST_CASE (testZeroInflationCurveNonInterpolatedLastMonthFixingWithSeasonality)
 

Function Documentation

◆ BOOST_AUTO_TEST_CASE() [1/5]

BOOST_AUTO_TEST_CASE ( testZeroInflationCurveNonInterpolatedLastMonthFixingUnknown  )

Definition at line 107 of file inflationcurve.cpp.

107 {
108
109 CommonData cd;
110 Settings::instance().evaluationDate() = cd.today;
111 bool isInterpolated = false;
112 bool useLastKnownFixingDateAsBaseDate = false;
113 // Build Curve and Index
114 QuantLib::ext::shared_ptr<ZeroInflationIndex> curveBuildIndex = QuantLib::ext::make_shared<EUHICPXT>(false);
115 addFixings(cd.cpiFixings, *curveBuildIndex);
116 auto curve = buildZeroInflationCurve(cd, useLastKnownFixingDateAsBaseDate, curveBuildIndex, isInterpolated);
117
118 BOOST_CHECK_NO_THROW(curve->zeroRate(1.0));
119
120 auto index = curveBuildIndex->clone(Handle<ZeroInflationTermStructure>(curve));
121
122 std::vector<Date> expectedPillarDates{Date(1, June, 2022), Date(1, June, 2023), Date(1, June, 2024),
123 Date(1, June, 2025), Date(1, June, 2027)};
124
125 std::vector<Real> expectedZeroRates{0.06, 0.06, 0.04, 0.03, 0.02};
126
127 std::vector<Real> expectedCPIs{100., 106., 108.171622850024, 109.281549591561, 110.414070537467};
128
129 BOOST_CHECK_EQUAL(curve->baseDate(), expectedPillarDates.front());
130
131 BOOST_CHECK_EQUAL(curve->dates().size(), expectedPillarDates.size());
132
133 for (size_t i = 0; i < expectedPillarDates.size(); ++i) {
134 BOOST_CHECK_EQUAL(curve->dates().at(i), expectedPillarDates.at(i));
135 BOOST_CHECK_CLOSE(curve->zeroRate(curve->dates().at(i), 0 * Days), expectedZeroRates.at(i), cd.tolerance);
136 }
137
138 // Check index fixing forecasts
139
140 for (size_t i = 0; i < expectedPillarDates.size(); ++i) {
141 auto forwardCPI = index->fixing(expectedPillarDates.at(i));
142 BOOST_CHECK_CLOSE(forwardCPI, expectedCPIs.at(i), cd.tolerance);
143 }
144}

◆ BOOST_AUTO_TEST_CASE() [2/5]

BOOST_AUTO_TEST_CASE ( testZeroInflationCurveNonInterpolatedLastMonthFixing  )

Definition at line 146 of file inflationcurve.cpp.

146 {
147
148 CommonData cd;
149 Settings::instance().evaluationDate() = cd.today;
150 bool isInterpolated = false;
151 bool useLastKnownFixingDateAsBaseDate = true;
152 // Build Curve and Index
153 QuantLib::ext::shared_ptr<ZeroInflationIndex> curveBuildIndex = QuantLib::ext::make_shared<EUHICPXT>(false);
154 addFixings(cd.cpiFixings, *curveBuildIndex);
155 auto curve = buildZeroInflationCurve(cd, useLastKnownFixingDateAsBaseDate, curveBuildIndex, isInterpolated);
156
157 BOOST_CHECK_NO_THROW(curve->zeroRate(1.0));
158
159 auto index = curveBuildIndex->clone(Handle<ZeroInflationTermStructure>(curve));
160
161 std::vector<Date> expectedPillarDates{Date(1, July, 2022), Date(1, June, 2023), Date(1, June, 2024),
162 Date(1, June, 2025), Date(1, June, 2027)};
163
164 std::vector<Real> expectedZeroRates{0.02097086546, 0.02097086546, 0.02068868041, 0.01710609424437, 0.01223686945};
165
166 std::vector<Real> expectedCPIs{104, 106., 108.171622850024, 109.281549591561, 110.414070537467};
167
168 BOOST_CHECK_EQUAL(curve->baseDate(), expectedPillarDates.front());
169
170 BOOST_CHECK_EQUAL(curve->dates().size(), expectedPillarDates.size());
171
172 for (size_t i = 0; i < expectedPillarDates.size(); ++i) {
173 BOOST_CHECK_EQUAL(curve->dates().at(i), expectedPillarDates.at(i));
174 BOOST_CHECK_CLOSE(curve->zeroRate(curve->dates().at(i), 0 * Days), expectedZeroRates.at(i), cd.tolerance);
175 }
176
177 // Check index fixing forecasts
178
179 for (size_t i = 0; i < expectedPillarDates.size(); ++i) {
180 auto forwardCPI = index->fixing(expectedPillarDates.at(i));
181 BOOST_CHECK_CLOSE(forwardCPI, expectedCPIs.at(i), cd.tolerance);
182 }
183}

◆ BOOST_AUTO_TEST_CASE() [3/5]

BOOST_AUTO_TEST_CASE ( testZeroInflationCurveInterpolatedLastMonthFixing  )

Definition at line 185 of file inflationcurve.cpp.

185 {
186
187 CommonData cd;
188 Settings::instance().evaluationDate() = cd.today;
189 bool isInterpolated = true;
190 bool useLastKnownFixingDateAsBaseDate = true;
191 // Build Curve and Index
192 QuantLib::ext::shared_ptr<ZeroInflationIndex> curveBuildIndex = QuantLib::ext::make_shared<EUHICPXT>(false);
193 addFixings(cd.cpiFixings, *curveBuildIndex);
194 auto curve = buildZeroInflationCurve(cd, useLastKnownFixingDateAsBaseDate, curveBuildIndex, isInterpolated);
195
196 BOOST_CHECK_NO_THROW(curve->zeroRate(1.0));
197
198 auto index = curveBuildIndex->clone(Handle<ZeroInflationTermStructure>(curve));
199
200 std::vector<Date> expectedPillarDates{Date(1, July, 2022), Date(1, July, 2023), Date(1, July, 2024),
201 Date(1, July, 2025), Date(1, July, 2027)};
202
203 std::vector<Real> expectedZeroRates{0.03945267289772, 0.03945267289772, 0.02921461897637, 0.02277721089513,
204 0.01564691567};
205
206 std::vector<Date> fixingDates{Date(15, June, 2022), Date(15, June, 2023), Date(15, June, 2024),
207 Date(15, June, 2025), Date(15, June, 2027)};
208
209 // Base CPI is 100 + (104-100)*14/31, and then for the forward cpi it is baseCPI * (1+r)^T
210 std::vector<Real> expectedCPIs{101.806451613, 107.914838710, 110.125690876, 111.255667907, 112.408647296};
211
212 BOOST_CHECK_EQUAL(curve->baseDate(), expectedPillarDates.front());
213
214 BOOST_CHECK_EQUAL(curve->dates().size(), expectedPillarDates.size());
215
216 for (size_t i = 0; i < expectedPillarDates.size(); ++i) {
217 BOOST_CHECK_EQUAL(curve->dates().at(i), expectedPillarDates.at(i));
218 BOOST_CHECK_CLOSE(curve->zeroRate(curve->dates().at(i), 0 * Days), expectedZeroRates.at(i), 1e-6);
219 }
220
221 // Check index fixing forecasts
222
223 for (size_t i = 0; i < fixingDates.size(); ++i) {
224 Date fixDate1 = inflationPeriod(fixingDates.at(i), index->frequency()).first;
225 Date fixDate2 = inflationPeriod(fixingDates.at(i), index->frequency()).second + 1 * Days;
226 Rate cpi1 = index->fixing(fixDate1);
227 Rate cpi2 = index->fixing(fixDate2);
228 auto forwardCPI = cpi1 + (cpi2 - cpi1) * 14 / 31;
229 BOOST_CHECK_CLOSE(forwardCPI, expectedCPIs.at(i), cd.tolerance);
230 }
231}

◆ BOOST_AUTO_TEST_CASE() [4/5]

BOOST_AUTO_TEST_CASE ( testZeroInflationCurveNonInterpolatedLastMonthFixingUnknownWithSeasonality  )

Definition at line 233 of file inflationcurve.cpp.

233 {
234
235 CommonData cd;
236 Settings::instance().evaluationDate() = cd.today;
237 bool isInterpolated = false;
238 bool useLastKnownFixingDateAsBaseDate = false;
239 // Build Curve and Index
240 QuantLib::ext::shared_ptr<ZeroInflationIndex> curveBuildIndex = QuantLib::ext::make_shared<EUHICPXT>(false);
241 addFixings(cd.cpiFixings, *curveBuildIndex);
242 auto seasonalityCurve = buildSeasonalityCurve();
243 auto curve = buildZeroInflationCurve(cd, useLastKnownFixingDateAsBaseDate, curveBuildIndex, isInterpolated,
244 seasonalityCurve);
245 BOOST_CHECK_NO_THROW(curve->zeroRate(1.0));
246
247 auto index = curveBuildIndex->clone(Handle<ZeroInflationTermStructure>(curve));
248
249 std::vector<Date> expectedPillarDates{Date(1, June, 2022), Date(1, June, 2023), Date(1, June, 2024),
250 Date(1, June, 2025), Date(1, June, 2027)};
251
252 std::vector<Real> expectedZeroRates{0.06, 0.06, 0.04, 0.03, 0.02};
253
254 std::vector<Real> expectedCPIs{100., 106., 108.171622850024, 109.281549591561, 110.414070537467};
255
256 BOOST_CHECK_EQUAL(curve->baseDate(), expectedPillarDates.front());
257
258 BOOST_CHECK_EQUAL(curve->dates().size(), expectedPillarDates.size());
259
260 for (size_t i = 0; i < expectedPillarDates.size(); ++i) {
261 BOOST_CHECK_EQUAL(curve->dates().at(i), expectedPillarDates.at(i));
262 BOOST_CHECK_CLOSE(curve->zeroRate(curve->dates().at(i), 0 * Days), expectedZeroRates.at(i), cd.tolerance);
263 BOOST_CHECK_CLOSE(curve->data().at(i), expectedZeroRates.at(i), cd.tolerance);
264 }
265
266 // Check index fixing forecasts
267
268 for (size_t i = 0; i < expectedPillarDates.size(); ++i) {
269 auto forwardCPI = index->fixing(expectedPillarDates.at(i));
270 BOOST_CHECK_CLOSE(forwardCPI, expectedCPIs.at(i), cd.tolerance);
271 }
272}

◆ BOOST_AUTO_TEST_CASE() [5/5]

BOOST_AUTO_TEST_CASE ( testZeroInflationCurveNonInterpolatedLastMonthFixingWithSeasonality  )

Definition at line 274 of file inflationcurve.cpp.

274 {
275
276 CommonData cd;
277 Settings::instance().evaluationDate() = cd.today;
278 bool isInterpolated = false;
279 bool useLastKnownFixingDateAsBaseDate = true;
280 // Build Curve and Index
281 QuantLib::ext::shared_ptr<ZeroInflationIndex> curveBuildIndex = QuantLib::ext::make_shared<EUHICPXT>(false);
282 addFixings(cd.cpiFixings, *curveBuildIndex);
283 auto seasonalityCurve = buildSeasonalityCurve();
284 auto curve = buildZeroInflationCurve(cd, useLastKnownFixingDateAsBaseDate, curveBuildIndex, isInterpolated,
285 seasonalityCurve);
286
287 BOOST_CHECK_NO_THROW(curve->zeroRate(1.0));
288
289 auto index = curveBuildIndex->clone(Handle<ZeroInflationTermStructure>(curve));
290
291 std::vector<Date> expectedPillarDates{Date(1, July, 2022), Date(1, June, 2023), Date(1, June, 2024),
292 Date(1, June, 2025), Date(1, June, 2027)};
293
294 std::vector<Real> expectedZeroRates{0.02097086546, 0.02097086546, 0.02068868041, 0.01710609424437, 0.01223686945};
295 std::vector<Real> expectedZeroRatesWithoutSeasonality{0.02097086546, -0.05439424967, -0.01603861959, -0.00711164972,
296 -0.00213855283};
297 std::vector<Real> expectedCPIs{104, 106., 108.171622850024, 109.281549591561, 110.414070537467};
298
299 BOOST_CHECK_EQUAL(curve->baseDate(), expectedPillarDates.front());
300
301 BOOST_CHECK_EQUAL(curve->dates().size(), expectedPillarDates.size());
302
303 for (size_t i = 0; i < expectedPillarDates.size(); ++i) {
304 BOOST_CHECK_EQUAL(curve->dates().at(i), expectedPillarDates.at(i));
305 BOOST_CHECK_CLOSE(curve->data().at(i), expectedZeroRatesWithoutSeasonality.at(i), cd.tolerance);
306 BOOST_CHECK_CLOSE(curve->zeroRate(curve->dates().at(i), 0 * Days), expectedZeroRates.at(i), cd.tolerance);
307 }
308 // Check index fixing forecasts
309
310 for (size_t i = 0; i < expectedPillarDates.size(); ++i) {
311 auto forwardCPI = index->fixing(expectedPillarDates.at(i));
312 BOOST_CHECK_CLOSE(forwardCPI, expectedCPIs.at(i), cd.tolerance);
313 }
314}