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

Go to the source code of this file.

Functions

 BOOST_AUTO_TEST_CASE (testBlackVolSurfaceDeltaConstantVol)
 
 BOOST_AUTO_TEST_CASE (testInterpolatedSmileSectionConstruction)
 

Function Documentation

◆ BOOST_AUTO_TEST_CASE() [1/2]

BOOST_AUTO_TEST_CASE ( testBlackVolSurfaceDeltaConstantVol  )

Definition at line 38 of file blackvolsurfacedelta.cpp.

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

◆ BOOST_AUTO_TEST_CASE() [2/2]

BOOST_AUTO_TEST_CASE ( testInterpolatedSmileSectionConstruction  )

Definition at line 74 of file blackvolsurfacedelta.cpp.

74 {
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}
vector< Real > strikes