Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
Functions
strippedoptionletadapter.cpp File Reference
#include <boost/assign.hpp>
#include <boost/test/unit_test.hpp>
#include <ql/quotes/simplequote.hpp>
#include <ql/termstructures/volatility/optionlet/strippedoptionlet.hpp>
#include <ql/time/calendars/unitedstates.hpp>
#include <qle/math/flatextrapolation.hpp>
#include <qle/termstructures/strippedoptionletadapter.hpp>
#include <test/toplevelfixture.hpp>

Go to the source code of this file.

Functions

 BOOST_FIXTURE_TEST_CASE (testFlatExtrapAfterLastExpiry, F)
 
 BOOST_FIXTURE_TEST_CASE (testFlatExtrapBetweenFirstLastExpiry, F)
 
 BOOST_FIXTURE_TEST_CASE (testFlatExtrapBeforeFirstExpiry, F)
 
 BOOST_AUTO_TEST_CASE (testOneStrikeColumn)
 

Function Documentation

◆ BOOST_FIXTURE_TEST_CASE() [1/3]

BOOST_FIXTURE_TEST_CASE ( testFlatExtrapAfterLastExpiry  ,
 
)

Definition at line 87 of file strippedoptionletadapter.cpp.

87 {
88
89 // Set up optionlet adapter with flat extrapolation
90 QuantLib::ext::shared_ptr<StrippedOptionletAdapter<LinearFlat, LinearFlat> > adapter =
91 QuantLib::ext::make_shared<StrippedOptionletAdapter<LinearFlat, LinearFlat> >(optionletSurface);
92
93 // Pick a date 1Y after the max date
94 Date testDate = expiries.back() + 1 * Years;
95
96 // Check flat extrapolation on the pillar strikes
97 for (Size i = 0; i < strikes.size(); i++) {
98 Volatility testVol = adapter->volatility(testDate, strikes[i], true);
99 BOOST_CHECK_CLOSE(testVol, vols.back()[i]->value(), 1e-12);
100 }
101
102 // Check flat extrapolation below first strike
103 Volatility testVol = adapter->volatility(testDate, strikes.front() / 2.0, true);
104 BOOST_CHECK_CLOSE(testVol, vols.back().front()->value(), 1e-12);
105
106 // Check flat extrapolation above last strike
107 testVol = adapter->volatility(testDate, 2.0 * strikes.back(), true);
108 BOOST_CHECK_CLOSE(testVol, vols.back().back()->value(), 1e-12);
109
110 // Check flat extrapolation between two strikes
111 Rate avgStrike = (strikes[0] + strikes[1]) / 2.0;
112 Volatility expectedVol = (vols.back()[0]->value() + vols.back()[1]->value()) / 2.0;
113 testVol = adapter->volatility(testDate, avgStrike, true);
114 BOOST_CHECK_CLOSE(testVol, expectedVol, 1e-12);
115}
vector< Real > strikes

◆ BOOST_FIXTURE_TEST_CASE() [2/3]

BOOST_FIXTURE_TEST_CASE ( testFlatExtrapBetweenFirstLastExpiry  ,
 
)

Definition at line 117 of file strippedoptionletadapter.cpp.

117 {
118
119 // Set up optionlet adapter with flat extrapolation
120 QuantLib::ext::shared_ptr<StrippedOptionletAdapter<LinearFlat, LinearFlat> > adapter =
121 QuantLib::ext::make_shared<StrippedOptionletAdapter<LinearFlat, LinearFlat> >(optionletSurface);
122
123 // Check flat extrapolation on expiry pillars
124 for (Size i = 0; i < expiries.size(); i++) {
125 // Below first strike
126 Volatility testVol = adapter->volatility(expiries[i], strikes.front() / 2.0, true);
127 BOOST_CHECK_CLOSE(testVol, vols[i].front()->value(), 1e-12);
128 // Above last strike
129 testVol = adapter->volatility(expiries[i], 2.0 * strikes.back(), true);
130 BOOST_CHECK_CLOSE(testVol, vols[i].back()->value(), 1e-12);
131 }
132
133 // Pick a date between first expiry and last expiry
134 Size numDays = dc.dayCount(expiries.front(), expiries.back()) / 2;
135 Date testDate = expiries.front() + numDays * Days;
136
137 // Check flat extrapolation below first strike
138 Volatility testVol = adapter->volatility(testDate, strikes.front() / 2.0, true);
139 Volatility expectedVol = adapter->volatility(testDate, strikes.front(), true);
140 BOOST_CHECK_CLOSE(testVol, expectedVol, 1e-12);
141
142 // Check flat extrapolation above last strike
143 testVol = adapter->volatility(testDate, 2.0 * strikes.back(), true);
144 expectedVol = adapter->volatility(testDate, strikes.back(), true);
145 BOOST_CHECK_CLOSE(testVol, expectedVol, 1e-12);
146}

◆ BOOST_FIXTURE_TEST_CASE() [3/3]

BOOST_FIXTURE_TEST_CASE ( testFlatExtrapBeforeFirstExpiry  ,
 
)

Definition at line 148 of file strippedoptionletadapter.cpp.

148 {
149
150 // Set up optionlet adapter with flat extrapolation
151 QuantLib::ext::shared_ptr<StrippedOptionletAdapter<LinearFlat, LinearFlat> > adapter =
152 QuantLib::ext::make_shared<StrippedOptionletAdapter<LinearFlat, LinearFlat> >(optionletSurface);
153
154 // Pick a date between evaluation date and first expiry
155 Size numDays = dc.dayCount(asof, expiries.front()) / 2;
156 Date testDate = asof + numDays * Days;
157
158 // Check flat extrapolation on the pillar strikes
159 for (Size i = 0; i < strikes.size(); i++) {
160 Volatility testVol = adapter->volatility(testDate, strikes[i], true);
161 BOOST_CHECK_CLOSE(testVol, vols.front()[i]->value(), 1e-12);
162 }
163
164 // Check flat extrapolation below first strike
165 Volatility testVol = adapter->volatility(testDate, strikes.front() / 2.0, true);
166 BOOST_CHECK_CLOSE(testVol, vols.front().front()->value(), 1e-12);
167
168 // Check flat extrapolation above last strike
169 testVol = adapter->volatility(testDate, 2.0 * strikes.back(), true);
170 BOOST_CHECK_CLOSE(testVol, vols.front().back()->value(), 1e-12);
171
172 // Check flat extrapolation between two strikes
173 Rate avgStrike = (strikes[0] + strikes[1]) / 2.0;
174 Volatility expectedVol = (vols.front()[0]->value() + vols.front()[1]->value()) / 2.0;
175 testVol = adapter->volatility(testDate, avgStrike, true);
176 BOOST_CHECK_CLOSE(testVol, expectedVol, 1e-12);
177}

◆ BOOST_AUTO_TEST_CASE()

BOOST_AUTO_TEST_CASE ( testOneStrikeColumn  )

Definition at line 179 of file strippedoptionletadapter.cpp.

179 {
180
181 BOOST_TEST_MESSAGE("Testing StrippedOptionletAdapter when StrippedOptionlet has one strike column");
182
183 // As of date
184 Date asof(17, Apr, 2019);
185 Settings::instance().evaluationDate() = asof;
186
187 // Set up the stripped optionlet surface with one strike column
188 Natural settlementDays = 2;
189 UnitedStates calendar(UnitedStates::Settlement);
190 BusinessDayConvention bdc = Following;
191 Actual365Fixed dc;
192 QuantLib::ext::shared_ptr<IborIndex> dummyIborIndex;
193 VolatilityType type = Normal;
194 vector<Date> expiries = list_of(Date(17, Jul, 2019))(Date(17, Oct, 2019));
195 vector<Rate> strikes = list_of(0.0);
196
197 vector<vector<Handle<Quote> > > vols(2);
198 vols[0].push_back(Handle<Quote>(QuantLib::ext::make_shared<SimpleQuote>(0.0091)));
199 vols[1].push_back(Handle<Quote>(QuantLib::ext::make_shared<SimpleQuote>(0.0070)));
200
201 // Create the optionlet surface
202 QuantLib::ext::shared_ptr<StrippedOptionlet> optionletSurface = QuantLib::ext::make_shared<StrippedOptionlet>(
203 settlementDays, calendar, bdc, dummyIborIndex, expiries, strikes, vols, dc, type);
204
205 // Set up optionlet adapter with flat extrapolation
206 QuantLib::ext::shared_ptr<StrippedOptionletAdapter<LinearFlat, LinearFlat> > adapter =
207 QuantLib::ext::make_shared<StrippedOptionletAdapter<LinearFlat, LinearFlat> >(optionletSurface);
208
209 // Ask for vols on expiry dates at any strikes and should get back inputs
210 Volatility strikeShift = 0.10;
211 Volatility testVol = adapter->volatility(expiries[0], 0.0, true);
212 Volatility expectedVol = vols[0][0]->value();
213 BOOST_CHECK_CLOSE(testVol, expectedVol, 1e-12);
214
215 testVol = adapter->volatility(expiries[0], 0.0 + strikeShift, true);
216 BOOST_CHECK_CLOSE(testVol, expectedVol, 1e-12);
217
218 testVol = adapter->volatility(expiries[0], 0.0 - strikeShift, true);
219 BOOST_CHECK_CLOSE(testVol, expectedVol, 1e-12);
220
221 testVol = adapter->volatility(expiries[0] - 1 * Weeks, 0.0, true);
222 BOOST_CHECK_CLOSE(testVol, expectedVol, 1e-12);
223
224 testVol = adapter->volatility(expiries[1], 0.0, true);
225 expectedVol = vols[1][0]->value();
226 BOOST_CHECK_CLOSE(testVol, expectedVol, 1e-12);
227
228 testVol = adapter->volatility(expiries[1] + 1 * Weeks, 0.0, true);
229 BOOST_CHECK_CLOSE(testVol, expectedVol, 1e-12);
230}