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

Go to the source code of this file.

Functions

 BOOST_AUTO_TEST_CASE (testCSVScenarioGenerator)
 

Function Documentation

◆ BOOST_AUTO_TEST_CASE()

BOOST_AUTO_TEST_CASE ( testCSVScenarioGenerator  )

Definition at line 39 of file scenario.cpp.

39 {
40
41 // Make up some scenarios
42 Date d(21, Dec, 2016);
43 vector<RiskFactorKey> rfks = {{RiskFactorKey::KeyType::DiscountCurve, "CHF", 0},
44 {RiskFactorKey::KeyType::DiscountCurve, "CHF", 1},
45 {RiskFactorKey::KeyType::DiscountCurve, "CHF", 2},
46 {RiskFactorKey::KeyType::YieldCurve, "CHF-LIBOR", 0},
47 {RiskFactorKey::KeyType::YieldCurve, "CHF-LIBOR", 1},
48 {RiskFactorKey::KeyType::IndexCurve, "CHF - LIBOR - 6M", 0},
49 {RiskFactorKey::KeyType::IndexCurve, "CHF - LIBOR - 6M", 1},
50 {RiskFactorKey::KeyType::IndexCurve, "CHF - LIBOR - 6M", 2},
51 {RiskFactorKey::KeyType::SwaptionVolatility, "SwapVol"},
52 {RiskFactorKey::KeyType::FXSpot, "CHF"},
53 {RiskFactorKey::KeyType::FXVolatility, "CHFVol"}};
54
55 QuantLib::ext::shared_ptr<TestScenarioGenerator> tsg = QuantLib::ext::make_shared<TestScenarioGenerator>();
56 tsg->addScenario(QuantLib::ext::make_shared<SimpleScenario>(d));
57 tsg->addScenario(QuantLib::ext::make_shared<SimpleScenario>(d));
58 for (auto scenario : tsg->scenarios) {
59 for (auto rf : rfks) {
60 scenario->add(rf, rand());
61 }
62 }
63
64 // Write scenarios to file
65 string filename = "test_csv_scenario_generator.csv";
66 ScenarioWriter sw(tsg, filename);
67 tsg->reset();
68 for (Size i = 0; i < tsg->scenarios.size(); i++) {
69 sw.next(d);
70 }
71 sw.reset();
72
73 // Read in scenarios from file
74 QuantLib::ext::shared_ptr<SimpleScenarioFactory> ssf = QuantLib::ext::make_shared<SimpleScenarioFactory>(true);
75 CSVScenarioGenerator csvsgen(filename, ssf);
76
77 // Compare scenarios by looping over risk keys
78 for (Size i = 0; i < tsg->scenarios.size(); i++) {
79 QuantLib::ext::shared_ptr<Scenario> s = csvsgen.next(d);
80 BOOST_CHECK_EQUAL_COLLECTIONS(s->keys().begin(), s->keys().end(), tsg->scenarios[i]->keys().begin(),
81 tsg->scenarios[i]->keys().end());
82 for (auto rfk : s->keys()) {
83 BOOST_CHECK_EQUAL(s->get(rfk), tsg->scenarios[i]->get(rfk));
84 }
85 }
86
87 remove("test_csv_scenario_generator.csv");
88}
Class for generating scenarios from a csv file assumed to be in a format compatible with ScenarioWrit...
Class for writing scenarios to file.
+ Here is the call graph for this function: