Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
Functions
stresstest.cpp File Reference
#include <boost/test/unit_test.hpp>
#include <orea/cube/inmemorycube.hpp>
#include <orea/cube/npvcube.hpp>
#include <orea/engine/filteredsensitivitystream.hpp>
#include <orea/engine/observationmode.hpp>
#include <orea/engine/parametricvar.hpp>
#include <orea/engine/riskfilter.hpp>
#include <orea/engine/sensitivityaggregator.hpp>
#include <orea/engine/sensitivityanalysis.hpp>
#include <orea/engine/sensitivitycubestream.hpp>
#include <orea/engine/sensitivityfilestream.hpp>
#include <orea/engine/sensitivityinmemorystream.hpp>
#include <orea/engine/sensitivityrecord.hpp>
#include <orea/engine/sensitivitystream.hpp>
#include <orea/engine/stresstest.hpp>
#include <orea/engine/valuationcalculator.hpp>
#include <orea/engine/valuationengine.hpp>
#include <orea/scenario/clonescenariofactory.hpp>
#include <orea/scenario/scenariosimmarket.hpp>
#include <orea/scenario/scenariosimmarketparameters.hpp>
#include <orea/scenario/stressscenariogenerator.hpp>
#include <ored/model/lgmdata.hpp>
#include <ored/portfolio/builders/capfloor.hpp>
#include <ored/portfolio/builders/fxforward.hpp>
#include <ored/portfolio/builders/fxoption.hpp>
#include <ored/portfolio/builders/swap.hpp>
#include <ored/portfolio/builders/swaption.hpp>
#include <ored/portfolio/portfolio.hpp>
#include <ored/portfolio/swap.hpp>
#include <ored/portfolio/swaption.hpp>
#include <ored/utilities/log.hpp>
#include <ored/utilities/osutils.hpp>
#include <oret/toplevelfixture.hpp>
#include <ql/math/randomnumbers/mt19937uniformrng.hpp>
#include <ql/time/calendars/target.hpp>
#include <ql/time/date.hpp>
#include <ql/time/daycounters/actualactual.hpp>
#include <test/oreatoplevelfixture.hpp>
#include "testmarket.hpp"
#include "testportfolio.hpp"

Go to the source code of this file.

Functions

QuantLib::ext::shared_ptr< data::ConventionsstressConv ()
 
QuantLib::ext::shared_ptr< analytics::ScenarioSimMarketParameterssetupStressSimMarketData ()
 
QuantLib::ext::shared_ptr< StressTestScenarioDatasetupStressScenarioData ()
 
 BOOST_AUTO_TEST_CASE (regression)
 

Function Documentation

◆ stressConv()

QuantLib::ext::shared_ptr< data::Conventions > stressConv ( )

Definition at line 75 of file stresstest.cpp.

75 {
76 QuantLib::ext::shared_ptr<data::Conventions> conventions(new data::Conventions());
77
78 QuantLib::ext::shared_ptr<data::Convention> swapIndexConv(
79 new data::SwapIndexConvention("EUR-CMS-2Y", "EUR-6M-SWAP-CONVENTIONS"));
80 conventions->add(swapIndexConv);
81
82 // QuantLib::ext::shared_ptr<data::Convention> swapConv(
83 // new data::IRSwapConvention("EUR-6M-SWAP-CONVENTIONS", "TARGET", "Annual", "MF", "30/360", "EUR-EURIBOR-6M"));
84 conventions->add(QuantLib::ext::make_shared<data::IRSwapConvention>("EUR-6M-SWAP-CONVENTIONS", "TARGET", "A", "MF",
85 "30/360", "EUR-EURIBOR-6M"));
86 conventions->add(QuantLib::ext::make_shared<data::IRSwapConvention>("USD-3M-SWAP-CONVENTIONS", "TARGET", "Q", "MF",
87 "30/360", "USD-LIBOR-3M"));
88 conventions->add(QuantLib::ext::make_shared<data::IRSwapConvention>("USD-6M-SWAP-CONVENTIONS", "TARGET", "Q", "MF",
89 "30/360", "USD-LIBOR-6M"));
90 conventions->add(QuantLib::ext::make_shared<data::IRSwapConvention>("GBP-6M-SWAP-CONVENTIONS", "TARGET", "A", "MF",
91 "30/360", "GBP-LIBOR-6M"));
92 conventions->add(QuantLib::ext::make_shared<data::IRSwapConvention>("JPY-6M-SWAP-CONVENTIONS", "TARGET", "A", "MF",
93 "30/360", "JPY-LIBOR-6M"));
94 conventions->add(QuantLib::ext::make_shared<data::IRSwapConvention>("CHF-6M-SWAP-CONVENTIONS", "TARGET", "A", "MF",
95 "30/360", "CHF-LIBOR-6M"));
96
97 conventions->add(QuantLib::ext::make_shared<data::DepositConvention>("EUR-DEP-CONVENTIONS", "EUR-EURIBOR"));
98 conventions->add(QuantLib::ext::make_shared<data::DepositConvention>("USD-DEP-CONVENTIONS", "USD-LIBOR"));
99 conventions->add(QuantLib::ext::make_shared<data::DepositConvention>("GBP-DEP-CONVENTIONS", "GBP-LIBOR"));
100 conventions->add(QuantLib::ext::make_shared<data::DepositConvention>("JPY-DEP-CONVENTIONS", "JPY-LIBOR"));
101 conventions->add(QuantLib::ext::make_shared<data::DepositConvention>("CHF-DEP-CONVENTIONS", "CHF-LIBOR"));
102
103 InstrumentConventions::instance().setConventions(conventions);
104
105 return conventions;
106}
+ Here is the caller graph for this function:

◆ setupStressSimMarketData()

QuantLib::ext::shared_ptr< analytics::ScenarioSimMarketParameters > setupStressSimMarketData ( )

Definition at line 108 of file stresstest.cpp.

108 {
109 QuantLib::ext::shared_ptr<analytics::ScenarioSimMarketParameters> simMarketData(
111
112 simMarketData->baseCcy() = "EUR";
113 simMarketData->setDiscountCurveNames({"EUR", "GBP", "USD", "CHF", "JPY"});
114 simMarketData->setYieldCurveTenors("", {1 * Months, 6 * Months, 1 * Years, 2 * Years, 3 * Years, 4 * Years,
115 5 * Years, 7 * Years, 10 * Years, 15 * Years, 20 * Years, 30 * Years});
116 simMarketData->setIndices(
117 {"EUR-EURIBOR-6M", "USD-LIBOR-3M", "USD-LIBOR-6M", "GBP-LIBOR-6M", "CHF-LIBOR-6M", "JPY-LIBOR-6M"});
118 simMarketData->interpolation() = "LogLinear";
119 simMarketData->extrapolation() = "FlatFwd";
120
121 simMarketData->setSwapVolTerms("", {1 * Years, 2 * Years, 3 * Years, 5 * Years, 7 * Years, 10 * Years, 20 * Years});
122 simMarketData->setSwapVolExpiries(
123 "", {6 * Months, 1 * Years, 2 * Years, 3 * Years, 5 * Years, 7 * Years, 10 * Years, 20 * Years});
124 simMarketData->setSwapVolKeys({"EUR", "GBP", "USD", "CHF", "JPY"});
125 simMarketData->swapVolDecayMode() = "ForwardVariance";
126 simMarketData->setSimulateSwapVols(true); // false;
127
128 simMarketData->setFxVolExpiries("",
129 vector<Period>{1 * Months, 3 * Months, 6 * Months, 2 * Years, 3 * Years, 4 * Years, 5 * Years});
130 simMarketData->setFxVolDecayMode(string("ConstantVariance"));
131 simMarketData->setSimulateFXVols(true); // false;
132 simMarketData->setFxVolIsSurface(false);
133 simMarketData->setFxVolMoneyness(vector<Real>{0.0});
134 simMarketData->setFxVolCcyPairs({"EURUSD", "EURGBP", "EURCHF", "EURJPY"});
135
136 simMarketData->setFxCcyPairs({"EURUSD", "EURGBP", "EURCHF", "EURJPY"});
137
138 simMarketData->setSimulateCapFloorVols(true);
139 simMarketData->capFloorVolDecayMode() = "ForwardVariance";
140 simMarketData->setCapFloorVolKeys({"EUR", "USD"});
141 simMarketData->setCapFloorVolExpiries(
142 "", {6 * Months, 1 * Years, 2 * Years, 3 * Years, 5 * Years, 7 * Years, 10 * Years, 15 * Years, 20 * Years});
143 simMarketData->setCapFloorVolStrikes("", {0.00, 0.01, 0.02, 0.03, 0.04, 0.05, 0.06});
144
145 return simMarketData;
146}
+ Here is the caller graph for this function:

◆ setupStressScenarioData()

QuantLib::ext::shared_ptr< StressTestScenarioData > setupStressScenarioData ( )

Definition at line 148 of file stresstest.cpp.

148 {
149 QuantLib::ext::shared_ptr<StressTestScenarioData> stressData = QuantLib::ext::make_shared<StressTestScenarioData>();
150
152 data.label = "stresstest_1";
153 data.discountCurveShifts["EUR"] = StressTestScenarioData::CurveShiftData();
154 data.discountCurveShifts["EUR"].shiftType = ShiftType::Absolute;
155 data.discountCurveShifts["EUR"].shiftTenors = {6 * Months, 1 * Years, 2 * Years, 3 * Years,
156 5 * Years, 7 * Years, 10 * Years};
157 data.discountCurveShifts["EUR"].shifts = {0.001, 0.002, 0.003, 0.004, 0.005, 0.006, 0.007};
158 data.discountCurveShifts["USD"] = StressTestScenarioData::CurveShiftData();
159 data.discountCurveShifts["USD"].shiftType = ShiftType::Absolute;
160 data.discountCurveShifts["USD"].shiftTenors = {6 * Months, 1 * Years, 2 * Years, 3 * Years,
161 5 * Years, 7 * Years, 10 * Years};
162 data.discountCurveShifts["USD"].shifts = {0.001, 0.002, 0.003, 0.004, 0.005, 0.006, 0.007};
163 data.discountCurveShifts["GBP"] = StressTestScenarioData::CurveShiftData();
164 data.discountCurveShifts["GBP"].shiftType = ShiftType::Absolute;
165 data.discountCurveShifts["GBP"].shiftTenors = {6 * Months, 1 * Years, 2 * Years, 3 * Years,
166 5 * Years, 7 * Years, 10 * Years};
167 data.discountCurveShifts["GBP"].shifts = {0.001, 0.002, 0.003, 0.004, 0.005, 0.006, 0.007};
168 data.discountCurveShifts["JPY"] = StressTestScenarioData::CurveShiftData();
169 data.discountCurveShifts["JPY"].shiftType = ShiftType::Absolute;
170 data.discountCurveShifts["JPY"].shiftTenors = {6 * Months, 1 * Years, 2 * Years, 3 * Years,
171 5 * Years, 7 * Years, 10 * Years};
172 data.discountCurveShifts["JPY"].shifts = {0.001, 0.002, 0.003, 0.004, 0.005, 0.006, 0.007};
173 data.discountCurveShifts["CHF"] = StressTestScenarioData::CurveShiftData();
174 data.discountCurveShifts["CHF"].shiftType = ShiftType::Absolute;
175 data.discountCurveShifts["CHF"].shiftTenors = {6 * Months, 1 * Years, 2 * Years, 3 * Years,
176 5 * Years, 7 * Years, 10 * Years};
177 data.discountCurveShifts["CHF"].shifts = {0.001, 0.002, 0.003, 0.004, 0.005, 0.006, 0.007};
178 data.indexCurveShifts["EUR-EURIBOR-6M"] = StressTestScenarioData::CurveShiftData();
179 data.indexCurveShifts["EUR-EURIBOR-6M"].shiftType = ShiftType::Absolute;
180 data.indexCurveShifts["EUR-EURIBOR-6M"].shiftTenors = {6 * Months, 1 * Years, 2 * Years, 3 * Years,
181 5 * Years, 7 * Years, 10 * Years};
182 data.indexCurveShifts["EUR-EURIBOR-6M"].shifts = {0.001, 0.002, 0.003, 0.004, 0.005, 0.006, 0.007};
183 data.indexCurveShifts["USD-LIBOR-3M"] = StressTestScenarioData::CurveShiftData();
184 data.indexCurveShifts["USD-LIBOR-3M"].shiftType = ShiftType::Absolute;
185 data.indexCurveShifts["USD-LIBOR-3M"].shiftTenors = {6 * Months, 1 * Years, 2 * Years, 3 * Years,
186 5 * Years, 7 * Years, 10 * Years};
187 data.indexCurveShifts["USD-LIBOR-3M"].shifts = {0.001, 0.002, 0.003, 0.004, 0.005, 0.006, 0.007};
188 data.indexCurveShifts["USD-LIBOR-6M"] = StressTestScenarioData::CurveShiftData();
189 data.indexCurveShifts["USD-LIBOR-6M"].shiftType = ShiftType::Absolute;
190 data.indexCurveShifts["USD-LIBOR-6M"].shiftTenors = {6 * Months, 1 * Years, 2 * Years, 3 * Years,
191 5 * Years, 7 * Years, 10 * Years};
192 data.indexCurveShifts["USD-LIBOR-6M"].shifts = {0.001, 0.002, 0.003, 0.004, 0.005, 0.006, 0.007};
193 data.indexCurveShifts["GBP-LIBOR-6M"] = StressTestScenarioData::CurveShiftData();
194 data.indexCurveShifts["GBP-LIBOR-6M"].shiftType = ShiftType::Absolute;
195 data.indexCurveShifts["GBP-LIBOR-6M"].shiftTenors = {6 * Months, 1 * Years, 2 * Years, 3 * Years,
196 5 * Years, 7 * Years, 10 * Years};
197 data.indexCurveShifts["GBP-LIBOR-6M"].shifts = {0.001, 0.002, 0.003, 0.004, 0.005, 0.006, 0.007};
198 data.indexCurveShifts["CHF-LIBOR-6M"] = StressTestScenarioData::CurveShiftData();
199 data.indexCurveShifts["CHF-LIBOR-6M"].shiftType = ShiftType::Absolute;
200 data.indexCurveShifts["CHF-LIBOR-6M"].shiftTenors = {6 * Months, 1 * Years, 2 * Years, 3 * Years,
201 5 * Years, 7 * Years, 10 * Years};
202 data.indexCurveShifts["CHF-LIBOR-6M"].shifts = {0.001, 0.002, 0.003, 0.004, 0.005, 0.006, 0.007};
203 data.indexCurveShifts["JPY-LIBOR-6M"] = StressTestScenarioData::CurveShiftData();
204 data.indexCurveShifts["JPY-LIBOR-6M"].shiftType = ShiftType::Absolute;
205 data.indexCurveShifts["JPY-LIBOR-6M"].shiftTenors = {6 * Months, 1 * Years, 2 * Years, 3 * Years,
206 5 * Years, 7 * Years, 10 * Years};
207 data.indexCurveShifts["JPY-LIBOR-6M"].shifts = {0.001, 0.002, 0.003, 0.004, 0.005, 0.006, 0.007};
208 data.fxShifts["EURUSD"] = StressTestScenarioData::SpotShiftData();
209 data.fxShifts["EURUSD"].shiftType = ShiftType::Relative;
210 data.fxShifts["EURUSD"].shiftSize = 0.01;
211 data.fxShifts["EURGBP"] = StressTestScenarioData::SpotShiftData();
212 data.fxShifts["EURGBP"].shiftType = ShiftType::Relative;
213 data.fxShifts["EURGBP"].shiftSize = 0.01;
214 data.fxShifts["EURJPY"] = StressTestScenarioData::SpotShiftData();
215 data.fxShifts["EURJPY"].shiftType = ShiftType::Relative;
216 data.fxShifts["EURJPY"].shiftSize = 0.01;
217 data.fxShifts["EURCHF"] = StressTestScenarioData::SpotShiftData();
218 data.fxShifts["EURCHF"].shiftType = ShiftType::Relative;
219 data.fxShifts["EURCHF"].shiftSize = 0.01;
220 data.fxVolShifts["EURUSD"] = StressTestScenarioData::VolShiftData();
221 data.fxVolShifts["EURUSD"].shiftType = ShiftType::Absolute;
222 data.fxVolShifts["EURUSD"].shiftExpiries = {6 * Months, 2 * Years, 3 * Years, 5 * Years};
223 data.fxVolShifts["EURUSD"].shifts = {0.10, 0.11, 0.13, 0.14};
224 data.fxVolShifts["EURGBP"] = StressTestScenarioData::VolShiftData();
225 data.fxVolShifts["EURGBP"].shiftType = ShiftType::Absolute;
226 data.fxVolShifts["EURGBP"].shiftExpiries = {6 * Months, 2 * Years, 3 * Years, 5 * Years};
227 data.fxVolShifts["EURGBP"].shifts = {0.10, 0.11, 0.13, 0.14};
228 data.fxVolShifts["EURJPY"] = StressTestScenarioData::VolShiftData();
229 data.fxVolShifts["EURJPY"].shiftType = ShiftType::Absolute;
230 data.fxVolShifts["EURJPY"].shiftExpiries = {6 * Months, 2 * Years, 3 * Years, 5 * Years};
231 data.fxVolShifts["EURJPY"].shifts = {0.10, 0.11, 0.13, 0.14};
232 data.fxVolShifts["EURCHF"] = StressTestScenarioData::VolShiftData();
233 data.fxVolShifts["EURCHF"].shiftType = ShiftType::Absolute;
234 data.fxVolShifts["EURCHF"].shiftExpiries = {6 * Months, 2 * Years, 3 * Years, 5 * Years};
235 data.fxVolShifts["EURCHF"].shifts = {0.10, 0.11, 0.13, 0.14};
236
237 stressData->data() = vector<StressTestScenarioData::StressTestData>(1, data);
238
239 return stressData;
240}
data
+ Here is the caller graph for this function:

◆ BOOST_AUTO_TEST_CASE()

BOOST_AUTO_TEST_CASE ( regression  )

Definition at line 246 of file stresstest.cpp.

246 {
247 BOOST_TEST_MESSAGE("Testing Sensitivity Par Conversion");
248
249 SavedSettings backup;
250
251 Date today = Date(14, April, 2016); // Settings::instance().evaluationDate();
252 Settings::instance().evaluationDate() = today;
253
254 BOOST_TEST_MESSAGE("Today is " << today);
255
256 // build model
257 string baseCcy = "EUR";
258 vector<string> ccys;
259 ccys.push_back(baseCcy);
260 ccys.push_back("GBP");
261 ccys.push_back("CHF");
262 ccys.push_back("USD");
263 ccys.push_back("JPY");
264
265 // Init market
266 QuantLib::ext::shared_ptr<Market> initMarket = QuantLib::ext::make_shared<TestMarket>(today);
267
268 // build scenario sim market parameters
269 QuantLib::ext::shared_ptr<analytics::ScenarioSimMarketParameters> simMarketData = setupStressSimMarketData();
270
271 // sensitivity config
272 QuantLib::ext::shared_ptr<StressTestScenarioData> stressData = setupStressScenarioData();
273
274 // build scenario sim market
275 stressConv();
276 QuantLib::ext::shared_ptr<analytics::ScenarioSimMarket> simMarket =
277 QuantLib::ext::make_shared<analytics::ScenarioSimMarket>(initMarket, simMarketData);
278
279 // build scenario factory
280 QuantLib::ext::shared_ptr<Scenario> baseScenario = simMarket->baseScenario();
281 QuantLib::ext::shared_ptr<ScenarioFactory> scenarioFactory = QuantLib::ext::make_shared<CloneScenarioFactory>(baseScenario);
282
283 // build scenario generator
284 QuantLib::ext::shared_ptr<StressScenarioGenerator> scenarioGenerator =
285 QuantLib::ext::make_shared<StressScenarioGenerator>(stressData, baseScenario, simMarketData, simMarket, scenarioFactory);
286 simMarket->scenarioGenerator() = scenarioGenerator;
287
288 // build portfolio
289 QuantLib::ext::shared_ptr<EngineData> engineData = QuantLib::ext::make_shared<EngineData>();
290 engineData->model("Swap") = "DiscountedCashflows";
291 engineData->engine("Swap") = "DiscountingSwapEngine";
292 engineData->model("CrossCurrencySwap") = "DiscountedCashflows";
293 engineData->engine("CrossCurrencySwap") = "DiscountingCrossCurrencySwapEngine";
294 engineData->model("EuropeanSwaption") = "BlackBachelier";
295 engineData->engine("EuropeanSwaption") = "BlackBachelierSwaptionEngine";
296 engineData->model("FxForward") = "DiscountedCashflows";
297 engineData->engine("FxForward") = "DiscountingFxForwardEngine";
298 engineData->model("FxOption") = "GarmanKohlhagen";
299 engineData->engine("FxOption") = "AnalyticEuropeanEngine";
300 engineData->model("CapFloor") = "IborCapModel";
301 engineData->engine("CapFloor") = "IborCapEngine";
302 engineData->model("CapFlooredIborLeg") = "BlackOrBachelier";
303 engineData->engine("CapFlooredIborLeg") = "BlackIborCouponPricer";
304 QuantLib::ext::shared_ptr<EngineFactory> factory = QuantLib::ext::make_shared<EngineFactory>(engineData, simMarket);
305
306 // QuantLib::ext::shared_ptr<Portfolio> portfolio = buildSwapPortfolio(portfolioSize, factory);
307 QuantLib::ext::shared_ptr<Portfolio> portfolio(new Portfolio());
308 portfolio->add(buildSwap("1_Swap_EUR", "EUR", true, 10000000.0, 0, 10, 0.03, 0.00, "1Y", "30/360", "6M", "A360",
309 "EUR-EURIBOR-6M"));
310 portfolio->add(buildSwap("2_Swap_USD", "USD", true, 10000000.0, 0, 15, 0.02, 0.00, "6M", "30/360", "3M", "A360",
311 "USD-LIBOR-3M"));
312 portfolio->add(buildSwap("3_Swap_GBP", "GBP", true, 10000000.0, 0, 20, 0.04, 0.00, "6M", "30/360", "3M", "A360",
313 "GBP-LIBOR-6M"));
314 portfolio->add(buildSwap("4_Swap_JPY", "JPY", true, 1000000000.0, 0, 5, 0.01, 0.00, "6M", "30/360", "3M", "A360",
315 "JPY-LIBOR-6M"));
316 portfolio->add(buildEuropeanSwaption("5_Swaption_EUR", "Long", "EUR", true, 1000000.0, 10, 10, 0.03, 0.00, "1Y",
317 "30/360", "6M", "A360", "EUR-EURIBOR-6M"));
318 portfolio->add(buildEuropeanSwaption("6_Swaption_EUR", "Long", "EUR", true, 1000000.0, 2, 5, 0.03, 0.00, "1Y",
319 "30/360", "6M", "A360", "EUR-EURIBOR-6M"));
320 portfolio->add(buildFxOption("7_FxOption_EUR_USD", "Long", "Call", 3, "EUR", 10000000.0, "USD", 11000000.0));
321 portfolio->add(buildFxOption("8_FxOption_EUR_GBP", "Long", "Call", 7, "EUR", 10000000.0, "GBP", 11000000.0));
322 portfolio->add(buildCap("9_Cap_EUR", "EUR", "Long", 0.05, 1000000.0, 0, 10, "6M", "A360", "EUR-EURIBOR-6M"));
323 portfolio->add(buildFloor("10_Floor_USD", "USD", "Long", 0.01, 1000000.0, 0, 10, "3M", "A360", "USD-LIBOR-3M"));
324 portfolio->build(factory);
325
326 BOOST_TEST_MESSAGE("Portfolio size after build: " << portfolio->size());
327
328 // build the sensitivity analysis object
329 ore::analytics::StressTest analysis(portfolio, initMarket, "default", engineData, simMarketData, stressData);
330
331 std::map<std::string, Real> baseNPV = analysis.baseNPV();
332 std::map<std::pair<std::string, std::string>, Real> shiftedNPV = analysis.shiftedNPV();
333
334 QL_REQUIRE(shiftedNPV.size() > 0, "no shifted results");
335
336 struct Results {
337 string id;
338 string label;
339 Real shift;
340 };
341
342 std::vector<Results> cachedResults = {{"10_Floor_USD", "stresstest_1", -2487.75},
343 {"1_Swap_EUR", "stresstest_1", 629406},
344 {"2_Swap_USD", "stresstest_1", 599846},
345 {"3_Swap_GBP", "stresstest_1", 1.11005e+06},
346 {"4_Swap_JPY", "stresstest_1", 186736},
347 {"5_Swaption_EUR", "stresstest_1", 13623.1},
348 {"6_Swaption_EUR", "stresstest_1", 5041.52},
349 {"7_FxOption_EUR_USD", "stresstest_1", 748160},
350 {"8_FxOption_EUR_GBP", "stresstest_1", 1.21724e+06},
351 {"9_Cap_EUR", "stresstest_1", 1175.5}};
352
353 std::map<pair<string, string>, Real> stressMap;
354 for (Size i = 0; i < cachedResults.size(); ++i) {
355 pair<string, string> p(cachedResults[i].id, cachedResults[i].label);
356 stressMap[p] = cachedResults[i].shift;
357 }
358
359 Real tolerance = 0.01;
360 Size count = 0;
361 for (auto data : shiftedNPV) {
362 pair<string, string> p = data.first;
363 string id = data.first.first;
364 Real npv = data.second;
365 QL_REQUIRE(baseNPV.find(id) != baseNPV.end(), "base npv not found for trade " << id);
366 Real base = baseNPV[id];
367 Real delta = npv - base;
368 if (fabs(delta) > 0.0) {
369 count++;
370 QL_REQUIRE(stressMap.find(p) != stressMap.end(),
371 "pair (" << p.first << ", " << p.second << ") not found in sensi map");
372 BOOST_CHECK_MESSAGE(fabs(delta - stressMap[p]) < tolerance ||
373 fabs((delta - stressMap[p]) / delta) < tolerance,
374 "stress test regression failed for pair (" << p.first << ", " << p.second
375 << "): " << delta << " vs " << stressMap[p]);
376 }
377 }
378 BOOST_CHECK_MESSAGE(count == cachedResults.size(), "number of non-zero stress impacts ("
379 << count << ") do not match regression data ("
380 << cachedResults.size() << ")");
381 IndexManager::instance().clearHistories();
382}
Stress Test Analysis.
Definition: stresstest.hpp:55
QuantLib::ext::shared_ptr< Trade > buildCap(string id, string ccy, string longShort, Real capRate, Real notional, int start, Size term, string floatFreq, string floatDC, string index, Calendar calendar, Natural spotDays, bool spotStartLag)
QuantLib::ext::shared_ptr< Trade > buildFxOption(string id, string longShort, string putCall, Size expiry, string boughtCcy, Real boughtAmount, string soldCcy, Real soldAmount, Real premium, string premiumCcy, string premiumDate)
QuantLib::ext::shared_ptr< Trade > buildSwap(string id, string ccy, bool isPayer, Real notional, int start, Size term, Real rate, Real spread, string fixedFreq, string fixedDC, string floatFreq, string floatDC, string index, Calendar calendar, Natural spotDays, bool spotStartLag)
QuantLib::ext::shared_ptr< Trade > buildFloor(string id, string ccy, string longShort, Real floorRate, Real notional, int start, Size term, string floatFreq, string floatDC, string index, Calendar calendar, Natural spotDays, bool spotStartLag)
QuantLib::ext::shared_ptr< Trade > buildEuropeanSwaption(string id, string longShort, string ccy, bool isPayer, Real notional, int start, Size term, Real rate, Real spread, string fixedFreq, string fixedDC, string floatFreq, string floatDC, string index, string cashPhysical, Real premium, string premiumCcy, string premiumDate)
std::size_t count
QuantLib::ext::shared_ptr< data::Conventions > stressConv()
Definition: stresstest.cpp:75
QuantLib::ext::shared_ptr< analytics::ScenarioSimMarketParameters > setupStressSimMarketData()
Definition: stresstest.cpp:108
QuantLib::ext::shared_ptr< StressTestScenarioData > setupStressScenarioData()
Definition: stresstest.cpp:148
+ Here is the call graph for this function: