Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
Functions
blackvariancesurfacestddevs.cpp File Reference
#include "toplevelfixture.hpp"
#include <boost/test/unit_test.hpp>
#include <ql/quotes/simplequote.hpp>
#include <ql/termstructures/yield/flatforward.hpp>
#include <ql/time/calendars/nullcalendar.hpp>
#include <ql/time/daycounters/actualactual.hpp>
#include <ql/currencies/europe.hpp>
#include <qle/indexes/fxindex.hpp>
#include <qle/termstructures/blackvariancesurfacestddevs.hpp>

Go to the source code of this file.

Functions

 BOOST_AUTO_TEST_CASE (testFlatSurface)
 

Function Documentation

◆ BOOST_AUTO_TEST_CASE()

BOOST_AUTO_TEST_CASE ( testFlatSurface  )

Definition at line 37 of file blackvariancesurfacestddevs.cpp.

37 {
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}