Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
Functions
compositewrapper.cpp File Reference
#include <boost/make_shared.hpp>
#include <boost/test/unit_test.hpp>
#include <ored/configuration/conventions.hpp>
#include <ored/marketdata/csvloader.hpp>
#include <ored/marketdata/todaysmarket.hpp>
#include <ored/portfolio/builders/fxbarrieroption.hpp>
#include <ored/portfolio/builders/fxdigitalbarrieroption.hpp>
#include <ored/portfolio/builders/fxdigitaloption.hpp>
#include <ored/portfolio/builders/fxdoublebarrieroption.hpp>
#include <ored/portfolio/builders/fxdoubletouchoption.hpp>
#include <ored/portfolio/builders/fxtouchoption.hpp>
#include <ored/portfolio/compositeinstrumentwrapper.hpp>
#include <ored/portfolio/enginefactory.hpp>
#include <ored/portfolio/fxbarrieroption.hpp>
#include <ored/portfolio/fxdigitalbarrieroption.hpp>
#include <ored/portfolio/fxdigitaloption.hpp>
#include <ored/portfolio/fxdoublebarrieroption.hpp>
#include <ored/portfolio/fxdoubletouchoption.hpp>
#include <ored/portfolio/fxkikobarrieroption.hpp>
#include <ored/portfolio/fxtouchoption.hpp>
#include <ored/portfolio/portfolio.hpp>
#include <ored/portfolio/tradefactory.hpp>
#include <oret/datapaths.hpp>
#include <oret/toplevelfixture.hpp>

Go to the source code of this file.

Functions

 BOOST_AUTO_TEST_CASE (testCompositeInstrumentWrapperPrice)
 

Function Documentation

◆ BOOST_AUTO_TEST_CASE()

BOOST_AUTO_TEST_CASE ( testCompositeInstrumentWrapperPrice  )

Definition at line 89 of file compositewrapper.cpp.

89 {
90 CommonVars vars;
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>();
96
97 loadFromXMLString(*curveConfig, vars.curveConfig);
98 loadFromXMLString(*conventions, vars.conventions);
99 InstrumentConventions::instance().setConventions(conventions);
100
101 loadFromXMLString(*todaysMarketConfig, vars.todaysMarketConfig);
102 loadFromXMLString(*pricingEngineConfig, vars.pricingEngineConfig);
103
104 portfolio->fromXMLString(vars.portfolio);
105
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);
111
112 BOOST_TEST_MESSAGE("number trades " << portfolio->size());
113 portfolio->build(factory);
114 BOOST_TEST_MESSAGE("number trades " << portfolio->size());
115
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;
119
120 Real totalNPV = 0;
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());
129
130 totalNPV += iw.back()->NPV() * fxRates.back()->value();
131 }
132 QuantLib::ext::shared_ptr<InstrumentWrapper> instrument =
133 QuantLib::ext::shared_ptr<InstrumentWrapper>(new ore::data::CompositeInstrumentWrapper(iw, fxRates, vars.asof));
134
135 BOOST_TEST_MESSAGE(instrument->NPV());
136
137 BOOST_CHECK_CLOSE(instrument->NPV(), totalNPV, 0.01);
138}