Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
Functions
mxnircurves.cpp File Reference
#include <boost/make_shared.hpp>
#include <boost/test/unit_test.hpp>
#include <ored/configuration/conventions.hpp>
#include <ored/configuration/curveconfigurations.hpp>
#include <ored/marketdata/csvloader.hpp>
#include <ored/marketdata/todaysmarket.hpp>
#include <ored/marketdata/todaysmarketparameters.hpp>
#include <ored/portfolio/enginefactory.hpp>
#include <ored/portfolio/portfolio.hpp>
#include <ored/portfolio/trade.hpp>
#include <oret/datapaths.hpp>
#include <oret/toplevelfixture.hpp>
#include <ql/cashflows/cashflows.hpp>
#include <ql/cashflows/couponpricer.hpp>
#include <ql/instruments/capfloor.hpp>
#include <ql/pricingengines/capfloor/blackcapfloorengine.hpp>
#include <ql/termstructures/volatility/optionlet/constantoptionletvol.hpp>
#include <ql/time/calendar.hpp>
#include <ql/time/daycounter.hpp>

Go to the source code of this file.

Functions

 BOOST_AUTO_TEST_CASE (testSingleCurrencyYieldCurveBootstrap)
 
 BOOST_AUTO_TEST_CASE (testCrossCurrencyYieldCurveBootstrap)
 
 BOOST_AUTO_TEST_CASE (testCapFloorStrip)
 

Function Documentation

◆ BOOST_AUTO_TEST_CASE() [1/3]

BOOST_AUTO_TEST_CASE ( testSingleCurrencyYieldCurveBootstrap  )

Definition at line 52 of file mxnircurves.cpp.

52 {
53
54 // Evaluation date
55 Date asof(17, Apr, 2019);
56 Settings::instance().evaluationDate() = asof;
57
58 // Market
59 auto conventions = QuantLib::ext::make_shared<Conventions>();
60 conventions->fromFile(TEST_INPUT_FILE("conventions_01.xml"));
61 InstrumentConventions::instance().setConventions(conventions);
62
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"));
67 auto loader =
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);
71
72 // Portfolio to test market
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);
79
80 // The single trade in the portfolio is a MXN 10Y swap, i.e. 10 x 13 28D coupons, with nominal 100 million. The
81 // rate on the swap is equal to the 10Y rate in the market file 'market_01.txt' so we should get an NPV of 0.
82 BOOST_CHECK_EQUAL(portfolio->size(), 1);
83 BOOST_CHECK_SMALL(portfolio->trades().begin()->second->instrument()->NPV(), 0.01);
84}
vector< string > curveConfigs

◆ BOOST_AUTO_TEST_CASE() [2/3]

BOOST_AUTO_TEST_CASE ( testCrossCurrencyYieldCurveBootstrap  )

Definition at line 87 of file mxnircurves.cpp.

87 {
88
89 // Evaluation date
90 Date asof(17, Apr, 2019);
91 Settings::instance().evaluationDate() = asof;
92
93 // Market
94 auto conventions = QuantLib::ext::make_shared<Conventions>();
95 conventions->fromFile(TEST_INPUT_FILE("conventions_02.xml"));
96 InstrumentConventions::instance().setConventions(conventions);
97
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"));
102 auto loader =
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);
106
107 // Portfolio to test market
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);
114
115 // The single trade in the portfolio is a USD/MXN 10Y cross currency basis swap, i.e. 10 x 13 28D coupons, with
116 // nominal USD 100 million. The spread on the swap is equal to the 10Y basis spread in the market file
117 // 'market_02.txt' so we should get an NPV of 0.
118 BOOST_CHECK_EQUAL(portfolio->size(), 1);
119 BOOST_CHECK_SMALL(portfolio->trades().begin()->second->instrument()->NPV(), 0.01);
120}

◆ BOOST_AUTO_TEST_CASE() [3/3]

BOOST_AUTO_TEST_CASE ( testCapFloorStrip  )

Definition at line 123 of file mxnircurves.cpp.

123 {
124
125 // Evaluation date
126 Date asof(17, Apr, 2019);
127 Settings::instance().evaluationDate() = asof;
128
129 // Market
130 auto conventions = QuantLib::ext::make_shared<Conventions>();
131 conventions->fromFile(TEST_INPUT_FILE("conventions_03.xml"));
132 InstrumentConventions::instance().setConventions(conventions);
133
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"));
138 auto loader =
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);
142
143 // Portfolio to test market
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);
150
151 // The single trade in the portfolio is a MXN 10Y cap, i.e. 10 x 13 28D coupons (without first caplet), with
152 // nominal USD 100 million.
153 BOOST_CHECK_EQUAL(portfolio->size(), 1);
154
155 // Get the npv of the trade using the market i.e. the stripped optionlet surface from TodaysMarket
156 Real npvTodaysMarket = portfolio->trades().begin()->second->instrument()->NPV();
157 BOOST_TEST_MESSAGE("NPV using TodaysMarket is: " << npvTodaysMarket);
158
159 // Price the same cap using the constant volatility from the market
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();
166 setCouponPricer(leg, pricer);
167 Real npvMarketVol = CashFlows::npv(leg, **market->discountCurve("MXN"), false);
168 BOOST_TEST_MESSAGE("NPV using the constant market volatility is: " << npvMarketVol);
169
170 // Check the difference in the NPVs. Should be small if the stripping is working correctly.
171 BOOST_CHECK_SMALL(fabs(npvTodaysMarket - npvMarketVol), 0.01);
172}
void setCouponPricer(const Leg &leg, const boost::shared_ptr< FloatingRateCouponPricer > &)
+ Here is the call graph for this function: