6#include <oret/toplevelfixture.hpp>
17using namespace boost::unit_test_framework;
21BOOST_FIXTURE_TEST_SUITE(OREAnalyticsTestSuite, ore::test::TopLevelFixture)
23BOOST_AUTO_TEST_SUITE(HistoricalScenarioGeneratorTest)
28 "Checking transformation of discount factors to zero rates in Historical Scenario Generator Transform...");
30 vector<QuantLib::ext::shared_ptr<Scenario>> scenarios;
33 Date d1 = Date(14, April, 2016);
34 Date d2 = d1 + Period(1, Days);
35 Settings::instance().evaluationDate() = d2;
37 map<RiskFactorKey, Real> rfks = {{{RiskFactorKey::KeyType::DiscountCurve,
"EUR", 3}, 0.999},
38 {{RiskFactorKey::KeyType::DiscountCurve,
"EUR", 4}, 0.995},
39 {{RiskFactorKey::KeyType::DiscountCurve,
"EUR", 5}, 0.99},
40 {{RiskFactorKey::KeyType::DiscountCurve,
"EUR", 6}, 0.981},
41 {{RiskFactorKey::KeyType::IndexCurve,
"EUR-EURIBOR-6M", 3}, 0.997},
42 {{RiskFactorKey::KeyType::IndexCurve,
"EUR-EURIBOR-6M", 4}, 0.985},
43 {{RiskFactorKey::KeyType::IndexCurve,
"EUR-EURIBOR-6M", 5}, 0.979},
44 {{RiskFactorKey::KeyType::IndexCurve,
"EUR-EURIBOR-6M", 6}, 0.965},
45 {{RiskFactorKey::KeyType::SurvivalProbability,
"dc", 1}, 0.920},
46 {{RiskFactorKey::KeyType::SurvivalProbability,
"dc", 2}, 0.905},
47 {{RiskFactorKey::KeyType::SurvivalProbability,
"dc", 3}, 0.875},
48 {{RiskFactorKey::KeyType::SurvivalProbability,
"dc", 4}, 0.861}};
50 QuantLib::ext::shared_ptr<Scenario> s1 = QuantLib::ext::make_shared<SimpleScenario>(d1);
51 QuantLib::ext::shared_ptr<Scenario> s2 = QuantLib::ext::make_shared<SimpleScenario>(d2);
53 for (
auto rf : rfks) {
55 s2->add(rf.first, rf.second);
58 scenarios.push_back(s1);
59 scenarios.push_back(s2);
60 QuantLib::ext::shared_ptr<HistoricalScenarioLoader> histScenariosLoader = QuantLib::ext::make_shared<HistoricalScenarioLoader>();
61 histScenariosLoader->historicalScenarios() = scenarios;
62 histScenariosLoader->dates() = vector<Date>{d1, d2};
63 QuantLib::ext::shared_ptr<HistoricalScenarioGenerator> histScenarios = QuantLib::ext::make_shared<HistoricalScenarioGenerator>(
64 histScenariosLoader, QuantLib::ext::make_shared<SimpleScenarioFactory>(
true), TARGET(),
nullptr, 1);
65 histScenarios->baseScenario() = s1;
69 QuantLib::ext::shared_ptr<Market> initMarket = QuantLib::ext::make_shared<testsuite::TestMarketParCurves>(d2);
72 QuantLib::ext::shared_ptr<analytics::ScenarioSimMarketParameters> simMarketData =
76 QuantLib::ext::shared_ptr<analytics::ScenarioSimMarket> simMarket =
77 QuantLib::ext::make_shared<analytics::ScenarioSimMarket>(initMarket, simMarketData);
79 QuantLib::ext::shared_ptr<HistoricalScenarioGeneratorTransform> histScenTrasform =
80 QuantLib::ext::make_shared<HistoricalScenarioGeneratorTransform>(histScenarios, simMarket, simMarketData);
81 histScenTrasform->reset();
82 QuantLib::ext::shared_ptr<Scenario> scenarioTransform = histScenTrasform->next(d2);
85 vector<Period> tenors;
86 Real tolerance = 0.0001;
87 for (
auto rfk : rfks) {
89 if (rf.keytype == RiskFactorKey::KeyType::DiscountCurve) {
90 dc = simMarket->discountCurve(rf.name)->dayCounter();
91 tenors = simMarketData->yieldCurveTenors(rf.name);
92 }
else if (rf.keytype == RiskFactorKey::KeyType::IndexCurve) {
93 dc = simMarket->iborIndex(rf.name)->dayCounter();
94 tenors = simMarketData->yieldCurveTenors(rf.name);
95 }
else if (rf.keytype == RiskFactorKey::KeyType::SurvivalProbability) {
96 dc = simMarket->defaultCurve(rf.name)->curve()->dayCounter();
97 tenors = simMarketData->defaultTenors(rf.name);
99 Time t = dc.yearFraction(d2, d2 + tenors[rf.index]);
100 Real expected = std::log(1 / rfk.second) / t;
101 Real transform = scenarioTransform->get(rf);
102 BOOST_CHECK_MESSAGE(fabs(expected - transform) < tolerance,
103 "Difference between expected and transformed rate > than " << tolerance <<
" for key "
108BOOST_AUTO_TEST_SUITE_END()
110BOOST_AUTO_TEST_SUITE_END()
static void setConventions()
Set Conventions.
static QuantLib::ext::shared_ptr< ore::analytics::ScenarioSimMarketParameters > setupSimMarketData(bool hasSwapVolCube=false, bool hasYYCapVols=false)
ScenarioSimMarketParameters instance.
scenario generator that builds from historical shifts
factory classes for simple scenarios
BOOST_AUTO_TEST_CASE(testHistoricalScenarioGeneratorTransform)