Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
Functions
strippedoptionletadapter2.cpp File Reference
#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/termstructures/strippedoptionletadapter2.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)
 

Function Documentation

◆ BOOST_FIXTURE_TEST_CASE() [1/3]

BOOST_FIXTURE_TEST_CASE ( testFlatExtrapAfterLastExpiry  ,
 
)

Definition at line 84 of file strippedoptionletadapter2.cpp.

84 {
85
86 // Set up optionlet adapter with flat extrapolation
87 QuantLib::ext::shared_ptr<StrippedOptionletAdapter2> adapter =
88 QuantLib::ext::make_shared<StrippedOptionletAdapter2>(optionletSurface, true);
89
90 // Pick a date 1Y after the max date
91 Date testDate = expiries.back() + 1 * Years;
92
93 // Check flat extrapolation on the pillar strikes
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);
97 }
98
99 // Check flat extrapolation below first strike
100 Volatility testVol = adapter->volatility(testDate, strikes.front() / 2.0, true);
101 BOOST_CHECK_CLOSE(testVol, vols.back().front()->value(), 1e-12);
102
103 // Check flat extrapolation above last strike
104 testVol = adapter->volatility(testDate, 2.0 * strikes.back(), true);
105 BOOST_CHECK_CLOSE(testVol, vols.back().back()->value(), 1e-12);
106
107 // Check flat extrapolation between two strikes
108 Rate avgStrike = (strikes[0] + strikes[1]) / 2.0;
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);
112}
vector< Real > strikes

◆ BOOST_FIXTURE_TEST_CASE() [2/3]

BOOST_FIXTURE_TEST_CASE ( testFlatExtrapBetweenFirstLastExpiry  ,
 
)

Definition at line 114 of file strippedoptionletadapter2.cpp.

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

◆ BOOST_FIXTURE_TEST_CASE() [3/3]

BOOST_FIXTURE_TEST_CASE ( testFlatExtrapBeforeFirstExpiry  ,
 
)

Definition at line 145 of file strippedoptionletadapter2.cpp.

145 {
146
147 // Set up optionlet adapter with flat extrapolation
148 QuantLib::ext::shared_ptr<StrippedOptionletAdapter2> adapter =
149 QuantLib::ext::make_shared<StrippedOptionletAdapter2>(optionletSurface, true);
150
151 // Pick a date between evaluation date and first expiry
152 Size numDays = dc.dayCount(asof, expiries.front()) / 2;
153 Date testDate = asof + numDays * Days;
154
155 // Check flat extrapolation on the pillar strikes
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);
159 }
160
161 // Check flat extrapolation below first strike
162 Volatility testVol = adapter->volatility(testDate, strikes.front() / 2.0, true);
163 BOOST_CHECK_CLOSE(testVol, vols.front().front()->value(), 1e-12);
164
165 // Check flat extrapolation above last strike
166 testVol = adapter->volatility(testDate, 2.0 * strikes.back(), true);
167 BOOST_CHECK_CLOSE(testVol, vols.front().back()->value(), 1e-12);
168
169 // Check flat extrapolation between two strikes
170 Rate avgStrike = (strikes[0] + strikes[1]) / 2.0;
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);
174}