6#include <oret/toplevelfixture.hpp>
10using namespace boost::unit_test_framework;
28BOOST_FIXTURE_TEST_SUITE(OREAnalyticsTestSuite, ore::test::TopLevelFixture)
30BOOST_AUTO_TEST_SUITE(ScenarioShiftCalculatorTest)
34 BOOST_TEST_MESSAGE(
"Testing absolute shift in a discount curve");
37 auto ssd = QuantLib::ext::make_shared<SensitivityScenarioData>();
38 auto ssp = QuantLib::ext::make_shared<ScenarioSimMarketParameters>();
41 ssd->discountCurveShiftData()[
"EUR"] = QuantLib::ext::make_shared<CurveShiftData>();
42 ssd->discountCurveShiftData()[
"EUR"]->shiftSize = 0.0001;
43 ssd->discountCurveShiftData()[
"EUR"]->shiftType = ShiftType::Absolute;
45 ssp->setYieldCurveTenors(
"EUR", {3 * Months, 6 * Months});
51 DiscountFactor v_1 = 0.995;
55 DiscountFactor v_2 = 0.990;
62 Real cal = ssc.
shift(rf, scen_1, scen_2);
63 Real
exp = 100.480591307889;
64 BOOST_CHECK_CLOSE(cal,
exp,
tol);
68 ssd->discountCurveShiftData()[
"EUR"]->shiftSize *= factor;
69 cal = ssc.
shift(rf, scen_1, scen_2);
71 BOOST_CHECK_CLOSE(cal,
exp,
tol);
76 BOOST_TEST_MESSAGE(
"Testing relative shift in a discount curve");
79 auto ssd = QuantLib::ext::make_shared<SensitivityScenarioData>();
80 auto ssp = QuantLib::ext::make_shared<ScenarioSimMarketParameters>();
83 ssd->discountCurveShiftData()[
"EUR"] = QuantLib::ext::make_shared<CurveShiftData>();
84 ssd->discountCurveShiftData()[
"EUR"]->shiftSize = 0.01;
85 ssd->discountCurveShiftData()[
"EUR"]->shiftType = ShiftType::Relative;
87 ssp->setYieldCurveTenors(
"EUR", {3 * Months, 6 * Months});
93 DiscountFactor v_1 = 0.995;
97 DiscountFactor v_2 = 0.990;
104 Real cal = ssc.
shift(rf, scen_1, scen_2);
105 Real
exp = 100.503780463123;
106 BOOST_CHECK_CLOSE(cal,
exp,
tol);
110 ssd->discountCurveShiftData()[
"EUR"]->shiftSize *= factor;
111 cal = ssc.
shift(rf, scen_1, scen_2);
113 BOOST_CHECK_CLOSE(cal,
exp,
tol);
118 BOOST_TEST_MESSAGE(
"Testing absolute shift in a survival curve");
121 auto ssd = QuantLib::ext::make_shared<SensitivityScenarioData>();
122 auto ssp = QuantLib::ext::make_shared<ScenarioSimMarketParameters>();
125 ssd->creditCurveShiftData()[
"APPLE"] = QuantLib::ext::make_shared<CurveShiftData>();
126 ssd->creditCurveShiftData()[
"APPLE"]->shiftSize = 0.0010;
127 ssd->creditCurveShiftData()[
"APPLE"]->shiftType = ShiftType::Absolute;
129 ssp->setDefaultTenors(
"APPLE", {3 * Months, 6 * Months, 1 * Years});
135 Probability v_1 = 0.90;
139 Probability v_2 = 0.95;
148 Real cal = ssc.
shift(rf, scen_1, scen_2);
152 Real
exp = -54.067221270275702;
154 BOOST_CHECK_CLOSE(cal,
exp,
tol);
158 ssd->creditCurveShiftData()[
"APPLE"]->shiftSize *= factor;
159 cal = ssc.
shift(rf, scen_1, scen_2);
161 BOOST_CHECK_CLOSE(cal,
exp,
tol);
166 BOOST_TEST_MESSAGE(
"Testing relative shift in a survival curve");
169 auto ssd = QuantLib::ext::make_shared<SensitivityScenarioData>();
170 auto ssp = QuantLib::ext::make_shared<ScenarioSimMarketParameters>();
173 ssd->creditCurveShiftData()[
"APPLE"] = QuantLib::ext::make_shared<CurveShiftData>();
174 ssd->creditCurveShiftData()[
"APPLE"]->shiftSize = 0.10;
175 ssd->creditCurveShiftData()[
"APPLE"]->shiftType = ShiftType::Relative;
177 ssp->setDefaultTenors(
"APPLE", {3 * Months, 6 * Months, 1 * Years});
183 Probability v_1 = 0.90;
187 Probability v_2 = 0.95;
194 Real cal = ssc.
shift(rf, scen_1, scen_2);
195 Real
exp = -5.1316397734676;
196 BOOST_CHECK_CLOSE(cal,
exp,
tol);
200 ssd->creditCurveShiftData()[
"APPLE"]->shiftSize *= factor;
201 cal = ssc.
shift(rf, scen_1, scen_2);
203 BOOST_CHECK_CLOSE(cal,
exp,
tol);
208 BOOST_TEST_MESSAGE(
"Testing absolute shift in a FX spot rate");
211 auto ssd = QuantLib::ext::make_shared<SensitivityScenarioData>();
212 auto ssp = QuantLib::ext::make_shared<ScenarioSimMarketParameters>();
218 ssd->fxShiftData()[
"EURUSD"].shiftSize = shift;
219 ssd->fxShiftData()[
"EURUSD"].shiftType = ShiftType::Absolute;
229 Rate v_2 = v_1 +
exp * shift;
236 Real cal = ssc.
shift(rf, scen_1, scen_2);
237 BOOST_CHECK_CLOSE(cal,
exp,
tol);
240 Real factor = 1 / 5.0;
241 ssd->fxShiftData()[
"EURUSD"].shiftSize *= factor;
242 cal = ssc.
shift(rf, scen_1, scen_2);
244 BOOST_CHECK_CLOSE(cal,
exp,
tol);
249 BOOST_TEST_MESSAGE(
"Testing relative shift in a FX spot rate");
255 auto ssd = QuantLib::ext::make_shared<SensitivityScenarioData>();
256 auto ssp = QuantLib::ext::make_shared<ScenarioSimMarketParameters>();
259 ssd->fxShiftData()[
"EURUSD"].shiftSize = shift;
260 ssd->fxShiftData()[
"EURUSD"].shiftType = ShiftType::Relative;
270 Rate v_2 = v_1 * (1.0 +
exp * shift);
277 Real cal = ssc.
shift(rf, scen_1, scen_2);
278 BOOST_CHECK_CLOSE(cal,
exp,
tol);
281 Real factor = 1 / 2.0;
282 ssd->fxShiftData()[
"EURUSD"].shiftSize *= factor;
283 cal = ssc.
shift(rf, scen_1, scen_2);
285 BOOST_CHECK_CLOSE(cal,
exp,
tol);
290 BOOST_TEST_MESSAGE(
"Testing absolute shift in a swaption volatility");
293 auto ssd = QuantLib::ext::make_shared<SensitivityScenarioData>();
294 auto ssp = QuantLib::ext::make_shared<ScenarioSimMarketParameters>();
300 ssd->swaptionVolShiftData()[
"EUR"].shiftSize = shift;
301 ssd->swaptionVolShiftData()[
"EUR"].shiftType = ShiftType::Absolute;
312 Rate v_2 = v_1 +
exp * shift;
319 Real cal = ssc.
shift(rf, scen_1, scen_2);
320 BOOST_CHECK_CLOSE(cal,
exp,
tol);
323 Real factor = 1 / 2.0;
324 ssd->swaptionVolShiftData()[
"EUR"].shiftSize *= factor;
325 cal = ssc.
shift(rf, scen_1, scen_2);
327 BOOST_CHECK_CLOSE(cal,
exp,
tol);
332 BOOST_TEST_MESSAGE(
"Testing relative shift in a swaption volatility");
335 auto ssd = QuantLib::ext::make_shared<SensitivityScenarioData>();
336 auto ssp = QuantLib::ext::make_shared<ScenarioSimMarketParameters>();
342 ssd->swaptionVolShiftData()[
"EUR"].shiftSize = shift;
343 ssd->swaptionVolShiftData()[
"EUR"].shiftType = ShiftType::Relative;
354 Rate v_2 = v_1 * (1 +
exp * shift);
361 Real cal = ssc.
shift(rf, scen_1, scen_2);
362 BOOST_CHECK_CLOSE(cal,
exp,
tol);
365 Real factor = 1 / 2.0;
366 ssd->swaptionVolShiftData()[
"EUR"].shiftSize *= factor;
367 cal = ssc.
shift(rf, scen_1, scen_2);
369 BOOST_CHECK_CLOSE(cal,
exp,
tol);
372BOOST_AUTO_TEST_SUITE_END()
374BOOST_AUTO_TEST_SUITE_END()
Data types stored in the scenario class.
KeyType
Risk Factor types.
QuantLib::Real shift(const ore::analytics::RiskFactorKey &key, const ore::analytics::Scenario &s_1, const ore::analytics::Scenario &s_2) const
ScenarioSimMarket description.
Description of sensitivity shift scenarios.
void add(const RiskFactorKey &key, Real value) override
Add an element to the scenario.
RandomVariable exp(RandomVariable x)
Class for calculating the shift multiple between two scenarios for a given key.
SensitivityScenarioData::CurveShiftData CurveShiftData
SensitivityScenarioData::SpotShiftData SpotShiftData
BOOST_AUTO_TEST_CASE(testAbsoluteDiscountShift)