19#include <boost/test/unit_test.hpp>
20#include <ql/quotes/simplequote.hpp>
21#include <ql/termstructures/volatility/optionlet/strippedoptionlet.hpp>
22#include <ql/time/calendars/unitedstates.hpp>
28using namespace boost::unit_test_framework;
39 vector<Date> expiries;
42 vector<vector<Handle<Quote> > > vols;
43 QuantLib::ext::shared_ptr<StrippedOptionlet> optionletSurface;
45 F() : expiries(2),
strikes(2), dc(Actual365Fixed()), vols(2) {
48 asof = Date(17, Apr, 2019);
49 Settings::instance().evaluationDate() = asof;
52 Natural settlementDays = 2;
53 UnitedStates calendar(UnitedStates::Settlement);
54 BusinessDayConvention bdc = Following;
55 QuantLib::ext::shared_ptr<IborIndex> dummyIborIndex;
56 VolatilityType type = Normal;
58 expiries[0] = Date(17, Apr, 2020);
59 expiries[1] = Date(19, Apr, 2021);
65 vols[0].push_back(Handle<Quote>(QuantLib::ext::make_shared<SimpleQuote>(0.0091)));
66 vols[0].push_back(Handle<Quote>(QuantLib::ext::make_shared<SimpleQuote>(0.0092)));
67 vols[1].push_back(Handle<Quote>(QuantLib::ext::make_shared<SimpleQuote>(0.0070)));
68 vols[1].push_back(Handle<Quote>(QuantLib::ext::make_shared<SimpleQuote>(0.0088)));
72 optionletSurface = QuantLib::ext::make_shared<StrippedOptionlet>(settlementDays, calendar, bdc, dummyIborIndex,
73 expiries,
strikes, vols, dc, type);
82BOOST_AUTO_TEST_SUITE(StrippedOptionletAdapterTwoTests)
87 QuantLib::ext::shared_ptr<StrippedOptionletAdapter2> adapter =
88 QuantLib::ext::make_shared<StrippedOptionletAdapter2>(optionletSurface,
true);
91 Date testDate = expiries.back() + 1 * Years;
94 for (Size i = 0; i <
strikes.size(); i++) {
95 Volatility testVol = adapter->volatility(testDate,
strikes[i],
true);
96 BOOST_CHECK_CLOSE(testVol, vols.back()[i]->value(), 1e-12);
100 Volatility testVol = adapter->volatility(testDate,
strikes.front() / 2.0,
true);
101 BOOST_CHECK_CLOSE(testVol, vols.back().front()->value(), 1e-12);
104 testVol = adapter->volatility(testDate, 2.0 *
strikes.back(),
true);
105 BOOST_CHECK_CLOSE(testVol, vols.back().back()->value(), 1e-12);
109 Volatility expectedVol = (vols.back()[0]->value() + vols.back()[1]->value()) / 2.0;
110 testVol = adapter->volatility(testDate, avgStrike,
true);
111 BOOST_CHECK_CLOSE(testVol, expectedVol, 1e-12);
117 QuantLib::ext::shared_ptr<StrippedOptionletAdapter2> adapter =
118 QuantLib::ext::make_shared<StrippedOptionletAdapter2>(optionletSurface,
true);
121 for (Size i = 0; i < expiries.size(); i++) {
123 Volatility testVol = adapter->volatility(expiries[i],
strikes.front() / 2.0,
true);
124 BOOST_CHECK_CLOSE(testVol, vols[i].front()->value(), 1e-12);
126 testVol = adapter->volatility(expiries[i], 2.0 *
strikes.back(),
true);
127 BOOST_CHECK_CLOSE(testVol, vols[i].back()->value(), 1e-12);
131 Size numDays = dc.dayCount(expiries.front(), expiries.back()) / 2;
132 Date testDate = expiries.front() + numDays * Days;
135 Volatility testVol = adapter->volatility(testDate,
strikes.front() / 2.0,
true);
136 Volatility expectedVol = adapter->volatility(testDate,
strikes.front(),
true);
137 BOOST_CHECK_CLOSE(testVol, expectedVol, 1e-12);
140 testVol = adapter->volatility(testDate, 2.0 *
strikes.back(),
true);
141 expectedVol = adapter->volatility(testDate,
strikes.back(),
true);
142 BOOST_CHECK_CLOSE(testVol, expectedVol, 1e-12);
148 QuantLib::ext::shared_ptr<StrippedOptionletAdapter2> adapter =
149 QuantLib::ext::make_shared<StrippedOptionletAdapter2>(optionletSurface,
true);
152 Size numDays = dc.dayCount(asof, expiries.front()) / 2;
153 Date testDate = asof + numDays * Days;
156 for (Size i = 0; i <
strikes.size(); i++) {
157 Volatility testVol = adapter->volatility(testDate,
strikes[i],
true);
158 BOOST_CHECK_CLOSE(testVol, vols.front()[i]->value(), 1e-12);
162 Volatility testVol = adapter->volatility(testDate,
strikes.front() / 2.0,
true);
163 BOOST_CHECK_CLOSE(testVol, vols.front().front()->value(), 1e-12);
166 testVol = adapter->volatility(testDate, 2.0 *
strikes.back(),
true);
167 BOOST_CHECK_CLOSE(testVol, vols.front().back()->value(), 1e-12);
171 Volatility expectedVol = (vols.front()[0]->value() + vols.front()[1]->value()) / 2.0;
172 testVol = adapter->volatility(testDate, avgStrike,
true);
173 BOOST_CHECK_CLOSE(testVol, expectedVol, 1e-12);
176BOOST_AUTO_TEST_SUITE_END()
178BOOST_AUTO_TEST_SUITE_END()
StrippedOptionlet Adapter (with a deeper update method, linear interpolation and optional flat extrap...
BOOST_FIXTURE_TEST_CASE(testFlatExtrapAfterLastExpiry, F)
Fixture that can be used at top level.