Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
Functions
inflationcapfloor.cpp File Reference
#include <boost/make_shared.hpp>
#include <boost/test/unit_test.hpp>
#include <ored/marketdata/marketimpl.hpp>
#include <ored/portfolio/builders/yoycapfloor.hpp>
#include <ored/portfolio/capfloor.hpp>
#include <ored/portfolio/enginedata.hpp>
#include <ored/portfolio/portfolio.hpp>
#include <ored/utilities/indexparser.hpp>
#include <ored/utilities/log.hpp>
#include <oret/toplevelfixture.hpp>
#include <ql/indexes/inflation/euhicp.hpp>
#include <ql/instruments/inflationcapfloor.hpp>
#include <ql/pricingengines/inflation/inflationcapfloorengines.hpp>
#include <ql/termstructures/inflation/inflationhelpers.hpp>
#include <ql/termstructures/volatility/inflation/yoyinflationoptionletvolatilitystructure.hpp>
#include <ql/termstructures/yield/discountcurve.hpp>
#include <ql/termstructures/yield/flatforward.hpp>
#include <ql/time/daycounters/actualactual.hpp>
#include <qle/indexes/inflationindexwrapper.hpp>

Go to the source code of this file.

Functions

 BOOST_AUTO_TEST_CASE (testYoYCapFloor)
 

Function Documentation

◆ BOOST_AUTO_TEST_CASE()

BOOST_AUTO_TEST_CASE ( testYoYCapFloor  )

Definition at line 103 of file inflationcapfloor.cpp.

103 {
104
105 BOOST_TEST_MESSAGE("Testing YoY Cap Price...");
106
107 // build market
108 Date today(18, July, 2016);
109 Settings::instance().evaluationDate() = today;
110
111 QuantLib::ext::shared_ptr<TestMarket> market = QuantLib::ext::make_shared<TestMarket>(today);
112 // Test if EUR yoy inflation curve is empty
113 Handle<YoYInflationIndex> infidx = market->yoyInflationIndex("EUHICPXT");
114 QL_REQUIRE(!infidx.empty(), "EUHICPXT inflation index not found");
115
116 // envelope
117 Envelope env("CP");
118
119 // Start/End date
120 Date startDate = today;
121 Date endDate = today + 5 * Years;
122
123 // date 2 string
124 std::ostringstream oss;
125 oss << io::iso_date(startDate);
126 string start(oss.str());
127 oss.str("");
128 oss.clear();
129 oss << io::iso_date(endDate);
130 string end(oss.str());
131
132 // Schedules
133 string conv = "F";
134 string rule = "Forward";
135 ScheduleData scheduleYY(ScheduleRules(start, end, "1Y", "TARGET", conv, conv, rule));
136
137 // Leg variables
138 string dc = "ACT/ACT";
139 vector<Real> notional(1, 10000000);
140 string paymentConvention = "F";
141
142 // EUR YoY Leg
143 bool isPayerYY = false;
144 string indexYY = "EUHICPXT";
145 string lag = "3M";
146 LegData legYY(QuantLib::ext::make_shared<YoYLegData>(indexYY, lag, 0), isPayerYY, "EUR", scheduleYY, dc, notional,
147 vector<string>(), paymentConvention, false, true);
148
149 std::vector<double> caps(1, 0.009);
150 // Build capfloor trades
151 QuantLib::ext::shared_ptr<Trade> yyCap(new ore::data::CapFloor(env, "Long", legYY, caps, std::vector<double>()));
152
153 // engine data and factory
154 QuantLib::ext::shared_ptr<EngineData> engineData = QuantLib::ext::make_shared<EngineData>();
155 engineData->model("YYCapFloor") = "YYCapModel";
156 engineData->engine("YYCapFloor") = "YYCapEngine";
157 QuantLib::ext::shared_ptr<EngineFactory> engineFactory = QuantLib::ext::make_shared<EngineFactory>(engineData, market);
158
159 // build capfloor and portfolio
160 QuantLib::ext::shared_ptr<Portfolio> portfolio(new Portfolio());
161 yyCap->id() = "YoY_Cap";
162
163 portfolio->add(yyCap);
164 portfolio->build(engineFactory);
165
166 // check YoY cap NPV against pure QL pricing
167 Schedule schedule(startDate, endDate, 1 * Years, TARGET(), Following, Following, DateGeneration::Forward, false);
168 Handle<YieldTermStructure> nominalTs = market->discountCurve("EUR");
169 Leg yyLeg =
170 yoyInflationLeg(schedule, TARGET(), market->yoyInflationIndex("EUHICPXT").currentLink(), Period(3, Months))
171 .withNotionals(10000000)
172 .withPaymentDayCounter(ActualActual(ActualActual::ISDA))
173 .withPaymentAdjustment(Following)
174 .withRateCurve(nominalTs);
175
176 QuantLib::ext::shared_ptr<YoYInflationCapFloor> qlCap(new YoYInflationCap(yyLeg, caps));
177
178 Handle<QuantLib::YoYOptionletVolatilitySurface> hovs = market->yoyCapFloorVol("EUHICPXT");
179 auto dscEngine = QuantLib::ext::make_shared<YoYInflationBachelierCapFloorEngine>(
180 market->yoyInflationIndex("EUHICPXT").currentLink(), hovs, nominalTs);
181 qlCap->setPricingEngine(dscEngine);
182 BOOST_CHECK_CLOSE(yyCap->instrument()->NPV(), qlCap->NPV(), 1E-8); // this is 1E-10 rel diff
183 BOOST_CHECK_NO_THROW(yyCap->additionalData());
184}
yoyInflationLeg & withRateCurve(const Handle< YieldTermStructure > &rateCurve)
yoyInflationLeg & withPaymentAdjustment(BusinessDayConvention)
yoyInflationLeg & withNotionals(Real notional)
yoyInflationLeg & withPaymentDayCounter(const DayCounter &)
Serializable cap, floor, collar.
Definition: capfloor.hpp:37
Serializable object holding generic trade data, reporting dimensions.
Definition: envelope.hpp:51
Serializable object holding leg data.
Definition: legdata.hpp:844
Serializable portfolio.
Definition: portfolio.hpp:43
Serializable schedule data.
Definition: schedule.hpp:202
Serializable object holding schedule Rules data.
Definition: schedule.hpp:37
+ Here is the call graph for this function: