Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
blackvariancesurfacestddevs.cpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2019 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 <boost/test/unit_test.hpp>
21#include <ql/quotes/simplequote.hpp>
22#include <ql/termstructures/yield/flatforward.hpp>
23#include <ql/time/calendars/nullcalendar.hpp>
24#include <ql/time/daycounters/actualactual.hpp>
25#include <ql/currencies/europe.hpp>
28
29using namespace boost::unit_test_framework;
30using namespace QuantLib;
31using std::vector;
32
33BOOST_FIXTURE_TEST_SUITE(QuantExtTestSuite, qle::test::TopLevelFixture)
34
35BOOST_AUTO_TEST_SUITE(BlackVarianceSurfaceStdDevs)
36
37BOOST_AUTO_TEST_CASE(testFlatSurface) {
38
39 BOOST_TEST_MESSAGE("Testing QuantExt::BlackVarianceSurfaceStdDevs");
40
41 SavedSettings backup;
42 Settings::instance().evaluationDate() = Date(1, Dec, 2015);
43 Date today = Settings::instance().evaluationDate();
44
45 // we setup a flat surface, all at 12%
46 // Then we ask it for vol at different tenors and strikes
47 Calendar cal = NullCalendar();
48 Handle<Quote> spot = Handle<Quote>(QuantLib::ext::make_shared<SimpleQuote>(100));
49 vector<Time> times = { 1.0, 2.0, 3.0, 4.0 };
50 vector<Real> stdDevs = { -1.0, -0.5, 0, 0.5, 1.0 };
51 Volatility flatVol = 0.12;
52 Handle<Quote> flatVolQ = Handle<Quote>(QuantLib::ext::make_shared<SimpleQuote>(flatVol));
53 vector<vector<Handle<Quote> > > blackVolMatrix(stdDevs.size(), vector<Handle<Quote> >(times.size(), flatVolQ));
54 DayCounter dc = ActualActual(ActualActual::ISDA);
55 Handle<YieldTermStructure> forTS(
56 QuantLib::ext::make_shared<FlatForward>(today, Handle<Quote>(QuantLib::ext::make_shared<SimpleQuote>(0.02)), ActualActual(ActualActual::ISDA)));
57 Handle<YieldTermStructure> domTS(
58 QuantLib::ext::make_shared<FlatForward>(today, Handle<Quote>(QuantLib::ext::make_shared<SimpleQuote>(0.01)), ActualActual(ActualActual::ISDA)));
59
60 QuantLib::ext::shared_ptr<QuantExt::FxIndex> fxIndex =
61 QuantLib::ext::make_shared<QuantExt::FxIndex>("dummy", 2, EURCurrency(),
62 GBPCurrency(), cal, spot, forTS, domTS);
63 QuantExt::BlackVarianceSurfaceStdDevs surface(cal, spot, times, stdDevs, blackVolMatrix, dc, fxIndex);
64
65 // Now get a vol for different times and strikes
66 for (Time t = 0.05; t < 5.0; t += 0.1) {
67 // spot is 100 so strikes should range from (say) 70 to 150
68 for (Real k = 70; k < 150; k += 0.5) {
69 Volatility vol = surface.blackVol(t, k);
70 // BOOST_TEST_MESSAGE("BlackVarianceSurfaceStdDevs vol for t=" << t << " and k=" << k << " is " << vol);
71 BOOST_CHECK_CLOSE(vol, flatVol, 1e-12);
72 }
73 }
74}
75
76BOOST_AUTO_TEST_SUITE_END()
77
78BOOST_AUTO_TEST_SUITE_END()
Black volatility surface modeled as variance surface.
FX index class.
BOOST_AUTO_TEST_CASE(testFlatSurface)
Fixture that can be used at top level.