Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
Functions
historicalscenariogenerator.cpp File Reference
#include <oret/toplevelfixture.hpp>
#include <orea/scenario/simplescenario.hpp>
#include <orea/scenario/simplescenariofactory.hpp>
#include <orea/scenario/historicalscenariogenerator.hpp>
#include "testmarket.hpp"

Go to the source code of this file.

Functions

 BOOST_AUTO_TEST_CASE (testHistoricalScenarioGeneratorTransform)
 

Function Documentation

◆ BOOST_AUTO_TEST_CASE()

BOOST_AUTO_TEST_CASE ( testHistoricalScenarioGeneratorTransform  )

Definition at line 25 of file historicalscenariogenerator.cpp.

25 {
26
27 BOOST_TEST_MESSAGE(
28 "Checking transformation of discount factors to zero rates in Historical Scenario Generator Transform...");
29
30 vector<QuantLib::ext::shared_ptr<Scenario>> scenarios;
31
32 // Make up some scenarios
33 Date d1 = Date(14, April, 2016);
34 Date d2 = d1 + Period(1, Days);
35 Settings::instance().evaluationDate() = d2;
36
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}};
49
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);
52
53 for (auto rf : rfks) {
54 s1->add(rf.first, 1);
55 s2->add(rf.first, rf.second);
56 }
57
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;
66
67 // Init market
69 QuantLib::ext::shared_ptr<Market> initMarket = QuantLib::ext::make_shared<testsuite::TestMarketParCurves>(d2);
70
71 // build scen sim market params
72 QuantLib::ext::shared_ptr<analytics::ScenarioSimMarketParameters> simMarketData =
74
75 // build scenario sim market
76 QuantLib::ext::shared_ptr<analytics::ScenarioSimMarket> simMarket =
77 QuantLib::ext::make_shared<analytics::ScenarioSimMarket>(initMarket, simMarketData);
78
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);
83
84 DayCounter dc;
85 vector<Period> tenors;
86 Real tolerance = 0.0001;
87 for (auto rfk : rfks) {
88 auto rf = rfk.first;
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);
98 }
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 "
104 << rf.name);
105 }
106}
static void setConventions()
Set Conventions.
static QuantLib::ext::shared_ptr< ore::analytics::ScenarioSimMarketParameters > setupSimMarketData(bool hasSwapVolCube=false, bool hasYYCapVols=false)
ScenarioSimMarketParameters instance.
+ Here is the call graph for this function: