Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
inflationcurve.cpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2020 Quaternion Risk Management Ltd
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// clang-format off
20#include <boost/test/unit_test.hpp>
21#include <boost/test/data/test_case.hpp>
22
33#include <oret/datapaths.hpp>
34#include <oret/toplevelfixture.hpp>
35
36#include <boost/algorithm/string.hpp>
37#include <boost/make_shared.hpp>
38
39using namespace QuantLib;
40using namespace QuantExt;
41using namespace boost::unit_test_framework;
42using namespace std;
43using namespace ore;
44using namespace ore::data;
45
47
48namespace {
49
50// Construct and hold the arguments needed to construct a TodaysMarket.
51struct TodaysMarketArguments {
52
53 TodaysMarketArguments(const Date& asof, const string& inputDir, const string& marketFile,
54 const string& fixingsFile, const string& conventionsFile)
55 : asof(asof) {
56
57 Settings::instance().evaluationDate() = asof;
58
59 string filename = inputDir + "/" + conventionsFile;
60 conventions->fromFile(TEST_INPUT_FILE(filename));
61 InstrumentConventions::instance().setConventions(conventions);
62
63 filename = inputDir + "/curveconfig.xml";
64 curveConfigs->fromFile(TEST_INPUT_FILE(filename));
65
66 filename = inputDir + "/todaysmarket.xml";
67 todaysMarketParameters->fromFile(TEST_INPUT_FILE(filename));
68
69 filename = inputDir + "/" + marketFile;
70 string fixingsFilename = inputDir + "/" + fixingsFile;
71 loader = QuantLib::ext::make_shared<CSVLoader>(TEST_INPUT_FILE(filename), TEST_INPUT_FILE(fixingsFilename), false);
72 }
73
74 Date asof;
75 QuantLib::ext::shared_ptr<Conventions> conventions = QuantLib::ext::make_shared<Conventions>();
76 QuantLib::ext::shared_ptr<CurveConfigurations> curveConfigs = QuantLib::ext::make_shared<CurveConfigurations>();
77 QuantLib::ext::shared_ptr<TodaysMarketParameters> todaysMarketParameters = QuantLib::ext::make_shared<TodaysMarketParameters>();
78 QuantLib::ext::shared_ptr<Loader> loader;
79};
80
81}
82
83BOOST_FIXTURE_TEST_SUITE(OREDataTestSuite, ore::test::TopLevelFixture)
84
85BOOST_AUTO_TEST_SUITE(InflationCurveTests)
86
87// Test AU CPI bootstrap before and after index publication date in Oct 2020 (28 Oct 2020).
88// Mirrors the conventions from the example in section 2.5 of AFMA Inflation Product Conventions, May 2017.
89
90vector<Date> auCpiTestDates{
91 Date(27, Oct, 2020), // Before Q3 CPI release date => swaps start on 15 Sep referencing Q2 CPI
92 Date(28, Oct, 2020), // On Q3 CPI release date => swap start depends on PublicationRoll
93 Date(29, Oct, 2020) // After Q3 CPI release date => swaps start on 15 Dec referencing Q3 CPI
94};
95
96vector<string> publicationRolls{
97 "on", // Roll on the cpi release date
98 "after" // Roll after the cpi release date
99};
100
101BOOST_DATA_TEST_CASE(testAuCpiZcInflationCurve, bdata::make(auCpiTestDates) * bdata::make(publicationRolls),
102 asof, publicationRoll) {
103
104 BOOST_TEST_MESSAGE("Testing AU CPI zero coupon inflation curve bootstrap on date " << io::iso_date(asof));
105
106 // Create the market arguments. The fixing file on the release date depends on the publication roll setting.
107 string marketFile = "market_" + to_string(io::iso_date(asof)) + ".txt";
108 string fixingsFile = "fixings_" + to_string(io::iso_date(asof));
109 if (asof == Date(28, Oct, 2020)) {
110 fixingsFile += "_" + publicationRoll;
111 }
112 fixingsFile += ".txt";
113 string conventionsFile = "conventions_" + publicationRoll + ".xml";
114 TodaysMarketArguments tma(asof, "aucpi_zc", marketFile, fixingsFile, conventionsFile);
115
116 // Check that the market builds without error.
117 QuantLib::ext::shared_ptr<TodaysMarket> market;
118 BOOST_REQUIRE_NO_THROW(market = QuantLib::ext::make_shared<TodaysMarket>(tma.asof, tma.todaysMarketParameters,
119 tma.loader, tma.curveConfigs, false, true, false));
120
121 // Portfolio containing 2 AU CPI zero coupon swaps, AUD 10M, that should price at 0, i.e. NPV < AUD 0.01.
122 // Similar to the fixing file, the helpers on the release date depend on the publication roll setting.
123 string portfolioFile = "aucpi_zc/portfolio_" + to_string(io::iso_date(asof));
124 if (asof == Date(28, Oct, 2020)) {
125 portfolioFile += "_" + publicationRoll;
126 }
127 portfolioFile += ".xml";
128
129 QuantLib::ext::shared_ptr<EngineData> engineData = QuantLib::ext::make_shared<EngineData>();
130 engineData->fromFile(TEST_INPUT_FILE("aucpi_zc/pricingengine.xml"));
131 QuantLib::ext::shared_ptr<EngineFactory> factory = QuantLib::ext::make_shared<EngineFactory>(engineData, market);
132 QuantLib::ext::shared_ptr<Portfolio> portfolio = QuantLib::ext::make_shared<Portfolio>();
133 portfolio->fromFile(TEST_INPUT_FILE(portfolioFile));
134 portfolio->build(factory);
135
136 BOOST_CHECK_EQUAL(portfolio->size(), 2);
137 for (const auto& [tradeId, trade] : portfolio->trades()) {
138 BOOST_CHECK_SMALL(trade->instrument()->NPV(), 0.01);
139 }
140}
141
142BOOST_AUTO_TEST_SUITE_END()
143
144BOOST_AUTO_TEST_SUITE_END()
145
146// clang-format on
Market Datum Loader Implementation.
Pricing Engine Factory.
Market Datum Loader Interface.
Market Datum parser.
std::string to_string(const LocationInfo &l)
Definition: ast.cpp:28
Serializable Credit Default Swap.
Definition: namespaces.docs:23
Map text representations to QuantLib/QuantExt types.
Portfolio class.
BOOST_DATA_TEST_CASE(testMartingaleProperty, bdata::make(driftFreeState) *bdata::make(steps), driftFreeState, steps)
vector< string > curveConfigs
string conversion utilities
An concrete implementation of the Market class that loads todays market and builds the required curve...
base trade data model and serialization
Wrapper class for QuantLib term structures.