19#include <boost/make_shared.hpp>
20#include <boost/test/unit_test.hpp>
28#include <oret/toplevelfixture.hpp>
29#include <ql/indexes/inflation/euhicp.hpp>
30#include <ql/instruments/inflationcapfloor.hpp>
31#include <ql/pricingengines/inflation/inflationcapfloorengines.hpp>
32#include <ql/termstructures/inflation/inflationhelpers.hpp>
33#include <ql/termstructures/volatility/inflation/yoyinflationoptionletvolatilitystructure.hpp>
34#include <ql/termstructures/yield/discountcurve.hpp>
35#include <ql/termstructures/yield/flatforward.hpp>
36#include <ql/time/daycounters/actualactual.hpp>
40using namespace boost::unit_test_framework;
50 dc = ActualActual(ActualActual::ISDA);
55 Handle<YieldTermStructure> nominalTs(QuantLib::ext::make_shared<FlatForward>(0, cal, 0.005, dc));
59 QuantLib::ext::shared_ptr<ZeroInflationIndex> zcindex = QuantLib::ext::shared_ptr<EUHICPXT>(
new EUHICPXT());
61 QuantLib::ext::shared_ptr<YoYInflationIndex> index =
62 QuantLib::ext::make_shared<QuantExt::YoYInflationIndexWrapper>(zcindex,
false);
64 std::vector<Date> datesZCII = {asof + 1 * Years, asof + 2 * Years, asof + 5 * Years, asof + 10 * Years,
66 std::vector<Rate> ratesZCII = {1.1625, 1.23211, 1.36019, 1.51199, 1.74773};
68 std::vector<QuantLib::ext::shared_ptr<YoYInflationTraits::helper>> instruments;
69 for (Size i = 0; i < datesZCII.size(); i++) {
70 Handle<Quote> quote(QuantLib::ext::shared_ptr<Quote>(
new SimpleQuote(ratesZCII[i] / 100)));
71 QuantLib::ext::shared_ptr<YoYInflationTraits::helper> anInstrument =
72 QuantLib::ext::make_shared<YearOnYearInflationSwapHelper>(quote, Period(3, Months), datesZCII[i], cal, bdc, dc,
74 instruments.push_back(anInstrument);
76 QuantLib::ext::shared_ptr<YoYInflationTermStructure> yoyTs = QuantLib::ext::shared_ptr<PiecewiseYoYInflationCurve<Linear>>(
77 new PiecewiseYoYInflationCurve<Linear>(asof, TARGET(), Actual365Fixed(), Period(3, Months), Monthly,
78 index->interpolated(), ratesZCII[0] / 100, instruments));
81 Handle<YoYInflationIndex>(QuantLib::ext::make_shared<QuantExt::YoYInflationIndexWrapper>(
85 QuantLib::ext::shared_ptr<QuantLib::ConstantYoYOptionletVolatility> volSurface =
86 QuantLib::ext::make_shared<QuantLib::ConstantYoYOptionletVolatility>(0.01, 0, cal, bdc, dc, Period(3, Months),
87 Monthly, index->interpolated(), -1.0, 100.0,
88 VolatilityType::Normal);
91 Handle<QuantExt::YoYOptionletVolatilitySurface>(volSurface);
94 BusinessDayConvention bdc;
99BOOST_FIXTURE_TEST_SUITE(OREDataTestSuite, ore::test::TopLevelFixture)
101BOOST_AUTO_TEST_SUITE(InflationCapFloorTests)
105 BOOST_TEST_MESSAGE(
"Testing YoY Cap Price...");
108 Date today(18, July, 2016);
109 Settings::instance().evaluationDate() = today;
111 QuantLib::ext::shared_ptr<TestMarket> market = QuantLib::ext::make_shared<TestMarket>(today);
113 Handle<YoYInflationIndex> infidx = market->yoyInflationIndex(
"EUHICPXT");
114 QL_REQUIRE(!infidx.empty(),
"EUHICPXT inflation index not found");
120 Date startDate = today;
121 Date endDate = today + 5 * Years;
124 std::ostringstream oss;
125 oss << io::iso_date(startDate);
126 string start(oss.str());
129 oss << io::iso_date(endDate);
130 string end(oss.str());
134 string rule =
"Forward";
138 string dc =
"ACT/ACT";
139 vector<Real> notional(1, 10000000);
140 string paymentConvention =
"F";
143 bool isPayerYY =
false;
144 string indexYY =
"EUHICPXT";
146 LegData legYY(QuantLib::ext::make_shared<YoYLegData>(indexYY, lag, 0), isPayerYY,
"EUR", scheduleYY, dc, notional,
147 vector<string>(), paymentConvention,
false,
true);
149 std::vector<double> caps(1, 0.009);
151 QuantLib::ext::shared_ptr<Trade> yyCap(
new ore::data::CapFloor(env,
"Long", legYY, caps, std::vector<double>()));
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);
160 QuantLib::ext::shared_ptr<Portfolio> portfolio(
new Portfolio());
161 yyCap->id() =
"YoY_Cap";
163 portfolio->add(yyCap);
164 portfolio->build(engineFactory);
167 Schedule schedule(startDate, endDate, 1 * Years, TARGET(), Following, Following, DateGeneration::Forward,
false);
168 Handle<YieldTermStructure> nominalTs = market->discountCurve(
"EUR");
170 yoyInflationLeg(schedule, TARGET(), market->yoyInflationIndex(
"EUHICPXT").currentLink(), Period(3, Months))
176 QuantLib::ext::shared_ptr<YoYInflationCapFloor> qlCap(
new YoYInflationCap(yyLeg, caps));
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());
186BOOST_AUTO_TEST_SUITE_END()
188BOOST_AUTO_TEST_SUITE_END()
Ibor cap, floor or collar trade data model and serialization.
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.
static const string defaultConfiguration
Default configuration label.
map< tuple< string, YieldCurveType, string >, Handle< YieldTermStructure > > yieldCurves_
map< pair< string, string >, Handle< YoYOptionletVolatilitySurface > > yoyCapFloorVolSurfaces_
map< pair< string, string >, Handle< YoYInflationIndex > > yoyInflationIndices_
Serializable schedule data.
Serializable object holding schedule Rules data.
A class to hold pricing engine parameters.
QuantLib::ext::shared_ptr< ZeroInflationIndex > parseZeroInflationIndex(const string &s, const Handle< ZeroInflationTermStructure > &h)
Convert std::string to QuantLib::ZeroInflationIndex.
Map text representations to QuantLib/QuantExt types.
BOOST_AUTO_TEST_CASE(testYoYCapFloor)
Classes and functions for log message handling.
An implementation of the Market class that stores the required objects in maps.
Engine builder for year-on-year inflation caps/floors.