19#include <boost/make_shared.hpp>
20#include <boost/test/unit_test.hpp>
41#include <oret/datapaths.hpp>
42#include <oret/toplevelfixture.hpp>
45using namespace boost::unit_test_framework;
49BOOST_FIXTURE_TEST_SUITE(OREPlusEquityFXTestSuite, ore::test::TopLevelFixture)
51BOOST_AUTO_TEST_SUITE(CompositeWrapperTest)
54template <
class T>
void loadFromXMLString(T& t,
const std::string& str) {
63 : asof(Date(5, Feb, 2016)), baseCurrency(
"EUR"),
64 portfolio(
XMLDocument(TEST_INPUT_FILE(
"portfolio.xml")).toString()),
65 conventions(
XMLDocument(TEST_INPUT_FILE(
"conventions.xml")).toString()),
66 todaysMarketConfig(
XMLDocument(TEST_INPUT_FILE(
"todaysmarket.xml")).toString()),
67 pricingEngineConfig(
XMLDocument(TEST_INPUT_FILE(
"pricingengine.xml")).toString()),
68 curveConfig(
XMLDocument(TEST_INPUT_FILE(
"curveconfig.xml")).toString()),
69 loader(
QuantLib::ext::make_shared<
CSVLoader>(TEST_INPUT_FILE(
"market.csv"), TEST_INPUT_FILE(
"fixings.csv"),
"")) {
71 Settings::instance().evaluationDate() = asof;
78 string todaysMarketConfig;
79 string pricingEngineConfig;
81 QuantLib::ext::shared_ptr<Loader> loader;
82 SavedSettings savedSettings;
91 QuantLib::ext::shared_ptr<CurveConfigurations> curveConfig = QuantLib::ext::make_shared<CurveConfigurations>();
92 QuantLib::ext::shared_ptr<Conventions> conventions = QuantLib::ext::make_shared<Conventions>();
93 QuantLib::ext::shared_ptr<TodaysMarketParameters> todaysMarketConfig = QuantLib::ext::make_shared<TodaysMarketParameters>();
94 QuantLib::ext::shared_ptr<EngineData> pricingEngineConfig = QuantLib::ext::make_shared<EngineData>();
95 QuantLib::ext::shared_ptr<Portfolio> portfolio = QuantLib::ext::make_shared<Portfolio>();
97 loadFromXMLString(*curveConfig, vars.curveConfig);
98 loadFromXMLString(*conventions, vars.conventions);
99 InstrumentConventions::instance().setConventions(conventions);
101 loadFromXMLString(*todaysMarketConfig, vars.todaysMarketConfig);
102 loadFromXMLString(*pricingEngineConfig, vars.pricingEngineConfig);
104 portfolio->fromXMLString(vars.portfolio);
106 QuantLib::ext::shared_ptr<Market> market =
107 QuantLib::ext::make_shared<TodaysMarket>(vars.asof, todaysMarketConfig, vars.loader, curveConfig,
true);
108 auto configurations = std::map<MarketContext, string>();
109 QuantLib::ext::shared_ptr<EngineFactory> factory =
110 QuantLib::ext::make_shared<EngineFactory>(pricingEngineConfig, market, configurations);
112 BOOST_TEST_MESSAGE(
"number trades " << portfolio->size());
113 portfolio->build(factory);
114 BOOST_TEST_MESSAGE(
"number trades " << portfolio->size());
116 Handle<Quote> fx = Handle<Quote>(QuantLib::ext::make_shared<SimpleQuote>(1.0));
117 vector<QuantLib::ext::shared_ptr<InstrumentWrapper>> iw;
118 std::vector<Handle<Quote>> fxRates;
121 for (
const auto& [tradeId, trade] : portfolio->trades()) {
122 Handle<Quote> fx = Handle<Quote>(QuantLib::ext::make_shared<SimpleQuote>(1.0));
123 if (trade->npvCurrency() !=
"USD")
124 fx = factory->market()->fxRate(trade->npvCurrency() +
"USD");
125 fxRates.push_back(fx);
126 iw.push_back(trade->instrument());
127 BOOST_TEST_MESSAGE(
"NPV " << iw.back()->NPV());
128 BOOST_TEST_MESSAGE(
"FX " << fxRates.back()->value());
130 totalNPV += iw.back()->NPV() * fxRates.back()->value();
132 QuantLib::ext::shared_ptr<InstrumentWrapper> instrument =
135 BOOST_TEST_MESSAGE(instrument->NPV());
137 BOOST_CHECK_CLOSE(instrument->NPV(), totalNPV, 0.01);
140BOOST_AUTO_TEST_SUITE_END()
142BOOST_AUTO_TEST_SUITE_END()
Utility class for loading market quotes and fixings from a file.
Composite Instrument Wrapper.
Small XML Document wrapper class.
void fromXMLString(const string &xmlString)
load a document from a hard-coded string
XMLNode * getFirstNode(const string &name) const
used to store multiple trade wrappers
BOOST_AUTO_TEST_CASE(testCompositeInstrumentWrapperPrice)
Currency and instrument specific conventions/defaults.
Market Datum Loader Implementation.
FX Barrier Option data model and serialization.
FX Digital Option data model and serialization.
FX Double Barrier Option data model and serialization.
FX Double One-Touch/No-Touch Option data model and serialization.
FX One-Touch/No-Touch Option data model and serialization.
An concrete implementation of the Market class that loads todays market and builds the required curve...