39 {
40
41
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
65 string filename = "test_csv_scenario_generator.csv";
67 tsg->reset();
68 for (Size i = 0; i < tsg->scenarios.size(); i++) {
69 sw.next(d);
70 }
71 sw.reset();
72
73
74 QuantLib::ext::shared_ptr<SimpleScenarioFactory> ssf = QuantLib::ext::make_shared<SimpleScenarioFactory>(true);
76
77
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.