19#include <boost/make_shared.hpp>
21#include <boost/test/unit_test.hpp>
22#include <boost/test/data/test_case.hpp>
35#include <oret/datapaths.hpp>
36#include <oret/toplevelfixture.hpp>
40using namespace boost::unit_test_framework;
44using ore::test::TopLevelFixture;
54class F :
public TopLevelFixture {
57 QuantLib::ext::shared_ptr<Conventions> conventions = QuantLib::ext::make_shared<Conventions>();
58 QuantLib::ext::shared_ptr<EngineFactory> engineFactory;
61 today = Date(31, Dec, 2018);
62 Settings::instance().evaluationDate() = today;
64 conventions->fromFile(TEST_INPUT_FILE(
"conventions.xml"));
65 InstrumentConventions::instance().setConventions(conventions);
67 auto todaysMarketParams = QuantLib::ext::make_shared<TodaysMarketParameters>();
68 todaysMarketParams->fromFile(TEST_INPUT_FILE(
"todaysmarket.xml"));
70 auto curveConfigs = QuantLib::ext::make_shared<CurveConfigurations>();
71 curveConfigs->fromFile(TEST_INPUT_FILE(
"curveconfig.xml"));
73 string marketFile = TEST_INPUT_FILE(
"market.txt");
74 string fixingsFile = TEST_INPUT_FILE(
"fixings.txt");
75 auto loader = QuantLib::ext::make_shared<CSVLoader>(marketFile, fixingsFile,
false);
77 bool continueOnError =
false;
78 QuantLib::ext::shared_ptr<TodaysMarket> market = QuantLib::ext::make_shared<TodaysMarket>(
79 today, todaysMarketParams, loader,
curveConfigs, continueOnError);
81 QuantLib::ext::shared_ptr<EngineData> engineData = QuantLib::ext::make_shared<EngineData>();
82 engineData->fromFile(TEST_INPUT_FILE(
"pricingengine.xml"));
84 engineFactory = QuantLib::ext::make_shared<EngineFactory>(engineData, market);
105vector<string> testCases = {
"portfolio_singleflow.xml",
"portfolio_multiflow.xml",
"portfolio_multiflow_naked.xml"};
109BOOST_FIXTURE_TEST_SUITE(OREDataTestSuite, ore::test::TopLevelFixture)
111BOOST_AUTO_TEST_SUITE(CPICapFloorTests)
115 BOOST_TEST_MESSAGE(
"Testing " << testCase);
118 p.
fromFile(TEST_INPUT_FILE(testCase));
122 p.
build(engineFactory);
123 BOOST_CHECK_MESSAGE(p.
size() == n, n <<
" trades expected after build, found " << p.
size());
124 for (
const auto& [tradeId, trade] : p.
trades()) {
125 BOOST_TEST_MESSAGE(
"trade " << tradeId);
130 Real minimumNPV = QL_MAX_REAL;
131 for (
const auto& [tradeId, trade] : p.
trades()) {
132 BOOST_CHECK_NO_THROW(trade->instrument()->NPV());
133 BOOST_TEST_MESSAGE(
"trade " << tradeId <<
" npv " << trade->instrument()->NPV());
134 sum += trade->instrument()->NPV();
135 minimumNPV = std::min(minimumNPV, fabs(trade->instrument()->NPV()));
136 auto cf = QuantLib::ext::dynamic_pointer_cast<ore::data::CapFloor>(trade);
138 BOOST_CHECK_NO_THROW(cf->additionalData());
140 BOOST_TEST_MESSAGE(
"minimum absolute NPV = " << minimumNPV);
141 Real tolerance = 1.0e-8 * minimumNPV;
142 BOOST_TEST_MESSAGE(
"tolerance = " << tolerance);
143 BOOST_TEST_MESSAGE(
"NPV sum = " << sum);
144 BOOST_CHECK_MESSAGE(fabs(sum) < tolerance,
"portfolio NPV should be zero, found " << sum);
147BOOST_AUTO_TEST_SUITE_END()
149BOOST_AUTO_TEST_SUITE_END()
Ibor cap, floor or collar trade data model and serialization.
BOOST_DATA_TEST_CASE_F(CommonVars, testCapFloorTermVolCurveInterpolation, bdata::make(interpolationTypes) *bdata::make(isMovingValues) *bdata::make(flatFirstPeriodValues), interpolationType, isMoving, flatFirstPeriod)
const std::map< std::string, QuantLib::ext::shared_ptr< Trade > > & trades() const
Return the map tradeId -> trade.
QuantLib::Size size() const
Portfolio size.
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.
void fromFile(const std::string &filename)
Currency and instrument specific conventions/defaults.
utility class to access CSV files
Market Datum Loader Implementation.
Curve configuration repository.
Real sum(const Cash &c, const Cash &d)
vector< string > curveConfigs
string conversion utilities
An concrete implementation of the Market class that loads todays market and builds the required curve...
A class to hold todays market configuration(s)