Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
dynamicswaptionvolmatrix.cpp
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#include "toplevelfixture.hpp"
20#include "utilities.hpp"
21#include <boost/test/unit_test.hpp>
22
24
25#include <ql/quotes/simplequote.hpp>
26#include <ql/termstructures/volatility/swaption/swaptionvolmatrix.hpp>
27#include <ql/time/calendars/target.hpp>
28
29#include <ql/time/daycounters/actual365fixed.hpp>
30
31using namespace QuantExt;
32using namespace QuantLib;
33using namespace boost::unit_test_framework;
34
35namespace {
36
37struct TestData {
38
39 TestData() : origRefDate(20, Jan, 2016), atmVols(2, 2) {
40
41 Settings::instance().evaluationDate() = origRefDate;
42
43 optionTenors.push_back(3 * Months);
44 optionTenors.push_back(5 * Years);
45 swapTenors.push_back(1 * Years);
46 swapTenors.push_back(2 * Years);
47 // sw 1Y sw 2Y
48 atmVols[0][0] = 0.0050;
49 atmVols[0][1] = 0.0060; // opt 3m
50 atmVols[1][0] = 0.0100;
51 atmVols[1][1] = 0.0160; // opt 2y
52
53 // atm surface
54 atmSurface = QuantLib::ext::make_shared<SwaptionVolatilityMatrix>(origRefDate, TARGET(), Following, optionTenors,
55 swapTenors, atmVols, Actual365Fixed(), false, Normal);
56 }
57
58 SavedSettings backup;
59 const Date origRefDate;
60 QuantLib::ext::shared_ptr<SwaptionVolatilityStructure> atmSurface;
61 std::vector<Period> optionTenors, swapTenors;
62 Matrix atmVols;
63};
64
65} // anonymous namespace
66
67BOOST_FIXTURE_TEST_SUITE(QuantExtTestSuite, qle::test::TopLevelFixture)
68
69BOOST_AUTO_TEST_SUITE(DynamicSwaptionVolMatrixTest)
70
71BOOST_AUTO_TEST_CASE(testConstantVariance) {
72
73 BOOST_TEST_MESSAGE("Testing constant variance dynamics of "
74 "DynamicSwaptionVolatilityMatrix...");
75
76 TestData d;
77
78 QuantLib::ext::shared_ptr<SwaptionVolatilityStructure> dyn =
79 QuantLib::ext::make_shared<DynamicSwaptionVolatilityMatrix>(d.atmSurface, 0, TARGET(), ConstantVariance);
80
81 dyn->enableExtrapolation();
82
83 Real tol = 1.0E-8;
84
85 Real strike = 0.05; // dummy strike
86
87 // initially we should get the same volatilities
88
89 BOOST_CHECK_CLOSE(dyn->volatility(1 * Months, 1 * Years, strike),
90 d.atmSurface->volatility(1 * Months, 1 * Years, strike), tol);
91 BOOST_CHECK_CLOSE(dyn->volatility(1 * Months, 2 * Years, strike),
92 d.atmSurface->volatility(1 * Months, 2 * Years, strike), tol);
93 BOOST_CHECK_CLOSE(dyn->volatility(1 * Years, 1 * Years, strike),
94 d.atmSurface->volatility(1 * Years, 1 * Years, strike), tol);
95 BOOST_CHECK_CLOSE(dyn->volatility(1 * Years, 2 * Years, strike),
96 d.atmSurface->volatility(1 * Years, 2 * Years, strike), tol);
97
98 // move forward in time, we expect a constant surface
99
100 Settings::instance().evaluationDate() = TARGET().advance(d.origRefDate, 5 * Months);
101
102 BOOST_CHECK_CLOSE(dyn->volatility(0.1, 1.0, strike), d.atmSurface->volatility(0.1, 1.0, strike), tol);
103 BOOST_CHECK_CLOSE(dyn->volatility(0.1, 2.0, strike), d.atmSurface->volatility(0.1, 2.0, strike), tol);
104 BOOST_CHECK_CLOSE(dyn->volatility(1.0, 1.0, strike), d.atmSurface->volatility(1.0, 1.0, strike), tol);
105 BOOST_CHECK_CLOSE(dyn->volatility(1.0, 2.0, strike), d.atmSurface->volatility(1.0, 2.0, strike), tol);
106
107} // testConstantVariance
108
109BOOST_AUTO_TEST_CASE(testForwardForwardVariance) {
110
111 BOOST_TEST_MESSAGE("Testing forward forward variance dynamics of "
112 "DynamicSwaptionVolatilityMatrix");
113 TestData d;
114
115 QuantLib::ext::shared_ptr<SwaptionVolatilityStructure> dyn =
116 QuantLib::ext::make_shared<DynamicSwaptionVolatilityMatrix>(d.atmSurface, 0, TARGET(), ForwardForwardVariance);
117
118 dyn->enableExtrapolation();
119
120 Real tol = 1.0E-8;
121
122 Real strike = 0.05; // dummy strike
123
124 // initially we should get the same volatilities again
125
126 BOOST_CHECK_CLOSE(dyn->volatility(1 * Months, 1 * Years, strike),
127 d.atmSurface->volatility(1 * Months, 1 * Years, strike), tol);
128 BOOST_CHECK_CLOSE(dyn->volatility(1 * Months, 2 * Years, strike),
129 d.atmSurface->volatility(1 * Months, 2 * Years, strike), tol);
130 BOOST_CHECK_CLOSE(dyn->volatility(1 * Years, 1 * Years, strike),
131 d.atmSurface->volatility(1 * Years, 1 * Years, strike), tol);
132 BOOST_CHECK_CLOSE(dyn->volatility(1 * Years, 2 * Years, strike),
133 d.atmSurface->volatility(1 * Years, 2 * Years, strike), tol);
134
135 // move forward in time, we expect the forward forward variance
136
137 Settings::instance().evaluationDate() = TARGET().advance(d.origRefDate, 5 * Months);
138 Real tf = d.atmSurface->timeFromReference(Settings::instance().evaluationDate());
139
140 BOOST_CHECK_CLOSE(dyn->blackVariance(0.1, 1.0, strike),
141 d.atmSurface->blackVariance(tf + 0.1, 1.0, strike) - d.atmSurface->blackVariance(tf, 1.0, strike),
142 tol);
143 BOOST_CHECK_CLOSE(dyn->blackVariance(0.1, 2.0, strike),
144 d.atmSurface->blackVariance(tf + 0.1, 2.0, strike) - d.atmSurface->blackVariance(tf, 2.0, strike),
145 tol);
146 BOOST_CHECK_CLOSE(dyn->blackVariance(1.0, 1.0, strike),
147 d.atmSurface->blackVariance(tf + 1.0, 1.0, strike) - d.atmSurface->blackVariance(tf, 1.0, strike),
148 tol);
149 BOOST_CHECK_CLOSE(dyn->blackVariance(1.0, 2.0, strike),
150 d.atmSurface->blackVariance(tf + 1.0, 2.0, strike) - d.atmSurface->blackVariance(tf, 2.0, strike),
151 tol);
152
153} // testForwardForwardVariance
154
155BOOST_AUTO_TEST_SUITE_END()
156
157BOOST_AUTO_TEST_SUITE_END()
dynamic swaption volatility matrix
@ ConstantVariance
@ ForwardForwardVariance
BOOST_AUTO_TEST_CASE(testConstantVariance)
Fixture that can be used at top level.
helper macros and methods for tests