Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
Functions
scenariosimmarket.cpp File Reference
#include <boost/test/unit_test.hpp>
#include <orea/scenario/scenariosimmarket.hpp>
#include <orea/scenario/scenariosimmarketparameters.hpp>
#include <ored/configuration/conventions.hpp>
#include <ored/marketdata/market.hpp>
#include <ored/marketdata/marketimpl.hpp>
#include <ored/utilities/log.hpp>
#include <oret/toplevelfixture.hpp>
#include <ql/termstructures/credit/flathazardrate.hpp>
#include <ql/termstructures/volatility/capfloor/constantcapfloortermvol.hpp>
#include <ql/termstructures/volatility/equityfx/blackconstantvol.hpp>
#include <ql/termstructures/volatility/swaption/swaptionconstantvol.hpp>
#include <ql/termstructures/yield/flatforward.hpp>
#include <ql/time/daycounters/actualactual.hpp>
#include <test/oreatoplevelfixture.hpp>
#include "testmarket.hpp"
#include <ql/indexes/ibor/all.hpp>

Go to the source code of this file.

Functions

void testFxSpot (QuantLib::ext::shared_ptr< ore::data::Market > &initMarket, QuantLib::ext::shared_ptr< ore::analytics::ScenarioSimMarket > &simMarket, QuantLib::ext::shared_ptr< analytics::ScenarioSimMarketParameters > &parameters)
 
void testDiscountCurve (QuantLib::ext::shared_ptr< ore::data::Market > &initMarket, QuantLib::ext::shared_ptr< ore::analytics::ScenarioSimMarket > &simMarket, QuantLib::ext::shared_ptr< analytics::ScenarioSimMarketParameters > &parameters)
 
void testIndexCurve (QuantLib::ext::shared_ptr< ore::data::Market > &initMarket, QuantLib::ext::shared_ptr< ore::analytics::ScenarioSimMarket > &simMarket, QuantLib::ext::shared_ptr< analytics::ScenarioSimMarketParameters > &parameters)
 
void testSwaptionVolCurve (QuantLib::ext::shared_ptr< ore::data::Market > &initMarket, QuantLib::ext::shared_ptr< ore::analytics::ScenarioSimMarket > &simMarket, QuantLib::ext::shared_ptr< analytics::ScenarioSimMarketParameters > &parameters)
 
void testFxVolCurve (QuantLib::ext::shared_ptr< data::Market > &initMarket, QuantLib::ext::shared_ptr< analytics::ScenarioSimMarket > &simMarket, QuantLib::ext::shared_ptr< analytics::ScenarioSimMarketParameters > &parameters)
 
void testDefaultCurve (QuantLib::ext::shared_ptr< ore::data::Market > &initMarket, QuantLib::ext::shared_ptr< ore::analytics::ScenarioSimMarket > &simMarket, QuantLib::ext::shared_ptr< analytics::ScenarioSimMarketParameters > &parameters)
 
void testZeroInflationCurve (QuantLib::ext::shared_ptr< ore::data::Market > &initMarket, QuantLib::ext::shared_ptr< ore::analytics::ScenarioSimMarket > &simMarket, QuantLib::ext::shared_ptr< analytics::ScenarioSimMarketParameters > &parameters)
 
void testCorrelationCurve (QuantLib::ext::shared_ptr< ore::data::Market > &initMarket, QuantLib::ext::shared_ptr< ore::analytics::ScenarioSimMarket > &simMarket, QuantLib::ext::shared_ptr< analytics::ScenarioSimMarketParameters > &parameters)
 
void testToXML (QuantLib::ext::shared_ptr< analytics::ScenarioSimMarketParameters > params)
 
 BOOST_AUTO_TEST_CASE (testScenarioSimMarket)
 

Function Documentation

◆ testFxSpot()

void testFxSpot ( QuantLib::ext::shared_ptr< ore::data::Market > &  initMarket,
QuantLib::ext::shared_ptr< ore::analytics::ScenarioSimMarket > &  simMarket,
QuantLib::ext::shared_ptr< analytics::ScenarioSimMarketParameters > &  parameters 
)

Definition at line 101 of file scenariosimmarket.cpp.

103 {
104
105 for (const auto& ccy : parameters->ccys()) {
106 if (ccy != parameters->baseCcy()) {
107 string ccyPair(parameters->baseCcy() + ccy);
108 string ccyReverse(ccy + parameters->baseCcy());
109
110 Handle<Quote> fx_sim = simMarket->fxSpot(ccyPair);
111 Handle<Quote> fx_init = initMarket->fxSpot(ccyPair);
112 if (fx_sim.empty())
113 BOOST_FAIL("fx_sim handle is empty");
114 if (fx_init.empty())
115 BOOST_FAIL("fx_init handle is empty");
116
117 BOOST_CHECK_CLOSE(fx_init->value(), fx_sim->value(), 1e-12);
118
119 fx_sim = simMarket->fxSpot(ccyReverse);
120 fx_init = initMarket->fxSpot(ccyReverse);
121 if (fx_sim.empty())
122 BOOST_FAIL("fx_sim handle is empty");
123 if (fx_init.empty())
124 BOOST_FAIL("fx_init handle is empty");
125
126 BOOST_CHECK_CLOSE(fx_init->value(), fx_sim->value(), 1e-12);
127 }
128 }
129}
+ Here is the caller graph for this function:

◆ testDiscountCurve()

void testDiscountCurve ( QuantLib::ext::shared_ptr< ore::data::Market > &  initMarket,
QuantLib::ext::shared_ptr< ore::analytics::ScenarioSimMarket > &  simMarket,
QuantLib::ext::shared_ptr< analytics::ScenarioSimMarketParameters > &  parameters 
)

Definition at line 131 of file scenariosimmarket.cpp.

133 {
134
135 for (const auto& ccy : parameters->ccys()) {
136 Handle<YieldTermStructure> simCurve = simMarket->discountCurve(ccy);
137 Handle<YieldTermStructure> initCurve = initMarket->discountCurve(ccy);
138
139 BOOST_CHECK_CLOSE(simCurve->discount(0.5), initCurve->discount(0.5), 1e-12);
140 }
141}
+ Here is the caller graph for this function:

◆ testIndexCurve()

void testIndexCurve ( QuantLib::ext::shared_ptr< ore::data::Market > &  initMarket,
QuantLib::ext::shared_ptr< ore::analytics::ScenarioSimMarket > &  simMarket,
QuantLib::ext::shared_ptr< analytics::ScenarioSimMarketParameters > &  parameters 
)

Definition at line 143 of file scenariosimmarket.cpp.

145 {
146
147 for (const auto& ind : parameters->indices()) {
148 Handle<YieldTermStructure> simCurve = simMarket->iborIndex(ind)->forwardingTermStructure();
149 Handle<YieldTermStructure> initCurve = initMarket->iborIndex(ind)->forwardingTermStructure();
150
151 BOOST_CHECK_CLOSE(simCurve->discount(1), initCurve->discount(1), 1e-4);
152 }
153}
+ Here is the caller graph for this function:

◆ testSwaptionVolCurve()

void testSwaptionVolCurve ( QuantLib::ext::shared_ptr< ore::data::Market > &  initMarket,
QuantLib::ext::shared_ptr< ore::analytics::ScenarioSimMarket > &  simMarket,
QuantLib::ext::shared_ptr< analytics::ScenarioSimMarketParameters > &  parameters 
)

Definition at line 155 of file scenariosimmarket.cpp.

157 {
158 for (const auto& ccy : parameters->ccys()) {
159 Handle<QuantLib::SwaptionVolatilityStructure> simCurve = simMarket->swaptionVol(ccy);
160 Handle<QuantLib::SwaptionVolatilityStructure> initCurve = initMarket->swaptionVol(ccy);
161 for (const auto& maturity : parameters->swapVolExpiries("")) {
162 for (const auto& tenor : parameters->swapVolTerms("")) {
163 BOOST_CHECK_CLOSE(simCurve->volatility(maturity, tenor, 0.0, true),
164 initCurve->volatility(maturity, tenor, 0.0, true), 1e-12);
165 }
166 }
167 }
168}
+ Here is the caller graph for this function:

◆ testFxVolCurve()

void testFxVolCurve ( QuantLib::ext::shared_ptr< data::Market > &  initMarket,
QuantLib::ext::shared_ptr< analytics::ScenarioSimMarket > &  simMarket,
QuantLib::ext::shared_ptr< analytics::ScenarioSimMarketParameters > &  parameters 
)

Definition at line 170 of file scenariosimmarket.cpp.

172 {
173 for (const auto& ccyPair : parameters->fxVolCcyPairs()) {
174 Handle<BlackVolTermStructure> simCurve = simMarket->fxVol(ccyPair);
175 Handle<BlackVolTermStructure> initCurve = initMarket->fxVol(ccyPair);
176 vector<Date> dates;
177 Date asof = initMarket->asofDate();
178 for (Size i = 0; i < parameters->fxVolExpiries(ccyPair).size(); i++) {
179 dates.push_back(asof + parameters->fxVolExpiries(ccyPair)[i]);
180 }
181
182 for (const auto& date : dates) {
183 BOOST_CHECK_CLOSE(simCurve->blackVol(date, 0.0, true), initCurve->blackVol(date, 0.0, true), 1e-12);
184 }
185 }
186}
Size size(const ValueType &v)
Date asof(14, Jun, 2018)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ testDefaultCurve()

void testDefaultCurve ( QuantLib::ext::shared_ptr< ore::data::Market > &  initMarket,
QuantLib::ext::shared_ptr< ore::analytics::ScenarioSimMarket > &  simMarket,
QuantLib::ext::shared_ptr< analytics::ScenarioSimMarketParameters > &  parameters 
)

Definition at line 188 of file scenariosimmarket.cpp.

190 {
191 for (const auto& spec : parameters->defaultNames()) {
192
193 Handle<DefaultProbabilityTermStructure> simCurve = simMarket->defaultCurve(spec)->curve();
194 Handle<DefaultProbabilityTermStructure> initCurve = initMarket->defaultCurve(spec)->curve();
195 BOOST_CHECK_EQUAL(initCurve->referenceDate(), simCurve->referenceDate());
196 vector<Date> dates;
197 Date asof = initMarket->asofDate();
198 for (Size i = 0; i < parameters->defaultTenors("").size(); i++) {
199 dates.push_back(asof + parameters->defaultTenors("")[i]);
200 }
201
202 for (const auto& date : dates) {
203 BOOST_CHECK_CLOSE(simCurve->survivalProbability(date, true), initCurve->survivalProbability(date, true),
204 1e-12);
205 }
206 }
207}
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ testZeroInflationCurve()

void testZeroInflationCurve ( QuantLib::ext::shared_ptr< ore::data::Market > &  initMarket,
QuantLib::ext::shared_ptr< ore::analytics::ScenarioSimMarket > &  simMarket,
QuantLib::ext::shared_ptr< analytics::ScenarioSimMarketParameters > &  parameters 
)

Definition at line 209 of file scenariosimmarket.cpp.

211 {
212 for (const auto& spec : parameters->zeroInflationIndices()) {
213
214 Handle<ZeroInflationTermStructure> simCurve = simMarket->zeroInflationIndex(spec)->zeroInflationTermStructure();
215 Handle<ZeroInflationTermStructure> initCurve =
216 initMarket->zeroInflationIndex(spec)->zeroInflationTermStructure();
217 BOOST_CHECK_EQUAL(initCurve->referenceDate(), simCurve->referenceDate());
218 vector<Date> dates;
219 Date asof = initMarket->asofDate();
220 for (Size i = 0; i < parameters->zeroInflationTenors("").size(); i++) {
221 dates.push_back(asof + parameters->zeroInflationTenors("")[i]);
222 }
223
224 for (const auto& date : dates) {
225 BOOST_CHECK_CLOSE(simCurve->zeroRate(date), initCurve->zeroRate(date), 1e-12);
226 }
227 }
228}
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ testCorrelationCurve()

void testCorrelationCurve ( QuantLib::ext::shared_ptr< ore::data::Market > &  initMarket,
QuantLib::ext::shared_ptr< ore::analytics::ScenarioSimMarket > &  simMarket,
QuantLib::ext::shared_ptr< analytics::ScenarioSimMarketParameters > &  parameters 
)

Definition at line 230 of file scenariosimmarket.cpp.

232 {
233 for (const auto& spec : parameters->correlationPairs()) {
234 vector<string> tokens;
235 boost::split(tokens, spec, boost::is_any_of(":&"));
236 QL_REQUIRE(tokens.size() == 2, "not a valid correlation pair: " << spec);
237 pair<string, string> pair = std::make_pair(tokens[0], tokens[1]);
238 Handle<QuantExt::CorrelationTermStructure> simCurve = simMarket->correlationCurve(pair.first, pair.second);
239 Handle<QuantExt::CorrelationTermStructure> initCurve = initMarket->correlationCurve(pair.first, pair.second);
240 BOOST_CHECK_EQUAL(initCurve->referenceDate(), simCurve->referenceDate());
241 vector<Date> dates;
242 Date asof = initMarket->asofDate();
243 for (Size i = 0; i < parameters->correlationExpiries().size(); i++) {
244 dates.push_back(asof + parameters->correlationExpiries()[i]);
245 }
246
247 for (const auto& date : dates) {
248 BOOST_CHECK_CLOSE(simCurve->correlation(date), initCurve->correlation(date), 1e-12);
249 }
250 }
251}
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ testToXML()

void testToXML ( QuantLib::ext::shared_ptr< analytics::ScenarioSimMarketParameters params)

Definition at line 253 of file scenariosimmarket.cpp.

253 {
254
255 BOOST_TEST_MESSAGE("Testing to XML...");
256 XMLDocument outDoc;
257 string testFile = "simtest.xml";
258 XMLNode* simulationNode = params->toXML(outDoc);
259
260 outDoc.appendNode(simulationNode);
261 outDoc.toFile(testFile);
262
263 QuantLib::ext::shared_ptr<analytics::ScenarioSimMarketParameters> newParams(new analytics::ScenarioSimMarketParameters());
264 newParams->fromFile(testFile);
265 BOOST_CHECK(*params == *newParams);
266
267 newParams->baseCcy() = "JPY";
268 BOOST_CHECK(*params != *newParams);
269
270 remove("simtest.xml");
271}
void appendNode(XMLNode *)
void toFile(const string &filename) const
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ BOOST_AUTO_TEST_CASE()

BOOST_AUTO_TEST_CASE ( testScenarioSimMarket  )

Definition at line 277 of file scenariosimmarket.cpp.

277 {
278 BOOST_TEST_MESSAGE("Testing OREAnalytics ScenarioSimMarket...");
279
280 SavedSettings backup;
281
282 Date today(20, Jan, 2015);
283 Settings::instance().evaluationDate() = today;
284 QuantLib::ext::shared_ptr<ore::data::Market> initMarket = QuantLib::ext::make_shared<TestMarket>(today);
285
286 // Empty scenario generator
287 QuantLib::ext::shared_ptr<ore::analytics::ScenarioGenerator> scenarioGenerator;
288
289 // build scenario
290 QuantLib::ext::shared_ptr<analytics::ScenarioSimMarketParameters> parameters = scenarioParameters();
291 convs();
292 // build scenario sim market
293 QuantLib::ext::shared_ptr<analytics::ScenarioSimMarket> simMarket(
294 new analytics::ScenarioSimMarket(initMarket, parameters));
295 simMarket->scenarioGenerator() = scenarioGenerator;
296
297 // test
298 testFxSpot(initMarket, simMarket, parameters);
299 testDiscountCurve(initMarket, simMarket, parameters);
300 testIndexCurve(initMarket, simMarket, parameters);
301 testSwaptionVolCurve(initMarket, simMarket, parameters);
302 testFxVolCurve(initMarket, simMarket, parameters);
303 testDefaultCurve(initMarket, simMarket, parameters);
304 testZeroInflationCurve(initMarket, simMarket, parameters);
305 testCorrelationCurve(initMarket, simMarket, parameters);
306 testToXML(parameters);
307}
Simulation Market updated with discrete scenarios.
QuantLib::ext::shared_ptr< data::Conventions > convs()
void testZeroInflationCurve(QuantLib::ext::shared_ptr< ore::data::Market > &initMarket, QuantLib::ext::shared_ptr< ore::analytics::ScenarioSimMarket > &simMarket, QuantLib::ext::shared_ptr< analytics::ScenarioSimMarketParameters > &parameters)
void testDefaultCurve(QuantLib::ext::shared_ptr< ore::data::Market > &initMarket, QuantLib::ext::shared_ptr< ore::analytics::ScenarioSimMarket > &simMarket, QuantLib::ext::shared_ptr< analytics::ScenarioSimMarketParameters > &parameters)
void testCorrelationCurve(QuantLib::ext::shared_ptr< ore::data::Market > &initMarket, QuantLib::ext::shared_ptr< ore::analytics::ScenarioSimMarket > &simMarket, QuantLib::ext::shared_ptr< analytics::ScenarioSimMarketParameters > &parameters)
void testDiscountCurve(QuantLib::ext::shared_ptr< ore::data::Market > &initMarket, QuantLib::ext::shared_ptr< ore::analytics::ScenarioSimMarket > &simMarket, QuantLib::ext::shared_ptr< analytics::ScenarioSimMarketParameters > &parameters)
void testIndexCurve(QuantLib::ext::shared_ptr< ore::data::Market > &initMarket, QuantLib::ext::shared_ptr< ore::analytics::ScenarioSimMarket > &simMarket, QuantLib::ext::shared_ptr< analytics::ScenarioSimMarketParameters > &parameters)
void testSwaptionVolCurve(QuantLib::ext::shared_ptr< ore::data::Market > &initMarket, QuantLib::ext::shared_ptr< ore::analytics::ScenarioSimMarket > &simMarket, QuantLib::ext::shared_ptr< analytics::ScenarioSimMarketParameters > &parameters)
void testToXML(QuantLib::ext::shared_ptr< analytics::ScenarioSimMarketParameters > params)
void testFxSpot(QuantLib::ext::shared_ptr< ore::data::Market > &initMarket, QuantLib::ext::shared_ptr< ore::analytics::ScenarioSimMarket > &simMarket, QuantLib::ext::shared_ptr< analytics::ScenarioSimMarketParameters > &parameters)
void testFxVolCurve(QuantLib::ext::shared_ptr< data::Market > &initMarket, QuantLib::ext::shared_ptr< analytics::ScenarioSimMarket > &simMarket, QuantLib::ext::shared_ptr< analytics::ScenarioSimMarketParameters > &parameters)
+ Here is the call graph for this function: