6#include <oret/toplevelfixture.hpp>
7#include <boost/make_shared.hpp>
13using namespace boost::unit_test_framework;
19 TestScenarioGenerator() { current_position_ = 0; }
20 void addScenario(QuantLib::ext::shared_ptr<Scenario> s) {
21 scenarios.push_back(s);
25 QuantLib::ext::shared_ptr<Scenario>
next(
const Date& d)
override {
return scenarios[current_position_++]; }
27 void reset()
override { current_position_ = 0; }
29 vector<QuantLib::ext::shared_ptr<Scenario>> scenarios;
32 int current_position_;
35BOOST_FIXTURE_TEST_SUITE(OREAnalyticsTestSuite, ore::test::TopLevelFixture)
37BOOST_AUTO_TEST_SUITE(CSVScenarioGeneratorTest)
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"}};
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());
65 string filename =
"test_csv_scenario_generator.csv";
68 for (Size i = 0; i < tsg->scenarios.size(); i++) {
74 QuantLib::ext::shared_ptr<SimpleScenarioFactory> ssf = QuantLib::ext::make_shared<SimpleScenarioFactory>(
true);
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));
87 remove(
"test_csv_scenario_generator.csv");
90BOOST_AUTO_TEST_SUITE_END()
92BOOST_AUTO_TEST_SUITE_END()
Class for generating scenarios from a csv file assumed to be in a format compatible with ScenarioWrit...
virtual QuantLib::ext::shared_ptr< Scenario > next(const Date &d) override
Return the next scenario for the given date.
Scenario generator base class.
virtual void reset()=0
Reset the generator so calls to next() return the first scenario.
virtual QuantLib::ext::shared_ptr< Scenario > next(const Date &d)=0
Return the next scenario for the given date.
Class for writing scenarios to file.
virtual QuantLib::ext::shared_ptr< Scenario > next(const Date &d) override
Return the next scenario for the given date.
virtual void reset() override
Reset the generator so calls to next() return the first scenario.
factory classes for simple scenarios
BOOST_AUTO_TEST_CASE(testCSVScenarioGenerator)