Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
Functions
interpolatedyoycapfloortermpricesurface.cpp File Reference
#include "toplevelfixture.hpp"
#include "utilities.hpp"
#include <boost/make_shared.hpp>
#include <boost/test/unit_test.hpp>
#include <qle/termstructures/interpolatedyoycapfloortermpricesurface.hpp>
#include <ql/indexes/inflation/euhicp.hpp>
#include <ql/math/interpolations/bilinearinterpolation.hpp>
#include <ql/math/interpolations/linearinterpolation.hpp>
#include <ql/math/matrix.hpp>
#include <ql/quotes/simplequote.hpp>
#include <ql/termstructures/inflation/piecewisezeroinflationcurve.hpp>
#include <ql/termstructures/volatility/equityfx/blackvariancesurface.hpp>
#include <ql/termstructures/yield/flatforward.hpp>
#include <ql/time/calendars/target.hpp>

Go to the source code of this file.

Functions

 BOOST_AUTO_TEST_CASE (testInterpolatedYoyCapFloorTermPriceSurface)
 

Function Documentation

◆ BOOST_AUTO_TEST_CASE()

BOOST_AUTO_TEST_CASE ( testInterpolatedYoyCapFloorTermPriceSurface  )

Definition at line 44 of file interpolatedyoycapfloortermpricesurface.cpp.

44 {
45
46 BOOST_TEST_MESSAGE("Testing InterpolatedYoyCapFloorTermPriceSurface");
47
48 Date asof_ = Date(18, July, 2016);
49 Settings::instance().evaluationDate() = asof_;
50
51 Handle<YieldTermStructure> nominalTs =
52 Handle<YieldTermStructure>(QuantLib::ext::make_shared<FlatForward>(0, TARGET(), 0.005, Actual365Fixed()));
53
54 std::vector<Rate> capStrikes;
55 capStrikes.push_back(0.01);
56 capStrikes.push_back(0.02);
57 capStrikes.push_back(0.03);
58 capStrikes.push_back(0.04);
59 capStrikes.push_back(0.05);
60
61 std::vector<Rate> floorStrikes;
62 floorStrikes.push_back(-0.02);
63 floorStrikes.push_back(-0.01);
64 floorStrikes.push_back(0.0);
65 floorStrikes.push_back(0.01);
66 floorStrikes.push_back(0.02);
67
68 std::vector<Period> maturities;
69 maturities.push_back(Period(2, Years));
70 maturities.push_back(Period(5, Years));
71 maturities.push_back(Period(7, Years));
72 maturities.push_back(Period(10, Years));
73 maturities.push_back(Period(15, Years));
74 maturities.push_back(Period(20, Years));
75
76 Matrix capPrice(capStrikes.size(), maturities.size(), Null<Real>()),
77 floorPrice(floorStrikes.size(), maturities.size(), Null<Real>());
78
79 capPrice[0][0] = 0.00874;
80 capPrice[1][0] = 0.00146;
81 capPrice[2][0] = 0.00019;
82 capPrice[3][0] = 0.00003;
83 capPrice[4][0] = 0.00001;
84 capPrice[0][1] = 0.02946;
85 capPrice[1][1] = 0.00793;
86 capPrice[2][1] = 0.00214;
87 capPrice[3][1] = 0.00074;
88 capPrice[4][1] = 0.00032;
89 capPrice[0][2] = 0.04626;
90 capPrice[1][2] = 0.01448;
91 capPrice[2][2] = 0.00481;
92 capPrice[3][2] = 0.00206;
93 capPrice[4][2] = 0.00107;
94 capPrice[0][3] = 0.07622;
95 capPrice[1][3] = 0.02778;
96 capPrice[2][3] = 0.01106;
97 capPrice[3][3] = 0.00565;
98 capPrice[4][3] = 0.00343;
99 capPrice[0][4] = 0.13218;
100 capPrice[1][4] = 0.05476;
101 capPrice[2][4] = 0.0245;
102 capPrice[3][4] = 0.01393;
103 capPrice[4][4] = 0.00927;
104 capPrice[0][5] = 0.18889;
105 capPrice[1][5] = 0.08297;
106 capPrice[2][5] = 0.03909;
107 capPrice[3][5] = 0.02369;
108 capPrice[4][5] = 0.01674;
109 floorPrice[0][0] = 0.000000001;
110 floorPrice[1][0] = 0.00005;
111 floorPrice[2][0] = 0.00057;
112 floorPrice[3][0] = 0.00415;
113 floorPrice[4][0] = 0.01695;
114 floorPrice[0][1] = 0.00005;
115 floorPrice[1][1] = 0.00071;
116 floorPrice[2][1] = 0.00259;
117 floorPrice[3][1] = 0.01135;
118 floorPrice[4][1] = 0.03983;
119 floorPrice[0][2] = 0.00035;
120 floorPrice[1][2] = 0.00131;
121 floorPrice[2][2] = 0.00482;
122 floorPrice[3][2] = 0.0169;
123 floorPrice[4][2] = 0.05463;
124 floorPrice[0][3] = 0.0014;
125 floorPrice[1][3] = 0.0036;
126 floorPrice[2][3] = 0.00943;
127 floorPrice[3][3] = 0.02584;
128 floorPrice[4][3] = 0.07515;
129 floorPrice[0][4] = 0.00481;
130 floorPrice[1][4] = 0.00904;
131 floorPrice[2][4] = 0.01814;
132 floorPrice[3][4] = 0.04028;
133 floorPrice[4][4] = 0.10449;
134 floorPrice[0][5] = 0.00832;
135 floorPrice[1][5] = 0.01433;
136 floorPrice[2][5] = 0.02612;
137 floorPrice[3][5] = 0.05269;
138 floorPrice[4][5] = 0.12839;
139
140 // build a
141 std::vector<Date> datesZCII;
142 datesZCII.push_back(asof_ + 1 * Years);
143 std::vector<Rate> ratesZCII;
144 ratesZCII.push_back(1.1625);
145
146 // build EUHICPXT fixing history
147 Schedule fixingDatesEUHICPXT =
148 MakeSchedule().from(Date(1, May, 2015)).to(Date(1, July, 2016)).withTenor(1 * Months);
149 std::vector<Real> fixingRatesEUHICPXT(15, 100);
150
151 Handle<ZeroInflationIndex> hEUHICPXT;
152 QuantLib::ext::shared_ptr<EUHICPXT> ii = QuantLib::ext::shared_ptr<EUHICPXT>(new EUHICPXT());
153 QuantLib::ext::shared_ptr<ZeroInflationTermStructure> cpiTS;
154 for (Size i = 0; i < fixingDatesEUHICPXT.size(); i++) {
155 ii->addFixing(fixingDatesEUHICPXT[i], fixingRatesEUHICPXT[i], true);
156 };
157 // now build the helpers ...
158 std::vector<QuantLib::ext::shared_ptr<BootstrapHelper<ZeroInflationTermStructure> > > instruments;
159 for (Size i = 0; i < datesZCII.size(); i++) {
160 Handle<Quote> quote(QuantLib::ext::shared_ptr<Quote>(new SimpleQuote(ratesZCII[i] / 100.0)));
161 QuantLib::ext::shared_ptr<BootstrapHelper<ZeroInflationTermStructure> > anInstrument(new ZeroCouponInflationSwapHelper(
162 quote, Period(3, Months), datesZCII[i], TARGET(), ModifiedFollowing, Actual365Fixed(), ii, CPI::AsIndex, nominalTs));
163 instruments.push_back(anInstrument);
164 };
165
166 Rate baseZeroRate = ratesZCII[0] / 100.0;
167 QuantLib::ext::shared_ptr<PiecewiseZeroInflationCurve<Linear>> pCPIts(new PiecewiseZeroInflationCurve<Linear>(
168 asof_, TARGET(), Actual365Fixed(), Period(3, Months), Monthly, baseZeroRate, instruments));
169 pCPIts->recalculate();
170 cpiTS = QuantLib::ext::dynamic_pointer_cast<ZeroInflationTermStructure>(pCPIts);
171
172 QuantLib::ext::shared_ptr<EUHICPXT> zii(new EUHICPXT(Handle<ZeroInflationTermStructure>(pCPIts)));
173 QuantLib::ext::shared_ptr<ZeroInflationIndex> zeroIndex = QuantLib::ext::dynamic_pointer_cast<ZeroInflationIndex>(zii);
174
175 QuantLib::ext::shared_ptr<YoYInflationIndex> yoyIndex;
176
177 yoyIndex =
178 QuantLib::ext::make_shared<QuantExt::YoYInflationIndexWrapper>(zeroIndex, true, Handle<YoYInflationTermStructure>());
179
181 0, Period(3, Months), yoyIndex, 1, nominalTs, Actual365Fixed(), TARGET(), Following, capStrikes, floorStrikes,
182 maturities, capPrice, floorPrice);
183
184 QuantLib::ext::shared_ptr<QuantExt::InterpolatedYoYCapFloorTermPriceSurface<Bilinear, Linear> > yoySurface =
185 QuantLib::ext::make_shared<QuantExt::InterpolatedYoYCapFloorTermPriceSurface<Bilinear, Linear> >(ys);
186
187 // check the cap and floor prices from the surface
188 Real tol = 1.0E-8;
189 for (Size i = 0; i < maturities.size(); i++) {
190 Date m = yoySurface->yoyOptionDateFromTenor(maturities[i]);
191 for (Size j = 0; j < capStrikes.size(); j++) {
192 BOOST_CHECK_CLOSE(yoySurface->capPrice(m, capStrikes[j]), capPrice[j][i], tol);
193 }
194 for (Size j = 0; j < floorStrikes.size(); j++) {
195 BOOST_CHECK_CLOSE(yoySurface->floorPrice(m, floorStrikes[j]), floorPrice[j][i], tol);
196 }
197 }
198} // testInterpolatedYoyCapFloorTermPriceSurface
Interpolated YoY Inflation Cap floor term price surface.
Piecewise zero-inflation term structure.