31 {
32 BOOST_TEST_MESSAGE("Testing simple CBO...");
33
34 Settings::instance().evaluationDate() = Date(31, Dec, 2018);
35 Date asof = Settings::instance().evaluationDate();
36
37
38 auto conventions = QuantLib::ext::make_shared<Conventions>();
39 conventions->fromFile(TEST_INPUT_FILE("conventions.xml"));
40 InstrumentConventions::instance().setConventions(conventions);
41
42 auto todaysMarketParams = QuantLib::ext::make_shared<TodaysMarketParameters>();
43 todaysMarketParams->fromFile(TEST_INPUT_FILE("todaysmarket.xml"));
44 auto curveConfigs = QuantLib::ext::make_shared<CurveConfigurations>();
45 curveConfigs->fromFile(TEST_INPUT_FILE(
"curveconfig.xml"));
46 auto loader = QuantLib::ext::make_shared<CSVLoader>(TEST_INPUT_FILE("market.txt"), TEST_INPUT_FILE("fixings.txt"), false);
47 auto market = QuantLib::ext::make_shared<TodaysMarket>(asof, todaysMarketParams, loader,
curveConfigs,
false);
48
49
50 QuantLib::ext::shared_ptr<EngineData> engineData = QuantLib::ext::make_shared<EngineData>();
51 engineData->fromFile(TEST_INPUT_FILE("pricingengine.xml"));
52 QuantLib::ext::shared_ptr<EngineFactory> factory = QuantLib::ext::make_shared<EngineFactory>(engineData, market);
53
55 BOOST_CHECK_NO_THROW(p.
fromFile(TEST_INPUT_FILE(
"cbo.xml")));
56 BOOST_CHECK_NO_THROW(p.
build(factory));
57
58
59 double expectedNpv = 3013120.939;
60 const Real tol = 0.01;
61
62 BOOST_CHECK_NO_THROW(p.
get(
"CBO-Constellation")->instrument()->NPV());
63 BOOST_TEST_MESSAGE(p.
get(
"CBO-Constellation")->instrument()->NPV());
64 BOOST_CHECK_CLOSE(p.
get(
"CBO-Constellation")->instrument()->NPV(), expectedNpv, tol);
65}
void build(const QuantLib::ext::shared_ptr< EngineFactory > &, const std::string &context="unspecified", const bool emitStructuredError=true)
Call build on all trades in the portfolio, the context is included in error messages.
QuantLib::ext::shared_ptr< Trade > get(const std::string &id) const
void fromFile(const std::string &filename)
vector< string > curveConfigs