Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
swaptionmarketdata.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2016 Quaternion Risk Management Ltd
3 All rights reserved.
4
5 This file is part of ORE, a free-software/open-source library
6 for transparent pricing and risk analysis - http://opensourcerisk.org
7
8 ORE is free software: you can redistribute it and/or modify it
9 under the terms of the Modified BSD License. You should have received a
10 copy of the license along with this program.
11 The license is also available online at <http://opensourcerisk.org>
12
13 This program is distributed on the basis that it will form a useful
14 contribution to risk analytics and model standardisation, but WITHOUT
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the license for more details.
17*/
18
19/*! \file test/swaptionmarketdata.hpp
20 \brief structs containing swaption market data that can be used in tests
21*/
22
23#ifndef quantext_test_swaptionmarketdata_hpp
24#define quantext_test_swaptionmarketdata_hpp
25
26#include <boost/make_shared.hpp>
27#include <ql/indexes/ibor/euribor.hpp>
28#include <ql/indexes/swap/euriborswap.hpp>
29#include <ql/math/matrix.hpp>
30#include <ql/math/randomnumbers/mt19937uniformrng.hpp>
31#include <ql/quotes/simplequote.hpp>
32#include <ql/time/calendars/target.hpp>
33#include <ql/time/daycounters/thirty360.hpp>
34#include <ql/time/period.hpp>
35
36#include <vector>
37
38using namespace QuantLib;
39using std::vector;
40
41namespace QuantExt {
43 // Constructor
45 : optionTenors(4), swapTenors(4), strikeSpreads(5), nVols(optionTenors.size(), swapTenors.size(), 0.0),
47 nVolSpreads(16, vector<Handle<Quote> >(5, Handle<Quote>())),
48 lnVolSpreads(16, vector<Handle<Quote> >(5, Handle<Quote>())),
49 slnVolSpreads(16, vector<Handle<Quote> >(5, Handle<Quote>())) {
50
51 // Populate option tenors
52 optionTenors[0] = Period(1, Years);
53 optionTenors[1] = Period(5, Years);
54 optionTenors[2] = Period(7, Years);
55 optionTenors[3] = Period(10, Years);
56
57 // Populate swap tenors
58 swapTenors[0] = Period(1, Years);
59 swapTenors[1] = Period(5, Years);
60 swapTenors[2] = Period(10, Years);
61 swapTenors[3] = Period(20, Years);
62
63 // Populate the normal volatility matrix
64 nVols[0][0] = 0.003543;
65 nVols[0][1] = 0.005270;
66 nVols[0][2] = 0.006978;
67 nVols[0][3] = 0.007918;
68 nVols[1][0] = 0.007013;
69 nVols[1][1] = 0.007443;
70 nVols[1][2] = 0.007820;
71 nVols[1][3] = 0.007363;
72 nVols[2][0] = 0.007519;
73 nVols[2][1] = 0.007807;
74 nVols[2][2] = 0.007698;
75 nVols[2][3] = 0.007117;
76 nVols[3][0] = 0.007668;
77 nVols[3][1] = 0.007705;
78 nVols[3][2] = 0.007611;
79 nVols[3][3] = 0.006848;
80
81 // Populate the lognormal volatility matrix
82 lnVols[0][0] = 2.187660;
83 lnVols[0][1] = 1.748360;
84 lnVols[0][2] = 0.834972;
85 lnVols[0][3] = 0.663957;
86 lnVols[1][0] = 0.891725;
87 lnVols[1][1] = 0.642449;
88 lnVols[1][2] = 0.585798;
89 lnVols[1][3] = 0.512169;
90 lnVols[2][0] = 0.549946;
91 lnVols[2][1] = 0.552918;
92 lnVols[2][2] = 0.528572;
93 lnVols[2][3] = 0.476202;
94 lnVols[3][0] = 0.531597;
95 lnVols[3][1] = 0.534495;
96 lnVols[3][2] = 0.526216;
97 lnVols[3][3] = 0.462007;
98
99 // Populate the first and second set of shifted lognormal volatilities
100 slnVols_1[0][0] = 0.929848;
101 slnVols_1[0][1] = 0.924660;
102 slnVols_1[0][2] = 0.610868;
103 slnVols_1[0][3] = 0.495445;
104 slnVols_1[1][0] = 0.689737;
105 slnVols_1[1][1] = 0.521342;
106 slnVols_1[1][2] = 0.472902;
107 slnVols_1[1][3] = 0.396814;
108 slnVols_1[2][0] = 0.474667;
109 slnVols_1[2][1] = 0.463982;
110 slnVols_1[2][2] = 0.432899;
111 slnVols_1[2][3] = 0.371330;
112 slnVols_1[3][0] = 0.460333;
113 slnVols_1[3][1] = 0.447973;
114 slnVols_1[3][2] = 0.428017;
115 slnVols_1[3][3] = 0.358081;
116
117 slnVols_2[0][0] = 0.732040;
118 slnVols_2[0][1] = 0.754222;
119 slnVols_2[0][2] = 0.539085;
120 slnVols_2[0][3] = 0.439887;
121 slnVols_2[1][0] = 0.622370;
122 slnVols_2[1][1] = 0.477238;
123 slnVols_2[1][2] = 0.431955;
124 slnVols_2[1][3] = 0.357137;
125 slnVols_2[2][0] = 0.444718;
126 slnVols_2[2][1] = 0.430028;
127 slnVols_2[2][2] = 0.397564;
128 slnVols_2[2][3] = 0.335037;
129 slnVols_2[3][0] = 0.432003;
130 slnVols_2[3][1] = 0.415209;
131 slnVols_2[3][2] = 0.392379;
132 slnVols_2[3][3] = 0.322612;
133
134 // Populate first and second set of shifts
135 shifts_1[0][0] = 0.002000;
136 shifts_1[0][1] = 0.002500;
137 shifts_1[0][2] = 0.003000;
138 shifts_1[0][3] = 0.004000;
139 shifts_1[1][0] = 0.002000;
140 shifts_1[1][1] = 0.002500;
141 shifts_1[1][2] = 0.003000;
142 shifts_1[1][3] = 0.004000;
143 shifts_1[2][0] = 0.002000;
144 shifts_1[2][1] = 0.002500;
145 shifts_1[2][2] = 0.003000;
146 shifts_1[2][3] = 0.004000;
147 shifts_1[3][0] = 0.002000;
148 shifts_1[3][1] = 0.002500;
149 shifts_1[3][2] = 0.003000;
150 shifts_1[3][3] = 0.004000;
151
152 shifts_2[0][0] = 0.003000;
153 shifts_2[0][1] = 0.003750;
154 shifts_2[0][2] = 0.004500;
155 shifts_2[0][3] = 0.006000;
156 shifts_2[1][0] = 0.003000;
157 shifts_2[1][1] = 0.003750;
158 shifts_2[1][2] = 0.004500;
159 shifts_2[1][3] = 0.006000;
160 shifts_2[2][0] = 0.003000;
161 shifts_2[2][1] = 0.003750;
162 shifts_2[2][2] = 0.004500;
163 shifts_2[2][3] = 0.006000;
164 shifts_2[3][0] = 0.003000;
165 shifts_2[3][1] = 0.003750;
166 shifts_2[3][2] = 0.004500;
167 shifts_2[3][3] = 0.006000;
168
169 strikeSpreads[0] = -0.02;
170 strikeSpreads[1] = -0.01;
171 strikeSpreads[2] = 0.00;
172 strikeSpreads[3] = +0.01;
173 strikeSpreads[4] = +0.02;
174 Size atmStrikeIndex = 2;
175
176 // random smile
177 MersenneTwisterUniformRng rng(42);
178 Real nVolSpreadMin = 0.0010;
179 Real nVolSpreadMax = 0.0050;
180 Real lnVolSpreadMin = 0.1;
181 Real lnVolSpreadMax = 0.3;
182 Real slnVolSpreadMin = 0.05;
183 Real slnVolSpreadMax = 0.25;
184 for (Size i = 0; i < optionTenors.size(); ++i) {
185 for (Size j = 0; j < swapTenors.size(); ++j) {
186 for (Size k = 0; k < strikeSpreads.size(); ++k) {
187 Size index = j * optionTenors.size() + i;
188 Real nVolSpread =
189 k == atmStrikeIndex ? 0.0 : nVolSpreadMin + rng.nextReal() * (nVolSpreadMax - nVolSpreadMin);
190 nVolSpreads[index][k] = Handle<Quote>(QuantLib::ext::shared_ptr<SimpleQuote>(new SimpleQuote(nVolSpread)));
191 Real lnVolSpread =
192 k == atmStrikeIndex ? 0.0 : lnVolSpreadMin + rng.nextReal() * (lnVolSpreadMax - lnVolSpreadMin);
193 lnVolSpreads[index][k] =
194 Handle<Quote>(QuantLib::ext::shared_ptr<SimpleQuote>(new SimpleQuote(lnVolSpread)));
195 Real slnVolSpread = k == atmStrikeIndex
196 ? 0.0
197 : slnVolSpreadMin + rng.nextReal() * (slnVolSpreadMax - slnVolSpreadMin);
198 slnVolSpreads[index][k] =
199 Handle<Quote>(QuantLib::ext::shared_ptr<SimpleQuote>(new SimpleQuote(slnVolSpread)));
200 }
201 }
202 }
203 }
204
205 // Members
206 vector<Period> optionTenors;
207 vector<Period> swapTenors;
208 vector<Real> strikeSpreads;
209 Matrix nVols;
210 Matrix lnVols;
211 Matrix slnVols_1;
212 Matrix slnVols_2;
213 Matrix shifts_1;
214 Matrix shifts_2;
215
216 vector<vector<Handle<Quote> > > nVolSpreads, lnVolSpreads, slnVolSpreads;
217};
218
220 // Constructor
222 : settlementDays(2), fixedTenor(Period(1, Years)), fixedCalendar(TARGET()), fixedConvention(ModifiedFollowing),
223 fixedDayCounter(Thirty360(Thirty360::BondBasis)), floatIndex(QuantLib::ext::make_shared<Euribor6M>()),
224 swapIndex(QuantLib::ext::make_shared<EuriborSwapIsdaFixA>(10 * Years)),
225 shortSwapIndex(QuantLib::ext::make_shared<EuriborSwapIsdaFixA>(2 * Years)) {}
226
227 // Members
231 BusinessDayConvention fixedConvention;
232 DayCounter fixedDayCounter;
233 QuantLib::ext::shared_ptr<IborIndex> floatIndex;
234 QuantLib::ext::shared_ptr<SwapIndex> swapIndex, shortSwapIndex;
235};
236} // namespace QuantExt
237
238#endif
QuantLib::ext::shared_ptr< SwapIndex > swapIndex
QuantLib::ext::shared_ptr< IborIndex > floatIndex
QuantLib::ext::shared_ptr< SwapIndex > shortSwapIndex
vector< vector< Handle< Quote > > > slnVolSpreads
vector< vector< Handle< Quote > > > lnVolSpreads
vector< vector< Handle< Quote > > > nVolSpreads