Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
fxvolcurve.cpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2021 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
35#include <oret/datapaths.hpp>
36#include <oret/toplevelfixture.hpp>
37
38#include <boost/algorithm/string.hpp>
39#include <boost/make_shared.hpp>
40
41using namespace QuantLib;
42using namespace QuantExt;
43using namespace boost::unit_test_framework;
44using namespace std;
45using namespace ore;
46using namespace ore::data;
47
49
50namespace {
51
52// Construct and hold the arguments needed to construct a TodaysMarket.
53struct TodaysMarketArguments {
54
55 TodaysMarketArguments(const Date& asof, const string& curveconfigFile)
56 : asof(asof) {
57
58 Settings::instance().evaluationDate() = asof;
59
60 string filename = "conventions.xml";
61 conventions->fromFile(TEST_INPUT_FILE(filename));
62 InstrumentConventions::instance().setConventions(conventions);
63
64 filename = curveconfigFile;
65 curveConfigs->fromFile(TEST_INPUT_FILE(filename));
66
67 filename = "todaysmarket.xml";
68 todaysMarketParameters->fromFile(TEST_INPUT_FILE(filename));
69
70 filename = "market.txt";
71 string fixingsFilename = "fixings.txt";
72 loader = QuantLib::ext::make_shared<CSVLoader>(TEST_INPUT_FILE(filename), TEST_INPUT_FILE(fixingsFilename), false);
73 }
74
75 Date asof;
76 QuantLib::ext::shared_ptr<Conventions> conventions = QuantLib::ext::make_shared<Conventions>();
77 QuantLib::ext::shared_ptr<CurveConfigurations> curveConfigs = QuantLib::ext::make_shared<CurveConfigurations>();
78 QuantLib::ext::shared_ptr<TodaysMarketParameters> todaysMarketParameters = QuantLib::ext::make_shared<TodaysMarketParameters>();
79 QuantLib::ext::shared_ptr<Loader> loader;
80};
81
82}
83
84BOOST_FIXTURE_TEST_SUITE(OREDataTestSuite, ore::test::TopLevelFixture)
85
86BOOST_AUTO_TEST_SUITE(FxVolCurveTests)
87
88BOOST_AUTO_TEST_CASE(testFxVolWildCards) {
89
90 BOOST_TEST_MESSAGE("Testing FxVolatility Curve Wildcards");
91
92 std::vector<std::pair<std::string, std::string>> curveConfigs = {
93 { "curveconfig_full.xml", "curveconfig_wc.xml" },
94 { "curveconfig_full_M.xml", "curveconfig_wc_M.xml" }
95 };
96
97 for (auto& c : curveConfigs) {
98 Date asof(31, Dec, 2018);
99 TodaysMarketArguments tma_full(asof, c.first);
100 TodaysMarketArguments tma_wc(asof, c.second);
101
102 // Check that the market builds without error.
103 QuantLib::ext::shared_ptr<TodaysMarket> market_full = QuantLib::ext::make_shared<TodaysMarket>(tma_full.asof, tma_full.todaysMarketParameters,
104 tma_full.loader, tma_full.curveConfigs, false, true, false);
105 QuantLib::ext::shared_ptr<TodaysMarket> market_wc = QuantLib::ext::make_shared<TodaysMarket>(tma_wc.asof, tma_wc.todaysMarketParameters,
106 tma_wc.loader, tma_wc.curveConfigs, false, true, false);
107
108 // Portfolio containing 2 AU CPI zero coupon swaps, AUD 10M, that should price at 0, i.e. NPV < AUD 0.01.
109 // Similar to the fixing file, the helpers on the release date depend on the publication roll setting.
110
111 QuantLib::ext::shared_ptr<EngineData> engineData = QuantLib::ext::make_shared<EngineData>();
112 engineData->model("FxOption") = "GarmanKohlhagen";
113 engineData->engine("FxOption") = "AnalyticEuropeanEngine";
114 QuantLib::ext::shared_ptr<EngineFactory> engineFactory_full = QuantLib::ext::make_shared<EngineFactory>(engineData, market_full);
115 QuantLib::ext::shared_ptr<EngineFactory> engineFactory_wc = QuantLib::ext::make_shared<EngineFactory>(engineData, market_wc);
116
117
118 string portfolioFile = "portfolio.xml";
119 QuantLib::ext::shared_ptr<Portfolio> portfolio_full = QuantLib::ext::make_shared<Portfolio>();
120 portfolio_full->fromFile(TEST_INPUT_FILE(portfolioFile));
121 portfolio_full->build(engineFactory_full);
122
123 QuantLib::ext::shared_ptr<Portfolio> portfolio_wc = QuantLib::ext::make_shared<Portfolio>();
124 portfolio_wc->fromFile(TEST_INPUT_FILE(portfolioFile));
125 portfolio_wc->build(engineFactory_wc);
126
127 BOOST_CHECK_EQUAL(portfolio_full->size(), portfolio_wc->size());
128
129 auto portfolioFullIt = portfolio_full->trades().begin();
130 auto portfolioWCIt = portfolio_wc->trades().begin();
131
132 for (Size i = 0; i < portfolio_full->trades().size(); i++) {
133 BOOST_CHECK_CLOSE(portfolioFullIt->second->instrument()->NPV(), portfolioWCIt->second->instrument()->NPV(), 0.001);
134 portfolioFullIt++;
135 portfolioWCIt++;
136 }
137 }
138}
139
140BOOST_AUTO_TEST_SUITE_END()
141
142BOOST_AUTO_TEST_SUITE_END()
Engine builder for FX Options.
Market Datum Loader Implementation.
Pricing Engine Factory.
Market Datum Loader Interface.
Market Datum parser.
Size size(const ValueType &v)
Definition: value.cpp:145
Serializable Credit Default Swap.
Definition: namespaces.docs:23
Map text representations to QuantLib/QuantExt types.
Portfolio class.
vector< string > curveConfigs
BOOST_AUTO_TEST_CASE(testFxVolWildCards)
Definition: fxvolcurve.cpp:88
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.