103 {
104
105 BOOST_TEST_MESSAGE("Testing YoY Cap Price...");
106
107
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
113 Handle<YoYInflationIndex> infidx = market->yoyInflationIndex("EUHICPXT");
114 QL_REQUIRE(!infidx.empty(), "EUHICPXT inflation index not found");
115
116
118
119
120 Date startDate = today;
121 Date endDate = today + 5 * Years;
122
123
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
133 string conv = "F";
134 string rule = "Forward";
136
137
138 string dc = "ACT/ACT";
139 vector<Real> notional(1, 10000000);
140 string paymentConvention = "F";
141
142
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
151 QuantLib::ext::shared_ptr<Trade> yyCap(
new ore::data::CapFloor(env,
"Long", legYY, caps, std::vector<double>()));
152
153
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
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
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))
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);
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.
Serializable object holding generic trade data, reporting dimensions.
Serializable object holding leg data.
Serializable schedule data.
Serializable object holding schedule Rules data.