19#include <boost/make_shared.hpp>
20#include <boost/test/unit_test.hpp>
29#include <oret/datapaths.hpp>
30#include <oret/toplevelfixture.hpp>
32#include <ql/cashflows/cashflows.hpp>
33#include <ql/cashflows/couponpricer.hpp>
34#include <ql/instruments/capfloor.hpp>
35#include <ql/pricingengines/capfloor/blackcapfloorengine.hpp>
36#include <ql/termstructures/volatility/optionlet/constantoptionletvol.hpp>
37#include <ql/time/calendar.hpp>
38#include <ql/time/daycounter.hpp>
42using namespace boost::unit_test_framework;
44using ore::test::TopLevelFixture;
47BOOST_FIXTURE_TEST_SUITE(OREDataTestSuite, TopLevelFixture)
49BOOST_AUTO_TEST_SUITE(MXNIrCurvesTest)
55 Date asof(17, Apr, 2019);
56 Settings::instance().evaluationDate() = asof;
59 auto conventions = QuantLib::ext::make_shared<Conventions>();
60 conventions->fromFile(TEST_INPUT_FILE(
"conventions_01.xml"));
61 InstrumentConventions::instance().setConventions(conventions);
63 auto todaysMarketParams = QuantLib::ext::make_shared<TodaysMarketParameters>();
64 todaysMarketParams->fromFile(TEST_INPUT_FILE(
"todaysmarket_01.xml"));
65 auto curveConfigs = QuantLib::ext::make_shared<CurveConfigurations>();
66 curveConfigs->fromFile(TEST_INPUT_FILE(
"curveconfig_01.xml"));
68 QuantLib::ext::make_shared<CSVLoader>(TEST_INPUT_FILE(
"market_01.txt"), TEST_INPUT_FILE(
"fixings.txt"),
false);
69 QuantLib::ext::shared_ptr<TodaysMarket> market =
70 QuantLib::ext::make_shared<TodaysMarket>(asof, todaysMarketParams, loader,
curveConfigs,
false);
73 QuantLib::ext::shared_ptr<EngineData> engineData = QuantLib::ext::make_shared<EngineData>();
74 engineData->fromFile(TEST_INPUT_FILE(
"pricingengine_01.xml"));
75 QuantLib::ext::shared_ptr<EngineFactory> factory = QuantLib::ext::make_shared<EngineFactory>(engineData, market);
76 QuantLib::ext::shared_ptr<Portfolio> portfolio = QuantLib::ext::make_shared<Portfolio>();
77 portfolio->fromFile(TEST_INPUT_FILE(
"mxn_ir_swap.xml"));
78 portfolio->build(factory);
82 BOOST_CHECK_EQUAL(portfolio->size(), 1);
83 BOOST_CHECK_SMALL(portfolio->trades().begin()->second->instrument()->NPV(), 0.01);
90 Date asof(17, Apr, 2019);
91 Settings::instance().evaluationDate() = asof;
94 auto conventions = QuantLib::ext::make_shared<Conventions>();
95 conventions->fromFile(TEST_INPUT_FILE(
"conventions_02.xml"));
96 InstrumentConventions::instance().setConventions(conventions);
98 auto todaysMarketParams = QuantLib::ext::make_shared<TodaysMarketParameters>();
99 todaysMarketParams->fromFile(TEST_INPUT_FILE(
"todaysmarket_02.xml"));
100 auto curveConfigs = QuantLib::ext::make_shared<CurveConfigurations>();
101 curveConfigs->fromFile(TEST_INPUT_FILE(
"curveconfig_02.xml"));
103 QuantLib::ext::make_shared<CSVLoader>(TEST_INPUT_FILE(
"market_02.txt"), TEST_INPUT_FILE(
"fixings.txt"),
false);
104 QuantLib::ext::shared_ptr<TodaysMarket> market =
105 QuantLib::ext::make_shared<TodaysMarket>(asof, todaysMarketParams, loader,
curveConfigs,
false);
108 QuantLib::ext::shared_ptr<EngineData> engineData = QuantLib::ext::make_shared<EngineData>();
109 engineData->fromFile(TEST_INPUT_FILE(
"pricingengine_02.xml"));
110 QuantLib::ext::shared_ptr<EngineFactory> factory = QuantLib::ext::make_shared<EngineFactory>(engineData, market);
111 QuantLib::ext::shared_ptr<Portfolio> portfolio = QuantLib::ext::make_shared<Portfolio>();
112 portfolio->fromFile(TEST_INPUT_FILE(
"mxn_usd_xccy_swap.xml"));
113 portfolio->build(factory);
118 BOOST_CHECK_EQUAL(portfolio->size(), 1);
119 BOOST_CHECK_SMALL(portfolio->trades().begin()->second->instrument()->NPV(), 0.01);
126 Date asof(17, Apr, 2019);
127 Settings::instance().evaluationDate() = asof;
130 auto conventions = QuantLib::ext::make_shared<Conventions>();
131 conventions->fromFile(TEST_INPUT_FILE(
"conventions_03.xml"));
132 InstrumentConventions::instance().setConventions(conventions);
134 auto todaysMarketParams = QuantLib::ext::make_shared<TodaysMarketParameters>();
135 todaysMarketParams->fromFile(TEST_INPUT_FILE(
"todaysmarket_03.xml"));
136 auto curveConfigs = QuantLib::ext::make_shared<CurveConfigurations>();
137 curveConfigs->fromFile(TEST_INPUT_FILE(
"curveconfig_03.xml"));
139 QuantLib::ext::make_shared<CSVLoader>(TEST_INPUT_FILE(
"market_03.txt"), TEST_INPUT_FILE(
"fixings.txt"),
false);
140 QuantLib::ext::shared_ptr<TodaysMarket> market =
141 QuantLib::ext::make_shared<TodaysMarket>(asof, todaysMarketParams, loader,
curveConfigs,
false);
144 QuantLib::ext::shared_ptr<EngineData> engineData = QuantLib::ext::make_shared<EngineData>();
145 engineData->fromFile(TEST_INPUT_FILE(
"pricingengine_03.xml"));
146 QuantLib::ext::shared_ptr<EngineFactory> factory = QuantLib::ext::make_shared<EngineFactory>(engineData, market);
147 QuantLib::ext::shared_ptr<Portfolio> portfolio = QuantLib::ext::make_shared<Portfolio>();
148 portfolio->fromFile(TEST_INPUT_FILE(
"mxn_ir_cap.xml"));
149 portfolio->build(factory);
153 BOOST_CHECK_EQUAL(portfolio->size(), 1);
156 Real npvTodaysMarket = portfolio->trades().begin()->second->instrument()->NPV();
157 BOOST_TEST_MESSAGE(
"NPV using TodaysMarket is: " << npvTodaysMarket);
160 auto trade = portfolio->trades().begin()->second;
161 BOOST_REQUIRE(trade);
162 BOOST_REQUIRE(trade->legs().size() == 1);
163 auto pricer = QuantLib::ext::make_shared<BlackIborCouponPricer>(Handle<OptionletVolatilityStructure>(
164 QuantLib::ext::make_shared<ConstantOptionletVolatility>(0, NullCalendar(), Unadjusted, 0.20320, Actual365Fixed())));
165 Leg leg = trade->legs().front();
167 Real npvMarketVol = CashFlows::npv(leg, **market->discountCurve(
"MXN"),
false);
168 BOOST_TEST_MESSAGE(
"NPV using the constant market volatility is: " << npvMarketVol);
171 BOOST_CHECK_SMALL(fabs(npvTodaysMarket - npvMarketVol), 0.01);
174BOOST_AUTO_TEST_SUITE_END()
176BOOST_AUTO_TEST_SUITE_END()
Currency and instrument specific conventions/defaults.
Market Datum Loader Implementation.
Curve configuration repository.
void setCouponPricer(const Leg &leg, const boost::shared_ptr< FloatingRateCouponPricer > &)
BOOST_AUTO_TEST_CASE(testSingleCurrencyYieldCurveBootstrap)
vector< string > curveConfigs
An concrete implementation of the Market class that loads todays market and builds the required curve...
A class to hold todays market configuration(s)
base trade data model and serialization