24#include <boost/timer/timer.hpp>
55#include <ql/math/randomnumbers/mt19937uniformrng.hpp>
56#include <ql/time/calendars/target.hpp>
57#include <ql/time/date.hpp>
58#include <ql/time/daycounters/actualactual.hpp>
64using namespace boost::unit_test_framework;
72inline unsigned long randInt(MersenneTwisterUniformRng& rng, Size min, Size max) {
73 return min + (rng.nextInt32() % (
max + 1 -
min));
76inline const string&
randString(MersenneTwisterUniformRng& rng,
const vector<string>& strs) {
77 return strs[
randInt(rng, 0, strs.size() - 1)];
80inline bool randBoolean(MersenneTwisterUniformRng& rng) {
return randInt(rng, 0, 1) == 1; }
83 QuantLib::ext::shared_ptr<analytics::ScenarioSimMarketParameters> simMarketData(
86 simMarketData->baseCcy() =
"EUR";
87 simMarketData->setDiscountCurveNames({
"EUR",
"GBP",
"USD",
"CHF",
"JPY"});
88 simMarketData->setYieldCurveTenors(
"", {1 * Months, 6 * Months, 1 * Years, 2 * Years, 3 * Years, 4 * Years,
89 5 * Years, 7 * Years, 10 * Years, 15 * Years, 20 * Years, 30 * Years});
90 simMarketData->setIndices(
91 {
"EUR-EURIBOR-6M",
"USD-LIBOR-3M",
"USD-LIBOR-6M",
"GBP-LIBOR-6M",
"CHF-LIBOR-6M",
"JPY-LIBOR-6M"});
92 simMarketData->interpolation() =
"LogLinear";
94 simMarketData->setSwapVolTerms(
"", {1 * Years, 2 * Years, 3 * Years, 5 * Years, 7 * Years, 10 * Years, 20 * Years});
95 simMarketData->setSwapVolExpiries(
96 "", {6 * Months, 1 * Years, 2 * Years, 3 * Years, 5 * Years, 7 * Years, 10 * Years, 20 * Years});
97 simMarketData->setSwapVolKeys({
"EUR",
"GBP",
"USD",
"CHF",
"JPY"});
98 simMarketData->swapVolDecayMode() =
"ForwardVariance";
99 simMarketData->setSimulateSwapVols(
true);
101 simMarketData->setFxVolExpiries(
"",
102 vector<Period>{1 * Months, 3 * Months, 6 * Months, 2 * Years, 3 * Years, 4 * Years, 5 * Years});
103 simMarketData->setFxVolDecayMode(
string(
"ConstantVariance"));
104 simMarketData->setSimulateFXVols(
true);
105 simMarketData->setFxVolCcyPairs({
"EURUSD",
"EURGBP",
"EURCHF",
"EURJPY"});
106 simMarketData->setFxVolIsSurface(
true);
107 simMarketData->setFxVolMoneyness(vector<Real>{0.1, 0.5, 1, 1.5, 2, 2.5, 2});
109 simMarketData->setFxCcyPairs({
"EURUSD",
"EURGBP",
"EURCHF",
"EURJPY"});
111 simMarketData->setSimulateCapFloorVols(
true);
112 simMarketData->capFloorVolDecayMode() =
"ForwardVariance";
113 simMarketData->setCapFloorVolKeys({
"EUR",
"USD"});
114 simMarketData->setCapFloorVolExpiries(
115 "", {6 * Months, 1 * Years, 2 * Years, 3 * Years, 5 * Years, 7 * Years, 10 * Years, 15 * Years, 20 * Years});
116 simMarketData->setCapFloorVolStrikes(
"", {0.00, 0.01, 0.02, 0.03, 0.04, 0.05, 0.06});
118 return simMarketData;
121QuantLib::ext::shared_ptr<analytics::ScenarioSimMarketParameters> setupSimMarketData7() {
122 QuantLib::ext::shared_ptr<analytics::ScenarioSimMarketParameters> simMarketData(
125 simMarketData->baseCcy() =
"EUR";
126 simMarketData->setDiscountCurveNames({
"EUR",
"GBP",
"USD",
"CHF",
"JPY",
"SEK",
"CAD"});
127 simMarketData->setYieldCurveTenors(
"", {2 * Weeks, 1 * Months, 3 * Months, 6 * Months, 1 * Years, 2 * Years,
128 3 * Years, 5 * Years, 10 * Years, 15 * Years, 20 * Years, 30 * Years});
129 simMarketData->setIndices({
"EUR-EONIA",
"EUR-EURIBOR-6M",
"EUR-EURIBOR-3M",
"USD-FedFunds",
"USD-LIBOR-3M",
130 "USD-LIBOR-6M",
"USD-LIBOR-1M",
"GBP-SONIA",
"GBP-LIBOR-6M",
"GBP-LIBOR-3M",
"CHF-TOIS",
131 "CHF-LIBOR-3M",
"CHF-LIBOR-6M",
"JPY-TONAR",
"JPY-LIBOR-3M",
"JPY-LIBOR-6M",
132 "CAD-CDOR-3M",
"CAD-CORRA",
"SEK-STIBOR-3M"});
133 simMarketData->interpolation() =
"LogLinear";
136 simMarketData->swapIndices()[
"USD-CMS-1Y"] =
"USD-LIBOR-3M";
137 simMarketData->swapIndices()[
"USD-CMS-30Y"] =
"USD-LIBOR-6M";
138 simMarketData->swapIndices()[
"JPY-CMS-1Y"] =
"JPY-LIBOR-6M";
139 simMarketData->swapIndices()[
"JPY-CMS-30Y"] =
"JPY-LIBOR-6M";
140 simMarketData->setFxCcyPairs({
"EURUSD",
"EURGBP",
"EURCHF",
"EURJPY",
"EURSEK",
"EURCAD"});
142 return simMarketData;
145QuantLib::ext::shared_ptr<analytics::ScenarioSimMarketParameters> setupSimMarketData5Big() {
146 QuantLib::ext::shared_ptr<analytics::ScenarioSimMarketParameters> simMarketData(
149 simMarketData->baseCcy() =
"EUR";
150 simMarketData->setDiscountCurveNames({
"EUR",
"GBP",
"USD",
"CHF",
"JPY"});
151 simMarketData->setYieldCurveTenors(
152 "", {1 * Weeks, 2 * Weeks, 1 * Months, 2 * Months, 3 * Months, 4 * Months, 5 * Months, 6 * Months,
153 9 * Months, 10 * Months, 11 * Months, 1 * Years, 13 * Months, 14 * Months, 15 * Months, 16 * Months,
154 17 * Months, 18 * Months, 19 * Months, 20 * Months, 21 * Months, 22 * Months, 23 * Months, 2 * Years,
155 25 * Months, 26 * Months, 27 * Months, 28 * Months, 29 * Months, 30 * Months, 31 * Months, 32 * Months,
156 3 * Years, 40 * Months, 41 * Months, 42 * Months, 43 * Months, 44 * Months, 4 * Years, 52 * Months,
157 53 * Months, 54 * Months, 55 * Months, 56 * Months, 5 * Years, 64 * Months, 65 * Months, 66 * Months,
158 67 * Months, 68 * Months, 6 * Years, 76 * Months, 77 * Months, 78 * Months, 79 * Months, 80 * Months,
159 7 * Years, 88 * Months, 89 * Months, 90 * Months, 91 * Months, 92 * Months, 10 * Years, 15 * Years,
160 20 * Years, 25 * Years, 30 * Years, 50 * Years});
161 simMarketData->setIndices(
162 {
"EUR-EURIBOR-6M",
"USD-LIBOR-3M",
"USD-LIBOR-6M",
"GBP-LIBOR-6M",
"CHF-LIBOR-6M",
"JPY-LIBOR-6M"});
163 simMarketData->interpolation() =
"LogLinear";
165 simMarketData->setSwapVolTerms(
166 "", {3 * Months, 4 * Months, 5 * Months, 6 * Months, 9 * Months, 10 * Months, 11 * Months, 1 * Years,
167 13 * Months, 14 * Months, 15 * Months, 16 * Months, 17 * Months, 18 * Months, 19 * Months, 20 * Months,
168 21 * Months, 22 * Months, 23 * Months, 2 * Years, 25 * Months, 26 * Months, 27 * Months, 28 * Months,
169 29 * Months, 30 * Months, 31 * Months, 32 * Months, 3 * Years, 40 * Months, 41 * Months, 42 * Months,
170 43 * Months, 44 * Months, 4 * Years, 52 * Months, 53 * Months, 54 * Months, 55 * Months, 56 * Months,
171 5 * Years, 64 * Months, 65 * Months, 66 * Months, 67 * Months, 68 * Months, 6 * Years, 76 * Months,
172 77 * Months, 78 * Months, 79 * Months, 80 * Months, 7 * Years, 88 * Months, 89 * Months, 90 * Months,
173 91 * Months, 92 * Months, 10 * Years, 15 * Years, 20 * Years, 25 * Years, 30 * Years, 50 * Years});
174 simMarketData->setSwapVolExpiries(
175 "", {1 * Weeks, 2 * Weeks, 1 * Months, 2 * Months, 3 * Months, 4 * Months, 5 * Months, 6 * Months,
176 9 * Months, 10 * Months, 11 * Months, 1 * Years, 13 * Months, 14 * Months, 15 * Months, 16 * Months,
177 17 * Months, 18 * Months, 19 * Months, 20 * Months, 21 * Months, 22 * Months, 23 * Months, 2 * Years,
178 25 * Months, 26 * Months, 27 * Months, 28 * Months, 29 * Months, 30 * Months, 31 * Months, 32 * Months,
179 3 * Years, 40 * Months, 41 * Months, 42 * Months, 43 * Months, 44 * Months, 4 * Years, 52 * Months,
180 53 * Months, 54 * Months, 55 * Months, 56 * Months, 5 * Years, 64 * Months, 65 * Months, 66 * Months,
181 67 * Months, 68 * Months, 6 * Years, 76 * Months, 77 * Months, 78 * Months, 79 * Months, 80 * Months,
182 7 * Years, 88 * Months, 89 * Months, 90 * Months, 91 * Months, 92 * Months, 10 * Years, 15 * Years,
183 20 * Years, 25 * Years, 30 * Years, 50 * Years});
184 simMarketData->setSwapVolKeys({
"EUR",
"GBP",
"USD",
"CHF",
"JPY"});
185 simMarketData->swapVolDecayMode() =
"ForwardVariance";
186 simMarketData->setSimulateSwapVols(
true);
187 vector<Period> tmpFxVolExpiries = {
188 1 * Weeks, 2 * Weeks, 1 * Months, 2 * Months, 3 * Months, 4 * Months, 5 * Months, 6 * Months,
189 9 * Months, 10 * Months, 11 * Months, 1 * Years, 13 * Months, 14 * Months, 15 * Months, 16 * Months,
190 17 * Months, 18 * Months, 19 * Months, 20 * Months, 21 * Months, 22 * Months, 23 * Months, 2 * Years,
191 25 * Months, 26 * Months, 27 * Months, 28 * Months, 29 * Months, 30 * Months, 31 * Months, 32 * Months,
192 3 * Years, 40 * Months, 41 * Months, 42 * Months, 43 * Months, 44 * Months, 4 * Years, 52 * Months,
193 53 * Months, 54 * Months, 55 * Months, 56 * Months, 5 * Years, 64 * Months, 65 * Months, 66 * Months,
194 67 * Months, 68 * Months, 6 * Years, 76 * Months, 77 * Months, 78 * Months, 79 * Months, 80 * Months,
195 7 * Years, 88 * Months, 89 * Months, 90 * Months, 91 * Months, 92 * Months, 10 * Years, 15 * Years,
196 20 * Years, 25 * Years, 30 * Years, 50 * Years};
197 simMarketData->setFxVolExpiries(
"", tmpFxVolExpiries);
198 simMarketData->setFxVolDecayMode(
string(
"ConstantVariance"));
199 simMarketData->setSimulateFXVols(
true);
200 simMarketData->setFxVolCcyPairs({
"EURUSD",
"EURGBP",
"EURCHF",
"EURJPY"});
201 simMarketData->setFxVolIsSurface(
false);
202 simMarketData->setFxVolMoneyness(vector<Real>{0});
204 simMarketData->setFxCcyPairs({
"EURUSD",
"EURGBP",
"EURCHF",
"EURJPY"});
206 simMarketData->setSimulateCapFloorVols(
true);
207 simMarketData->capFloorVolDecayMode() =
"ForwardVariance";
208 simMarketData->setCapFloorVolKeys({
"EUR",
"USD"});
209 simMarketData->setCapFloorVolExpiries(
210 "", {3 * Months, 4 * Months, 5 * Months, 6 * Months, 9 * Months, 10 * Months, 11 * Months, 1 * Years,
211 13 * Months, 14 * Months, 15 * Months, 16 * Months, 17 * Months, 18 * Months, 19 * Months, 20 * Months,
212 21 * Months, 22 * Months, 23 * Months, 2 * Years, 25 * Months, 26 * Months, 27 * Months, 28 * Months,
213 29 * Months, 30 * Months, 31 * Months, 32 * Months, 3 * Years, 40 * Months, 41 * Months, 42 * Months,
214 43 * Months, 44 * Months, 4 * Years, 52 * Months, 53 * Months, 54 * Months, 55 * Months, 56 * Months,
215 5 * Years, 64 * Months, 65 * Months, 66 * Months, 67 * Months, 68 * Months, 6 * Years, 76 * Months,
216 77 * Months, 78 * Months, 79 * Months, 80 * Months, 7 * Years, 88 * Months, 89 * Months, 90 * Months,
217 91 * Months, 92 * Months, 10 * Years, 15 * Years, 20 * Years, 25 * Years, 30 * Years, 50 * Years});
218 simMarketData->setCapFloorVolStrikes(
"", {0.00, 0.01, 0.02, 0.03, 0.04, 0.05, 0.06});
220 return simMarketData;
223QuantLib::ext::shared_ptr<SensitivityScenarioData> setupSensitivityScenarioData5Big() {
224 QuantLib::ext::shared_ptr<SensitivityScenarioData> sensiData = QuantLib::ext::make_shared<SensitivityScenarioData>();
226 QuantLib::ext::shared_ptr<SensitivityScenarioData::CurveShiftData> cvsData =
227 QuantLib::ext::make_shared<SensitivityScenarioData::CurveShiftData>();
228 cvsData->shiftTenors = {
229 1 * Weeks, 2 * Weeks, 1 * Months, 2 * Months, 3 * Months, 4 * Months, 5 * Months, 6 * Months,
230 9 * Months, 10 * Months, 11 * Months, 1 * Years, 13 * Months, 14 * Months, 15 * Months, 16 * Months,
231 17 * Months, 18 * Months, 19 * Months, 20 * Months, 21 * Months, 22 * Months, 23 * Months, 2 * Years,
232 25 * Months, 26 * Months, 27 * Months, 28 * Months, 29 * Months, 30 * Months, 31 * Months, 32 * Months,
233 3 * Years, 40 * Months, 41 * Months, 42 * Months, 43 * Months, 44 * Months, 4 * Years, 52 * Months,
234 53 * Months, 54 * Months, 55 * Months, 56 * Months, 5 * Years, 64 * Months, 65 * Months, 66 * Months,
235 67 * Months, 68 * Months, 6 * Years, 76 * Months, 77 * Months, 78 * Months, 79 * Months, 80 * Months,
236 7 * Years, 88 * Months, 89 * Months, 90 * Months, 91 * Months, 92 * Months, 10 * Years, 15 * Years,
237 20 * Years, 25 * Years, 30 * Years, 50 * Years};
238 cvsData->shiftType = ShiftType::Absolute;
239 cvsData->shiftSize = 0.0001;
246 fxvsData.
shiftType = ShiftType::Relative;
248 fxvsData.
shiftExpiries = {1 * Weeks, 2 * Weeks, 1 * Months, 2 * Months, 3 * Months, 4 * Months, 5 * Months,
249 6 * Months, 9 * Months, 10 * Months, 11 * Months, 1 * Years, 13 * Months, 14 * Months,
250 15 * Months, 16 * Months, 17 * Months, 18 * Months, 19 * Months, 20 * Months, 21 * Months,
251 22 * Months, 23 * Months, 2 * Years, 25 * Months, 26 * Months, 27 * Months, 28 * Months,
252 29 * Months, 30 * Months, 31 * Months, 32 * Months, 3 * Years, 40 * Months, 41 * Months,
253 42 * Months, 43 * Months, 44 * Months, 4 * Years, 52 * Months, 53 * Months, 54 * Months,
254 55 * Months, 56 * Months, 5 * Years, 64 * Months, 65 * Months, 66 * Months, 67 * Months,
255 68 * Months, 6 * Years, 76 * Months, 77 * Months, 78 * Months, 79 * Months, 80 * Months,
256 7 * Years, 88 * Months, 89 * Months, 90 * Months, 91 * Months, 92 * Months, 10 * Years,
257 15 * Years, 20 * Years, 25 * Years, 30 * Years, 50 * Years};
260 cfvsData.
shiftType = ShiftType::Absolute;
263 3 * Months, 4 * Months, 5 * Months, 6 * Months, 9 * Months, 10 * Months, 11 * Months, 1 * Years,
264 13 * Months, 14 * Months, 15 * Months, 16 * Months, 17 * Months, 18 * Months, 19 * Months, 20 * Months,
265 21 * Months, 22 * Months, 23 * Months, 2 * Years, 25 * Months, 26 * Months, 27 * Months, 28 * Months,
266 29 * Months, 30 * Months, 31 * Months, 32 * Months, 3 * Years, 40 * Months, 41 * Months, 42 * Months,
267 43 * Months, 44 * Months, 4 * Years, 52 * Months, 53 * Months, 54 * Months, 55 * Months, 56 * Months,
268 5 * Years, 64 * Months, 65 * Months, 66 * Months, 67 * Months, 68 * Months, 6 * Years, 76 * Months,
269 77 * Months, 78 * Months, 79 * Months, 80 * Months, 7 * Years, 88 * Months, 89 * Months, 90 * Months,
270 91 * Months, 92 * Months, 10 * Years, 15 * Years, 20 * Years, 25 * Years, 30 * Years, 50 * Years};
274 swvsData.
shiftType = ShiftType::Relative;
276 swvsData.
shiftExpiries = {1 * Weeks, 2 * Weeks, 1 * Months, 2 * Months, 3 * Months, 4 * Months, 5 * Months,
277 6 * Months, 9 * Months, 10 * Months, 11 * Months, 1 * Years, 13 * Months, 14 * Months,
278 15 * Months, 16 * Months, 17 * Months, 18 * Months, 19 * Months, 20 * Months, 21 * Months,
279 22 * Months, 23 * Months, 2 * Years, 25 * Months, 26 * Months, 27 * Months, 28 * Months,
280 29 * Months, 30 * Months, 31 * Months, 32 * Months, 3 * Years, 40 * Months, 41 * Months,
281 42 * Months, 43 * Months, 44 * Months, 4 * Years, 52 * Months, 53 * Months, 54 * Months,
282 55 * Months, 56 * Months, 5 * Years, 64 * Months, 65 * Months, 66 * Months, 67 * Months,
283 68 * Months, 6 * Years, 76 * Months, 77 * Months, 78 * Months, 79 * Months, 80 * Months,
284 7 * Years, 88 * Months, 89 * Months, 90 * Months, 91 * Months, 92 * Months, 10 * Years,
285 15 * Years, 20 * Years, 25 * Years, 30 * Years, 50 * Years};
287 3 * Months, 4 * Months, 5 * Months, 6 * Months, 9 * Months, 10 * Months, 11 * Months, 1 * Years,
288 13 * Months, 14 * Months, 15 * Months, 16 * Months, 17 * Months, 18 * Months, 19 * Months, 20 * Months,
289 21 * Months, 22 * Months, 23 * Months, 2 * Years, 25 * Months, 26 * Months, 27 * Months, 28 * Months,
290 29 * Months, 30 * Months, 31 * Months, 32 * Months, 3 * Years, 40 * Months, 41 * Months, 42 * Months,
291 43 * Months, 44 * Months, 4 * Years, 52 * Months, 53 * Months, 54 * Months, 55 * Months, 56 * Months,
292 5 * Years, 64 * Months, 65 * Months, 66 * Months, 67 * Months, 68 * Months, 6 * Years, 76 * Months,
293 77 * Months, 78 * Months, 79 * Months, 80 * Months, 7 * Years, 88 * Months, 89 * Months, 90 * Months,
294 91 * Months, 92 * Months, 10 * Years, 15 * Years, 20 * Years, 25 * Years, 30 * Years, 50 * Years};
296 sensiData->discountCurveShiftData()[
"EUR"] = cvsData;
298 sensiData->discountCurveShiftData()[
"USD"] = cvsData;
300 sensiData->discountCurveShiftData()[
"GBP"] = cvsData;
302 sensiData->discountCurveShiftData()[
"JPY"] = cvsData;
304 sensiData->discountCurveShiftData()[
"CHF"] = cvsData;
306 sensiData->indexCurveShiftData()[
"EUR-EURIBOR-6M"] = cvsData;
308 sensiData->indexCurveShiftData()[
"USD-LIBOR-3M"] = cvsData;
310 sensiData->indexCurveShiftData()[
"USD-LIBOR-6M"] = cvsData;
312 sensiData->indexCurveShiftData()[
"GBP-LIBOR-6M"] = cvsData;
314 sensiData->indexCurveShiftData()[
"JPY-LIBOR-6M"] = cvsData;
316 sensiData->indexCurveShiftData()[
"CHF-LIBOR-6M"] = cvsData;
318 sensiData->fxShiftData()[
"EURUSD"] = fxsData;
319 sensiData->fxShiftData()[
"EURGBP"] = fxsData;
320 sensiData->fxShiftData()[
"EURJPY"] = fxsData;
321 sensiData->fxShiftData()[
"EURCHF"] = fxsData;
323 sensiData->fxVolShiftData()[
"EURUSD"] = fxvsData;
324 sensiData->fxVolShiftData()[
"EURGBP"] = fxvsData;
325 sensiData->fxVolShiftData()[
"EURJPY"] = fxvsData;
326 sensiData->fxVolShiftData()[
"EURCHF"] = fxvsData;
328 sensiData->swaptionVolShiftData()[
"EUR"] = swvsData;
329 sensiData->swaptionVolShiftData()[
"GBP"] = swvsData;
330 sensiData->swaptionVolShiftData()[
"USD"] = swvsData;
331 sensiData->swaptionVolShiftData()[
"JPY"] = swvsData;
332 sensiData->swaptionVolShiftData()[
"CHF"] = swvsData;
334 sensiData->capFloorVolShiftData()[
"EUR"] =
335 QuantLib::ext::make_shared<SensitivityScenarioData::CapFloorVolShiftData>(cfvsData);
336 sensiData->capFloorVolShiftData()[
"EUR"]->indexName =
"EUR-EURIBOR-6M";
337 sensiData->capFloorVolShiftData()[
"USD"] =
338 QuantLib::ext::make_shared<SensitivityScenarioData::CapFloorVolShiftData>(cfvsData);
339 sensiData->capFloorVolShiftData()[
"USD"]->indexName =
"USD-LIBOR-3M";
345 QuantLib::ext::shared_ptr<SensitivityScenarioData> sensiData = QuantLib::ext::make_shared<SensitivityScenarioData>();
347 QuantLib::ext::shared_ptr<SensitivityScenarioData::CurveShiftData> cvsData =
348 QuantLib::ext::make_shared<SensitivityScenarioData::CurveShiftData>();
349 cvsData->shiftTenors = {6 * Months, 1 * Years, 2 * Years, 3 * Years, 5 * Years,
350 7 * Years, 10 * Years, 15 * Years, 20 * Years};
351 cvsData->shiftType = ShiftType::Absolute;
352 cvsData->shiftSize = 0.0001;
359 fxvsData.
shiftType = ShiftType::Relative;
364 cfvsData.
shiftType = ShiftType::Absolute;
366 cfvsData.
shiftExpiries = {1 * Years, 2 * Years, 3 * Years, 5 * Years, 10 * Years};
370 swvsData.
shiftType = ShiftType::Relative;
372 swvsData.
shiftExpiries = {6 * Months, 1 * Years, 3 * Years, 5 * Years, 10 * Years};
373 swvsData.
shiftTerms = {1 * Years, 3 * Years, 5 * Years, 10 * Years, 20 * Years};
374 sensiData->discountCurveShiftData()[
"EUR"] = cvsData;
376 sensiData->discountCurveShiftData()[
"USD"] = cvsData;
378 sensiData->discountCurveShiftData()[
"GBP"] = cvsData;
380 sensiData->discountCurveShiftData()[
"JPY"] = cvsData;
382 sensiData->discountCurveShiftData()[
"CHF"] = cvsData;
384 sensiData->indexCurveShiftData()[
"EUR-EURIBOR-6M"] = cvsData;
386 sensiData->indexCurveShiftData()[
"USD-LIBOR-3M"] = cvsData;
388 sensiData->indexCurveShiftData()[
"USD-LIBOR-6M"] = cvsData;
390 sensiData->indexCurveShiftData()[
"GBP-LIBOR-6M"] = cvsData;
392 sensiData->indexCurveShiftData()[
"JPY-LIBOR-6M"] = cvsData;
394 sensiData->indexCurveShiftData()[
"CHF-LIBOR-6M"] = cvsData;
396 sensiData->fxShiftData()[
"EURUSD"] = fxsData;
397 sensiData->fxShiftData()[
"EURGBP"] = fxsData;
398 sensiData->fxShiftData()[
"EURJPY"] = fxsData;
399 sensiData->fxShiftData()[
"EURCHF"] = fxsData;
401 sensiData->fxVolShiftData()[
"EURUSD"] = fxvsData;
402 sensiData->fxVolShiftData()[
"EURGBP"] = fxvsData;
403 sensiData->fxVolShiftData()[
"EURJPY"] = fxvsData;
404 sensiData->fxVolShiftData()[
"EURCHF"] = fxvsData;
406 sensiData->swaptionVolShiftData()[
"EUR"] = swvsData;
407 sensiData->swaptionVolShiftData()[
"GBP"] = swvsData;
408 sensiData->swaptionVolShiftData()[
"USD"] = swvsData;
409 sensiData->swaptionVolShiftData()[
"JPY"] = swvsData;
410 sensiData->swaptionVolShiftData()[
"CHF"] = swvsData;
412 sensiData->capFloorVolShiftData()[
"EUR"] =
413 QuantLib::ext::make_shared<SensitivityScenarioData::CapFloorVolShiftData>(cfvsData);
414 sensiData->capFloorVolShiftData()[
"EUR"]->indexName =
"EUR-EURIBOR-6M";
415 sensiData->capFloorVolShiftData()[
"USD"] =
416 QuantLib::ext::make_shared<SensitivityScenarioData::CapFloorVolShiftData>(cfvsData);
417 sensiData->capFloorVolShiftData()[
"USD"]->indexName =
"USD-LIBOR-3M";
422QuantLib::ext::shared_ptr<SensitivityScenarioData> setupSensitivityScenarioData7() {
423 QuantLib::ext::shared_ptr<SensitivityScenarioData> sensiData = QuantLib::ext::make_shared<SensitivityScenarioData>();
425 QuantLib::ext::shared_ptr<SensitivityScenarioData::CurveShiftData> cvsData =
426 QuantLib::ext::make_shared<SensitivityScenarioData::CurveShiftData>();
427 cvsData->shiftTenors = {
428 2 * Weeks, 1 * Months, 3 * Months, 6 * Months, 1 * Years, 2 * Years,
429 3 * Years, 5 * Years, 10 * Years, 15 * Years, 20 * Years, 30 * Years};
430 cvsData->shiftType = ShiftType::Absolute;
431 cvsData->shiftSize = 0.0001;
437 sensiData->discountCurveShiftData()[
"EUR"] = cvsData;
439 sensiData->discountCurveShiftData()[
"USD"] = cvsData;
441 sensiData->discountCurveShiftData()[
"GBP"] = cvsData;
443 sensiData->discountCurveShiftData()[
"JPY"] = cvsData;
445 sensiData->discountCurveShiftData()[
"CHF"] = cvsData;
447 sensiData->discountCurveShiftData()[
"CAD"] = cvsData;
449 sensiData->discountCurveShiftData()[
"SEK"] = cvsData;
451 sensiData->indexCurveShiftData()[
"EUR-EONIA"] = cvsData;
453 sensiData->indexCurveShiftData()[
"EUR-EURIBOR-3M"] = cvsData;
455 sensiData->indexCurveShiftData()[
"EUR-EURIBOR-6M"] = cvsData;
457 sensiData->indexCurveShiftData()[
"GBP-SONIA"] = cvsData;
459 sensiData->indexCurveShiftData()[
"GBP-LIBOR-3M"] = cvsData;
461 sensiData->indexCurveShiftData()[
"USD-FedFunds"] = cvsData;
463 sensiData->indexCurveShiftData()[
"USD-LIBOR-1M"] = cvsData;
465 sensiData->indexCurveShiftData()[
"USD-LIBOR-3M"] = cvsData;
467 sensiData->indexCurveShiftData()[
"USD-LIBOR-6M"] = cvsData;
469 sensiData->indexCurveShiftData()[
"GBP-LIBOR-6M"] = cvsData;
471 sensiData->indexCurveShiftData()[
"JPY-TONAR"] = cvsData;
473 sensiData->indexCurveShiftData()[
"JPY-LIBOR-3M"] = cvsData;
475 sensiData->indexCurveShiftData()[
"JPY-LIBOR-6M"] = cvsData;
477 sensiData->indexCurveShiftData()[
"CHF-TOIS"] = cvsData;
479 sensiData->indexCurveShiftData()[
"CHF-LIBOR-3M"] = cvsData;
481 sensiData->indexCurveShiftData()[
"CHF-LIBOR-6M"] = cvsData;
483 sensiData->indexCurveShiftData()[
"CAD-CDOR-3M"] = cvsData;
485 sensiData->indexCurveShiftData()[
"CAD-CORRA"] = cvsData;
487 sensiData->indexCurveShiftData()[
"SEK-STIBOR-3M"] = cvsData;
489 sensiData->fxShiftData()[
"EURUSD"] = fxsData;
490 sensiData->fxShiftData()[
"EURGBP"] = fxsData;
491 sensiData->fxShiftData()[
"EURJPY"] = fxsData;
492 sensiData->fxShiftData()[
"EURCHF"] = fxsData;
493 sensiData->fxShiftData()[
"EURCAD"] = fxsData;
494 sensiData->fxShiftData()[
"EURSEK"] = fxsData;
499void addCrossGammas(vector<pair<string, string>>& cgFilter) {
500 BOOST_CHECK_EQUAL(cgFilter.size(), 0);
501 cgFilter.push_back(pair<string, string>(
"DiscountCurve/EUR",
"DiscountCurve/EUR"));
502 cgFilter.push_back(pair<string, string>(
"DiscountCurve/USD",
"DiscountCurve/USD"));
503 cgFilter.push_back(pair<string, string>(
"DiscountCurve/GBP",
"DiscountCurve/GBP"));
504 cgFilter.push_back(pair<string, string>(
"DiscountCurve/CHF",
"DiscountCurve/CHF"));
505 cgFilter.push_back(pair<string, string>(
"DiscountCurve/JPY",
"DiscountCurve/JPY"));
506 cgFilter.push_back(pair<string, string>(
"IndexCurve/EUR",
"DiscountCurve/EUR"));
507 cgFilter.push_back(pair<string, string>(
"IndexCurve/USD",
"DiscountCurve/USD"));
508 cgFilter.push_back(pair<string, string>(
"IndexCurve/GBP",
"DiscountCurve/GBP"));
509 cgFilter.push_back(pair<string, string>(
"IndexCurve/CHF",
"DiscountCurve/CHF"));
510 cgFilter.push_back(pair<string, string>(
"IndexCurve/JPY",
"DiscountCurve/JPY"));
511 cgFilter.push_back(pair<string, string>(
"IndexCurve/EUR",
"IndexCurve/EUR"));
512 cgFilter.push_back(pair<string, string>(
"IndexCurve/USD",
"IndexCurve/USD"));
513 cgFilter.push_back(pair<string, string>(
"IndexCurve/GBP",
"IndexCurve/GBP"));
514 cgFilter.push_back(pair<string, string>(
"IndexCurve/CHF",
"IndexCurve/CHF"));
515 cgFilter.push_back(pair<string, string>(
"IndexCurve/JPY",
"IndexCurve/JPY"));
516 cgFilter.push_back(pair<string, string>(
"SwaptionVolatility/EUR",
"SwaptionVolatility/EUR"));
517 cgFilter.push_back(pair<string, string>(
"SwaptionVolatility/USD",
"SwaptionVolatility/USD"));
518 cgFilter.push_back(pair<string, string>(
"SwaptionVolatility/GBP",
"SwaptionVolatility/GBP"));
521void addCrossGammas7(vector<pair<string, string>>& cgFilter) {
522 BOOST_CHECK_EQUAL(cgFilter.size(), 0);
523 cgFilter.push_back(pair<string, string>(
"DiscountCurve/EUR",
"DiscountCurve/EUR"));
524 cgFilter.push_back(pair<string, string>(
"DiscountCurve/JPY",
"DiscountCurve/JPY"));
525 cgFilter.push_back(pair<string, string>(
"DiscountCurve/USD",
"DiscountCurve/USD"));
526 cgFilter.push_back(pair<string, string>(
"DiscountCurve/GBP",
"DiscountCurve/GBP"));
527 cgFilter.push_back(pair<string, string>(
"DiscountCurve/CHF",
"DiscountCurve/CHF"));
528 cgFilter.push_back(pair<string, string>(
"DiscountCurve/SEK",
"DiscountCurve/SEK"));
529 cgFilter.push_back(pair<string, string>(
"DiscountCurve/CAD",
"DiscountCurve/CAD"));
531 cgFilter.push_back(pair<string, string>(
"IndexCurve/EUR",
"IndexCurve/EUR"));
532 cgFilter.push_back(pair<string, string>(
"IndexCurve/JPY",
"IndexCurve/JPY"));
533 cgFilter.push_back(pair<string, string>(
"IndexCurve/USD",
"IndexCurve/USD"));
534 cgFilter.push_back(pair<string, string>(
"IndexCurve/GBP",
"IndexCurve/GBP"));
535 cgFilter.push_back(pair<string, string>(
"IndexCurve/CHF",
"IndexCurve/CHF"));
536 cgFilter.push_back(pair<string, string>(
"IndexCurve/SEK",
"IndexCurve/SEK"));
537 cgFilter.push_back(pair<string, string>(
"IndexCurve/CAD",
"IndexCurve/CAD"));
539 cgFilter.push_back(pair<string, string>(
"DiscountCurve/EUR",
"IndexCurve/EUR"));
540 cgFilter.push_back(pair<string, string>(
"DiscountCurve/JPY",
"IndexCurve/JPY"));
541 cgFilter.push_back(pair<string, string>(
"DiscountCurve/USD",
"IndexCurve/USD"));
542 cgFilter.push_back(pair<string, string>(
"DiscountCurve/GBP",
"IndexCurve/GBP"));
543 cgFilter.push_back(pair<string, string>(
"DiscountCurve/CHF",
"IndexCurve/CHF"));
544 cgFilter.push_back(pair<string, string>(
"DiscountCurve/SEK",
"IndexCurve/SEK"));
545 cgFilter.push_back(pair<string, string>(
"DiscountCurve/CAD",
"IndexCurve/CAD"));
547 cgFilter.push_back(pair<string, string>(
"DiscountCurve/EUR",
"SwaptionVolatility/EUR"));
548 cgFilter.push_back(pair<string, string>(
"DiscountCurve/JPY",
"SwaptionVolatility/JPY"));
549 cgFilter.push_back(pair<string, string>(
"DiscountCurve/USD",
"SwaptionVolatility/USD"));
550 cgFilter.push_back(pair<string, string>(
"DiscountCurve/GBP",
"SwaptionVolatility/GBP"));
551 cgFilter.push_back(pair<string, string>(
"DiscountCurve/CHF",
"SwaptionVolatility/CHF"));
552 cgFilter.push_back(pair<string, string>(
"DiscountCurve/SEK",
"SwaptionVolatility/SEK"));
553 cgFilter.push_back(pair<string, string>(
"DiscountCurve/CAD",
"SwaptionVolatility/CAD"));
555 cgFilter.push_back(pair<string, string>(
"IndexCurve/EUR",
"SwaptionVolatility/EUR"));
556 cgFilter.push_back(pair<string, string>(
"IndexCurve/JPY",
"SwaptionVolatility/JPY"));
557 cgFilter.push_back(pair<string, string>(
"IndexCurve/USD",
"SwaptionVolatility/USD"));
558 cgFilter.push_back(pair<string, string>(
"IndexCurve/GBP",
"SwaptionVolatility/GBP"));
559 cgFilter.push_back(pair<string, string>(
"IndexCurve/CHF",
"SwaptionVolatility/CHF"));
560 cgFilter.push_back(pair<string, string>(
"IndexCurve/SEK",
"SwaptionVolatility/SEK"));
561 cgFilter.push_back(pair<string, string>(
"IndexCurve/CAD",
"SwaptionVolatility/CAD"));
563 cgFilter.push_back(pair<string, string>(
"FXSpot/EURUSD",
"DiscountCurve/EUR"));
564 cgFilter.push_back(pair<string, string>(
"FXSpot/EURUSD",
"IndexCurve/EUR"));
565 cgFilter.push_back(pair<string, string>(
"FXSpot/JPYUSD",
"DiscountCurve/JPY"));
566 cgFilter.push_back(pair<string, string>(
"FXSpot/JPYUSD",
"IndexCurve/JPY"));
567 cgFilter.push_back(pair<string, string>(
"FXSpot/GBPUSD",
"DiscountCurve/GBP"));
568 cgFilter.push_back(pair<string, string>(
"FXSpot/GBPUSD",
"IndexCurve/GBP"));
569 cgFilter.push_back(pair<string, string>(
"FXSpot/CHFUSD",
"DiscountCurve/CHF"));
570 cgFilter.push_back(pair<string, string>(
"FXSpot/CHFUSD",
"IndexCurve/CHF"));
571 cgFilter.push_back(pair<string, string>(
"FXSpot/SEKUSD",
"DiscountCurve/SEK"));
572 cgFilter.push_back(pair<string, string>(
"FXSpot/SEKUSD",
"IndexCurve/SEK"));
573 cgFilter.push_back(pair<string, string>(
"FXSpot/CADUSD",
"DiscountCurve/CAD"));
574 cgFilter.push_back(pair<string, string>(
"FXSpot/CADUSD",
"IndexCurve/CAD"));
576 cgFilter.push_back(pair<string, string>(
"FXSpot/EURUSD",
"SwaptionVolatility/EUR"));
577 cgFilter.push_back(pair<string, string>(
"FXSpot/JPYUSD",
"SwaptionVolatility/JPY"));
578 cgFilter.push_back(pair<string, string>(
"FXSpot/GBPUSD",
"SwaptionVolatility/GBP"));
579 cgFilter.push_back(pair<string, string>(
"FXSpot/CHFUSD",
"SwaptionVolatility/CHF"));
580 cgFilter.push_back(pair<string, string>(
"FXSpot/SEKUSD",
"SwaptionVolatility/SEK"));
581 cgFilter.push_back(pair<string, string>(
"FXSpot/CADUSD",
"SwaptionVolatility/CAD"));
583 cgFilter.push_back(pair<string, string>(
"FXSpot/EURUSD",
"DiscountCurve/USD"));
584 cgFilter.push_back(pair<string, string>(
"FXSpot/EURUSD",
"IndexCurve/USD"));
585 cgFilter.push_back(pair<string, string>(
"FXSpot/JPYUSD",
"DiscountCurve/USD"));
586 cgFilter.push_back(pair<string, string>(
"FXSpot/JPYUSD",
"IndexCurve/USD"));
587 cgFilter.push_back(pair<string, string>(
"FXSpot/GBPUSD",
"DiscountCurve/USD"));
588 cgFilter.push_back(pair<string, string>(
"FXSpot/GBPUSD",
"IndexCurve/USD"));
589 cgFilter.push_back(pair<string, string>(
"FXSpot/CHFUSD",
"DiscountCurve/USD"));
590 cgFilter.push_back(pair<string, string>(
"FXSpot/CHFUSD",
"IndexCurve/USD"));
591 cgFilter.push_back(pair<string, string>(
"FXSpot/SEKUSD",
"DiscountCurve/USD"));
592 cgFilter.push_back(pair<string, string>(
"FXSpot/SEKUSD",
"IndexCurve/USD"));
593 cgFilter.push_back(pair<string, string>(
"FXSpot/CADUSD",
"DiscountCurve/USD"));
594 cgFilter.push_back(pair<string, string>(
"FXSpot/CADUSD",
"IndexCurve/USD"));
596 cgFilter.push_back(pair<string, string>(
"DiscountCurve/USD",
"DiscountCurve/EUR"));
597 cgFilter.push_back(pair<string, string>(
"DiscountCurve/USD",
"DiscountCurve/JPY"));
598 cgFilter.push_back(pair<string, string>(
"DiscountCurve/USD",
"DiscountCurve/GBP"));
599 cgFilter.push_back(pair<string, string>(
"DiscountCurve/USD",
"DiscountCurve/CHF"));
600 cgFilter.push_back(pair<string, string>(
"DiscountCurve/USD",
"DiscountCurve/SEK"));
601 cgFilter.push_back(pair<string, string>(
"DiscountCurve/USD",
"DiscountCurve/CAD"));
603 cgFilter.push_back(pair<string, string>(
"IndexCurve/USD",
"DiscountCurve/EUR"));
604 cgFilter.push_back(pair<string, string>(
"IndexCurve/USD",
"DiscountCurve/JPY"));
605 cgFilter.push_back(pair<string, string>(
"IndexCurve/USD",
"DiscountCurve/GBP"));
606 cgFilter.push_back(pair<string, string>(
"IndexCurve/USD",
"DiscountCurve/CHF"));
607 cgFilter.push_back(pair<string, string>(
"IndexCurve/USD",
"DiscountCurve/SEK"));
608 cgFilter.push_back(pair<string, string>(
"IndexCurve/USD",
"DiscountCurve/CAD"));
609 cgFilter.push_back(pair<string, string>(
"DiscountCurve/USD",
"IndexCurve/EUR"));
611 cgFilter.push_back(pair<string, string>(
"DiscountCurve/USD",
"IndexCurve/JPY"));
612 cgFilter.push_back(pair<string, string>(
"DiscountCurve/USD",
"IndexCurve/GBP"));
613 cgFilter.push_back(pair<string, string>(
"DiscountCurve/USD",
"IndexCurve/CHF"));
614 cgFilter.push_back(pair<string, string>(
"DiscountCurve/USD",
"IndexCurve/SEK"));
615 cgFilter.push_back(pair<string, string>(
"DiscountCurve/USD",
"IndexCurve/CAD"));
617 cgFilter.push_back(pair<string, string>(
"IndexCurve/USD",
"IndexCurve/EUR"));
618 cgFilter.push_back(pair<string, string>(
"IndexCurve/USD",
"IndexCurve/JPY"));
619 cgFilter.push_back(pair<string, string>(
"IndexCurve/USD",
"IndexCurve/GBP"));
620 cgFilter.push_back(pair<string, string>(
"IndexCurve/USD",
"IndexCurve/CHF"));
621 cgFilter.push_back(pair<string, string>(
"IndexCurve/USD",
"IndexCurve/SEK"));
622 cgFilter.push_back(pair<string, string>(
"IndexCurve/USD",
"IndexCurve/CAD"));
625QuantLib::ext::shared_ptr<Portfolio>
buildPortfolio(Size portfolioSize,
bool swapsOnly =
false,
626 QuantLib::ext::shared_ptr<EngineFactory> factory = {}) {
628 QuantLib::ext::shared_ptr<Portfolio> portfolio(
new Portfolio());
630 vector<string> ccys = {
"EUR",
"USD",
"GBP",
"JPY",
"CHF"};
632 map<string, vector<string>> indices = {{
"EUR", {
"EUR-EURIBOR-6M"}},
633 {
"USD", {
"USD-LIBOR-3M"}},
634 {
"GBP", {
"GBP-LIBOR-6M"}},
635 {
"CHF", {
"CHF-LIBOR-6M"}},
636 {
"JPY", {
"JPY-LIBOR-6M"}}};
638 vector<string> fixedTenors = {
"6M",
"1Y"};
645 Size minFixedBps = 10;
646 Size maxFixedBps = 400;
649 MersenneTwisterUniformRng rng(seed);
651 Calendar cal = TARGET();
652 string fixDC =
"30/360";
653 string floatDC =
"ACT/365";
655 Real notional = 1000000;
658 for (Size i = 0; i < portfolioSize; i++) {
661 string ccy = portfolioSize == 1 ?
"EUR" :
randString(rng, ccys);
662 string index = portfolioSize == 1 ?
"EUR-EURIBOR-6M" :
randString(rng, indices[ccy]);
663 string floatFreq = portfolioSize == 1 ?
"6M" : index.substr(index.find(
'-', 4) + 1);
666 Real fixedRate = portfolioSize == 1 ? 0.02 :
randInt(rng, minFixedBps, maxFixedBps) / 100.0;
667 string fixFreq = portfolioSize == 1 ?
"1Y" :
randString(rng, fixedTenors);
672 std::ostringstream oss;
675 oss <<
"Trade_" << i + 1;
676 string id = oss.str();
678 if (i % 2 == 0 && !swapsOnly) {
679 int start =
randInt(rng, minTerm, maxTerm);
680 Size term = portfolioSize == 1 ? 20 :
randInt(rng, minTerm, maxTerm);
681 string longShort =
randBoolean(rng) ?
"Long" :
"Short";
683 start, term, fixedRate, spread, fixFreq,
684 fixDC, floatFreq, floatDC, index));
686 int start =
randInt(rng, minStart, maxStart);
687 Size end =
randInt(rng, minTerm, maxTerm);
689 spread, fixFreq, fixDC, floatFreq, floatDC, index));
693 portfolio->build(factory);
695 BOOST_CHECK_MESSAGE(portfolio->size() == portfolioSize,
696 "Failed to build portfolio (got " << portfolio->size() <<
" expected " << portfolioSize <<
")");
701void test_performance(
bool bigPortfolio,
bool bigScenario,
bool lotsOfSensis,
bool crossGammas,
703 Size portfolioSize = bigPortfolio ? 100 : 1;
704 string om_str = (om == ObservationMode::Mode::None) ?
"None"
705 : (om == ObservationMode::Mode::Disable) ?
"Disable"
706 : (om == ObservationMode::Mode::Defer) ?
"Defer"
707 : (om == ObservationMode::Mode::Unregister) ?
"Unregister"
709 string bigPfolioStr = bigPortfolio ?
"big" :
"small";
710 string bigScenarioStr = bigScenario ?
"big" :
"small";
711 string lotsOfSensisStr = lotsOfSensis ?
"lots" :
"few";
712 string crossGammasStr = crossGammas ?
"included" :
"excluded";
714 BOOST_TEST_MESSAGE(
"Testing Sensitivity Performance "
715 <<
"(portfolio=" << bigPfolioStr <<
")"
716 <<
"(scenarioSize=" << bigScenarioStr <<
")"
717 <<
"(numSensis=" << lotsOfSensisStr <<
")"
718 <<
"(crossGammas=" << crossGammasStr <<
")"
719 <<
"(observation=" << om_str <<
")...");
721 SavedSettings backup;
722 ObservationMode::instance().setMode(om);
724 Date today = Date(14, April, 2016);
725 Settings::instance().evaluationDate() = today;
728 QuantLib::ext::shared_ptr<Market> initMarket = QuantLib::ext::make_shared<testsuite::TestMarket>(today);
731 QuantLib::ext::shared_ptr<analytics::ScenarioSimMarketParameters> simMarketData =
setupSimMarketData5();
734 simMarketData = setupSimMarketData5Big();
737 sensiData = setupSensitivityScenarioData5Big();
740 addCrossGammas(sensiData->crossGammaFilter());
746 QuantLib::ext::shared_ptr<EngineData>
data = QuantLib::ext::make_shared<EngineData>();
747 data->model(
"Swap") =
"DiscountedCashflows";
748 data->engine(
"Swap") =
"DiscountingSwapEngine";
749 data->model(
"EuropeanSwaption") =
"BlackBachelier";
750 data->engine(
"EuropeanSwaption") =
"BlackBachelierSwaptionEngine";
752 QuantLib::ext::shared_ptr<Portfolio> portfolio =
buildPortfolio(portfolioSize);
754 boost::timer::cpu_timer timer;
755 QuantLib::ext::shared_ptr<SensitivityAnalysis> sa = QuantLib::ext::make_shared<SensitivityAnalysis>(
757 sa->generateSensitivities();
759 Real elapsed = timer.elapsed().wall * 1e-9;
760 Size numScenarios = sa->scenarioGenerator()->samples();
761 Size scenarioSize = sa->scenarioGenerator()->scenarios().front()->keys().size();
762 BOOST_TEST_MESSAGE(
"number of scenarios=" << numScenarios);
763 BOOST_TEST_MESSAGE(
"Size of scenario = " << scenarioSize <<
" keys");
764 BOOST_TEST_MESSAGE(
"time = " << elapsed <<
" seconds");
765 Real avTime = (elapsed / ((Real)(numScenarios * portfolioSize)));
766 BOOST_TEST_MESSAGE(
"Average pricing time = " << avTime <<
" seconds");
771 Size portfolioSize = 100;
772 string om_str = (om == ObservationMode::Mode::None) ?
"None"
773 : (om == ObservationMode::Mode::Disable) ?
"Disable"
774 : (om == ObservationMode::Mode::Defer) ?
"Defer"
775 : (om == ObservationMode::Mode::Unregister) ?
"Unregister"
778 SavedSettings backup;
779 ObservationMode::instance().setMode(om);
781 Date today = Date(13, April, 2016);
782 Settings::instance().evaluationDate() = today;
785 QuantLib::ext::shared_ptr<Market> initMarket = QuantLib::ext::make_shared<testsuite::TestMarket>(today,
true);
788 QuantLib::ext::shared_ptr<analytics::ScenarioSimMarketParameters> simMarketData = setupSimMarketData7();
789 QuantLib::ext::shared_ptr<SensitivityScenarioData> sensiData = setupSensitivityScenarioData7();
791 addCrossGammas7(sensiData->crossGammaFilter());
795 QuantLib::ext::shared_ptr<EngineData>
data = QuantLib::ext::make_shared<EngineData>();
796 data->model(
"Swap") =
"DiscountedCashflows";
797 data->engine(
"Swap") =
"DiscountingSwapEngine";
798 data->model(
"EuropeanSwaption") =
"BlackBachelier";
799 data->engine(
"EuropeanSwaption") =
"BlackBachelierSwaptionEngine";
801 QuantLib::ext::shared_ptr<Portfolio> portfolio =
buildPortfolio(portfolioSize,
true);
803 boost::timer::cpu_timer timer;
804 QuantLib::ext::shared_ptr<SensitivityAnalysis> sa = QuantLib::ext::make_shared<SensitivityAnalysis>(
806 sa->generateSensitivities();
811 auto baseCurrency = sa->simMarketData()->baseCcy();
812 auto ss = QuantLib::ext::make_shared<SensitivityCubeStream>(sa->sensiCube(), baseCurrency);
816 Real elapsed = timer.elapsed().wall * 1e-9;
817 Size numScenarios = sa->scenarioGenerator()->samples();
818 Size scenarioSize = sa->scenarioGenerator()->scenarios().front()->keys().size();
819 BOOST_TEST_MESSAGE(
"number of scenarios=" << numScenarios);
820 BOOST_TEST_MESSAGE(
"Size of scenario = " << scenarioSize <<
" keys");
821 BOOST_TEST_MESSAGE(
"time = " << elapsed <<
" seconds");
822 Real avTime = (elapsed / ((Real)(numScenarios * portfolioSize)));
823 BOOST_TEST_MESSAGE(
"Average pricing time = " << avTime <<
" seconds");
831 boost::timer::cpu_timer timer;
835 BOOST_TEST_MESSAGE(
"total time = " << timer.format(boost::timer::default_places,
"%w") <<
" seconds");
839 boost::timer::cpu_timer timer;
843 BOOST_TEST_MESSAGE(
"total time = " << timer.format(boost::timer::default_places,
"%w") <<
" seconds");
847 boost::timer::cpu_timer timer;
851 BOOST_TEST_MESSAGE(
"total time = " << timer.format(boost::timer::default_places,
"%w") <<
" seconds");
855 boost::timer::cpu_timer timer;
859 BOOST_TEST_MESSAGE(
"total time = " << timer.format(boost::timer::default_places,
"%w") <<
" seconds");
863 boost::timer::cpu_timer timer;
867 BOOST_TEST_MESSAGE(
"total time = " << timer.format(boost::timer::default_places,
"%w") <<
" seconds");
871 boost::timer::cpu_timer timer;
875 BOOST_TEST_MESSAGE(
"total time = " << timer.format(boost::timer::default_places,
"%w") <<
" seconds");
879 boost::timer::cpu_timer timer;
883 BOOST_TEST_MESSAGE(
"total time = " << timer.format(boost::timer::default_places,
"%w") <<
" seconds");
887 boost::timer::cpu_timer timer;
891 BOOST_TEST_MESSAGE(
"total time = " << timer.format(boost::timer::default_places,
"%w") <<
" seconds");
895 boost::timer::cpu_timer timer;
899 BOOST_TEST_MESSAGE(
"total time = " << timer.format(boost::timer::default_places,
"%w") <<
" seconds");
903 boost::timer::cpu_timer timer;
907 BOOST_TEST_MESSAGE(
"total time = " << timer.format(boost::timer::default_places,
"%w") <<
" seconds");
911 boost::timer::cpu_timer timer;
915 BOOST_TEST_MESSAGE(
"total time = " << timer.format(boost::timer::default_places,
"%w") <<
" seconds");
919 boost::timer::cpu_timer timer;
921 BT_Benchmark(
true, om);
923 BOOST_TEST_MESSAGE(
"total time = " << timer.format(boost::timer::default_places,
"%w") <<
" seconds");
927BOOST_AUTO_TEST_SUITE(SensitivityPerformanceTest)
930 BOOST_TEST_MESSAGE(
"Testing Sensitivity Performance NoneObs");
935 BOOST_TEST_MESSAGE(
"Testing Sensitivity Performance DisableObs");
940 BOOST_TEST_MESSAGE(
"Testing Sensitivity Performance DeferObs");
945 BOOST_TEST_MESSAGE(
"Testing Sensitivity Performance UnregisterObs");
950 BOOST_TEST_MESSAGE(
"Testing Sensitivity Performance CrossGammaNoneObs");
955 BOOST_TEST_MESSAGE(
"Testing Sensitivity Performance BigScenarioNoneObs");
959BOOST_AUTO_TEST_SUITE_END()
960BOOST_AUTO_TEST_SUITE_END()
962BOOST_FIXTURE_TEST_SUITE(OREAnalyticsTestSuite,
ore::test::OreaTopLevelFixture)
963BOOST_AUTO_TEST_SUITE(SensitivityPerformanceBigPortfolioTest)
966 BOOST_TEST_MESSAGE(
"Testing Sensitivity Performance BigPortfolioNoneObs");
971 BOOST_TEST_MESSAGE(
"Testing Sensitivity Performance BigPortfolioBigScenarioNoneObs");
976 BOOST_TEST_MESSAGE(
"Testing Sensitivity Performance BigPortfolioCrossGammaNoneObs");
980BOOST_AUTO_TEST_SUITE_END()
981BOOST_AUTO_TEST_SUITE_END()
983BOOST_FIXTURE_TEST_SUITE(OREAnalyticsTestSuite,
ore::test::OreaTopLevelFixture)
984BOOST_AUTO_TEST_SUITE(SensitivityPerformanceBigScenarioTest)
987 BOOST_TEST_MESSAGE(
"Testing Sensitivity Performance BigScenarioCrossGammaNoneObs");
991BOOST_AUTO_TEST_SUITE_END()
992BOOST_AUTO_TEST_SUITE_END()
994BOOST_FIXTURE_TEST_SUITE(OREAnalyticsTestSuite,
ore::test::OreaTopLevelFixture)
995BOOST_AUTO_TEST_SUITE(SensitivityPerformanceBigPortfolioBigScenarioTest)
998 BOOST_TEST_MESSAGE(
"Testing Sensitivity Performance BigPortfolioBigScenarioCrossGammaNoneObs");
1002BOOST_AUTO_TEST_SUITE_END()
1003BOOST_AUTO_TEST_SUITE_END()
1005BOOST_FIXTURE_TEST_SUITE(OREAnalyticsTestSuite,
ore::test::OreaTopLevelFixture)
1006BOOST_AUTO_TEST_SUITE(SensitivityPerformanceBTSetupTest)
1009 BOOST_TEST_MESSAGE(
"Testing Sensitivity Performance BTSetupNoneObs");
1013BOOST_AUTO_TEST_SUITE_END()
1014BOOST_AUTO_TEST_SUITE_END()
Write ORE outputs to reports.
virtual void writeSensitivityReport(ore::data::Report &report, const QuantLib::ext::shared_ptr< SensitivityStream > &ss, QuantLib::Real outputThreshold=0.0, QuantLib::Size outputPrecision=2)
ScenarioSimMarket description.
static const string defaultConfiguration
OREAnalytics Top level fixture.
Scenario generation using cross asset model paths.
unsigned long randInt(MersenneTwisterUniformRng &rng, Size min, Size max)
bool randBoolean(MersenneTwisterUniformRng &rng)
const string & randString(MersenneTwisterUniformRng &rng, const vector< string > &strs)
QuantLib::ext::shared_ptr< Portfolio > buildPortfolio(Size portfolioSize, QuantLib::ext::shared_ptr< EngineFactory > &factory)
Class that wraps a sensitivity stream and filters out negligible records.
A cube implementation that stores the cube in memory.
RandomVariable max(RandomVariable x, const RandomVariable &y)
RandomVariable min(RandomVariable x, const RandomVariable &y)
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 > 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)
BOOST_AUTO_TEST_CASE(ZeroShifts1d)
Singleton class to hold global Observation Mode.
Fixture that can be used at top level of OREAnalytics test suites.
Perform parametric var calculation for a given portfolio.
A Class to write ORE outputs to reports.
risk class and type filter
A Market class that can be updated by Scenarios.
A class to hold Scenario parameters for scenarioSimMarket.
Class for aggregating SensitivityRecords.
Perform sensitivity analysis for a given portfolio.
Class for streaming SensitivityRecords from a SensitivityCube.
Class for streaming SensitivityRecords from file.
Class for streaming SensitivityRecords from in-memory container.
Struct for holding a sensitivity record.
Base class for sensitivity record streamer.
factory classes for simple scenarios
perform a stress testing analysis for a given portfolio.
vector< Period > shiftTerms
vector< Real > shiftStrikes
vector< Period > shiftExpiries
QuantLib::ext::shared_ptr< SensitivityScenarioData > setupSensitivityScenarioData5(bool parConversion)
QuantLib::ext::shared_ptr< analytics::ScenarioSimMarketParameters > setupSimMarketData5()
The counterparty cube calculator interface.