Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
blackvolsurfacedelta.cpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2019 Quaternion Risk Management Ltd
3 Copyright (C) 2020 Skandinaviska Enskilda Banken AB (publ)
4 All rights reserved.
5
6 This file is part of ORE, a free-software/open-source library
7 for transparent pricing and risk analysis - http://opensourcerisk.org
8
9 ORE is free software: you can redistribute it and/or modify it
10 under the terms of the Modified BSD License. You should have received a
11 copy of the license along with this program.
12 The license is also available online at <http://opensourcerisk.org>
13
14 This program is distributed on the basis that it will form a useful
15 contribution to risk analytics and model standardisation, but WITHOUT
16 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 FITNESS FOR A PARTICULAR PURPOSE. See the license for more details.
18*/
19
20#include "toplevelfixture.hpp"
21#include <boost/make_shared.hpp>
22#include <boost/test/unit_test.hpp>
23#include <ql/quotes/simplequote.hpp>
24#include <ql/termstructures/yield/flatforward.hpp>
25#include <ql/time/calendars/target.hpp>
26#include <ql/time/daycounters/actualactual.hpp>
28
29using namespace boost::unit_test_framework;
30using namespace QuantLib;
31using namespace QuantExt;
32using namespace std;
33
34BOOST_FIXTURE_TEST_SUITE(QuantExtTestSuite, qle::test::TopLevelFixture)
35
36BOOST_AUTO_TEST_SUITE(BlackVolSurfaceDeltaTest)
37
38BOOST_AUTO_TEST_CASE(testBlackVolSurfaceDeltaConstantVol) {
39
40 BOOST_TEST_MESSAGE("Testing QuantExt::BlackVolatilitySurfaceDelta...");
41
42 Volatility constVol = 0.10; // 10%
43
44 Date refDate(1, Jan, 2010);
45 Settings::instance().evaluationDate() = refDate;
46
47 // Setup a 2x2
48 vector<Date> dates = { Date(1, Jan, 2011), Date(1, Jan, 2012) };
49 vector<Real> putDeltas = { -0.25 };
50 vector<Real> callDeltas = { 0.25 };
51 bool hasAtm = false;
52 Matrix blackVolMatrix(2, 2, constVol);
53
54 // dummy spot and zero yield curve
55 Handle<Quote> spot(QuantLib::ext::make_shared<SimpleQuote>(1.0));
56 Handle<YieldTermStructure> dts(QuantLib::ext::make_shared<FlatForward>(0, TARGET(), 0.011, ActualActual(ActualActual::ISDA)));
57 Handle<YieldTermStructure> fts(QuantLib::ext::make_shared<FlatForward>(0, TARGET(), 0.012, ActualActual(ActualActual::ISDA)));
58
59 // build a vol surface
60 BOOST_TEST_MESSAGE("Build Surface");
61 BlackVolatilitySurfaceDelta surface(refDate, dates, putDeltas, callDeltas, hasAtm, blackVolMatrix, ActualActual(ActualActual::ISDA),
62 TARGET(), spot, dts, fts);
63
64 // ask for volatility at lots of points, should be constVol at every point
65 // make sure we ask for vols outside 25D and 2Y
66 for (Time t : { 0.25, 0.5, 1.0, 1.5, 2.0, 2.5, 10.0 }) {
67 for (Real k = 0.5; k < 2.0; k += 0.05) {
68 Volatility vol = surface.blackVol(t, k);
69 BOOST_CHECK_EQUAL(vol, constVol);
70 }
71 }
72}
73
74BOOST_AUTO_TEST_CASE(testInterpolatedSmileSectionConstruction) {
75
76 BOOST_TEST_MESSAGE("Testing QuantExt::InterpolatedSmileSection...");
77 // Set up the parameters with some arbitrary data
78 Real spot = 100;
79 Real rd = 0.05;
80 Real rf = 0.03;
81 Time t = 1.0;
82 vector<Real> strikes = { 90, 100, 110 };
83 vector<Volatility> vols = { 0.15, 0.1, 0.15 };
84 vector<InterpolatedSmileSection::InterpolationMethod> methods = {
85 InterpolatedSmileSection::InterpolationMethod::Linear,
86 InterpolatedSmileSection::InterpolationMethod::FinancialCubic,
87 InterpolatedSmileSection::InterpolationMethod::NaturalCubic,
88 InterpolatedSmileSection::InterpolationMethod::CubicSpline
89 };
90
91 // Construct the smile section
92 QuantLib::ext::shared_ptr<InterpolatedSmileSection> section;
93 for (auto method : methods) {
94 BOOST_TEST_MESSAGE("Trying to construct InterpolatedSmileSection with interpolation method: " << Integer(method) << ".");
95 BOOST_CHECK_NO_THROW(section =
96 QuantLib::ext::make_shared<InterpolatedSmileSection>(spot, rd, rf, t, strikes, vols, method));
97 BOOST_CHECK_EQUAL(section->volatility(strikes.at(1)), vols.at(1));
98 }
99}
100
101BOOST_AUTO_TEST_SUITE_END()
102
103BOOST_AUTO_TEST_SUITE_END()
Black volatility surface based on delta.
vector< Real > strikes
BOOST_AUTO_TEST_CASE(testBlackVolSurfaceDeltaConstantVol)
Fixture that can be used at top level.