Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
basecorrelationcurve.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// clang-format on
23#include <oret/datapaths.hpp>
24#include <oret/toplevelfixture.hpp>
25
26#include <boost/make_shared.hpp>
27
33
34using namespace std;
35using namespace boost::unit_test_framework;
36using namespace QuantLib;
37using namespace QuantExt;
38using namespace ore::data;
39
41
42namespace {
43
44QuantLib::ext::shared_ptr<TodaysMarket> createTodaysMarket(const Date& asof, const string& inputDir) {
45
46 auto conventions = QuantLib::ext::make_shared<Conventions>();
47 // conventions->fromFile(TEST_INPUT_FILE(string(inputDir + "/conventions.xml")));
48 InstrumentConventions::instance().setConventions(conventions);
49
50 auto curveConfigs = QuantLib::ext::make_shared<CurveConfigurations>();
51 curveConfigs->fromFile(TEST_INPUT_FILE(string(inputDir + "/curveconfig.xml")));
52
53 auto todaysMarketParameters = QuantLib::ext::make_shared<TodaysMarketParameters>();
54 todaysMarketParameters->fromFile(TEST_INPUT_FILE(string(inputDir + "/todaysmarket.xml")));
55
56 auto loader = QuantLib::ext::make_shared<CSVLoader>(TEST_INPUT_FILE(string(inputDir + "/market.txt")),
57 TEST_INPUT_FILE(string(inputDir + "/fixings.txt")), false);
58
59 return QuantLib::ext::make_shared<TodaysMarket>(asof, todaysMarketParameters, loader, curveConfigs);
60}
61
62}
63
64BOOST_FIXTURE_TEST_SUITE(OREDataTestSuite, ore::test::TopLevelFixture)
65
66BOOST_AUTO_TEST_SUITE(BaseCorrelationCurveTests)
67
68// Sub-directories containing input data to test various base correlation curve and market data set-ups
69vector<string> setups{
70 "exp_terms_exp_dps_curve",
71 "exp_terms_exp_dps_surface",
72 "exp_terms_wc_dps_curve",
73 "exp_terms_wc_dps_surface",
74 "wc_terms_exp_dps_curve",
75 "wc_terms_exp_dps_surface",
76 "wc_terms_wc_dps_curve",
77 "wc_terms_wc_dps_surface"
78};
79
80BOOST_DATA_TEST_CASE(testBaseCorrelationStructureBuilding, bdata::make(setups), setup) {
81
82 BOOST_TEST_MESSAGE("Testing base correlation structure building using setup in " << setup);
83
84 Date asof(19, Oct, 2020);
85 Settings::instance().evaluationDate() = asof;
86
87 auto todaysMarket = createTodaysMarket(asof, setup);
88
89 // Get the built base correlation structure.
90 auto bc = todaysMarket->baseCorrelation("BASE_CORR_TEST");
91
92 // These are the values used in the test configurations.
93 Calendar calendar = parseCalendar("US settlement");
94 BusinessDayConvention bdc = Following;
95
96 // Tolerance for comparison.
97 Real tol = 1e-12;
98
99 // Read in the expected results.
100 string filename = setup + "/expected.csv";
101 CSVFileReader reader(TEST_INPUT_FILE(filename), true, ",");
102 BOOST_REQUIRE_EQUAL(reader.numberOfColumns(), 3);
103
104 BOOST_TEST_MESSAGE("term,detachment,expected_bc,calculated_bc,difference");
105 while (reader.next()) {
106
107 // Get the term, detachment point and expected base correlation
108 Period term = parsePeriod(reader.get(0));
109 Real dp = parseReal(reader.get(1));
110 Real expBc = parseReal(reader.get(2));
111
112 // Check
113 Date d = calendar.advance(asof, term, bdc);
114 Real calcBc = bc->correlation(d, dp);
115 Real difference = expBc - calcBc;
116 BOOST_TEST_MESSAGE(term << "," << fixed << setprecision(12) << dp << "," <<
117 expBc << "," << calcBc << "," << difference);
118 BOOST_CHECK_SMALL(difference, tol);
119 }
120}
121
122BOOST_AUTO_TEST_SUITE_END()
123
124BOOST_AUTO_TEST_SUITE_END()
utility class to access CSV files
Market Datum Loader Implementation.
Curve configuration repository.
Calendar parseCalendar(const string &s)
Convert text to QuantLib::Calendar.
Definition: parsers.cpp:157
Period parsePeriod(const string &s)
Convert text to QuantLib::Period.
Definition: parsers.cpp:171
Real parseReal(const string &s)
Convert text to Real.
Definition: parsers.cpp:112
Calendar calendar
Definition: utilities.cpp:441
Map text representations to QuantLib/QuantExt types.
BOOST_DATA_TEST_CASE(testMartingaleProperty, bdata::make(driftFreeState) *bdata::make(steps), driftFreeState, steps)
vector< string > curveConfigs
An concrete implementation of the Market class that loads todays market and builds the required curve...