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>
29using namespace boost::unit_test_framework;
36BOOST_AUTO_TEST_SUITE(BlackVolSurfaceDeltaTest)
40 BOOST_TEST_MESSAGE(
"Testing QuantExt::BlackVolatilitySurfaceDelta...");
42 Volatility constVol = 0.10;
44 Date refDate(1, Jan, 2010);
45 Settings::instance().evaluationDate() = refDate;
48 vector<Date> dates = { Date(1, Jan, 2011), Date(1, Jan, 2012) };
49 vector<Real> putDeltas = { -0.25 };
50 vector<Real> callDeltas = { 0.25 };
52 Matrix blackVolMatrix(2, 2, constVol);
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)));
60 BOOST_TEST_MESSAGE(
"Build Surface");
61 BlackVolatilitySurfaceDelta surface(refDate, dates, putDeltas, callDeltas, hasAtm, blackVolMatrix, ActualActual(ActualActual::ISDA),
62 TARGET(), spot, dts, fts);
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);
76 BOOST_TEST_MESSAGE(
"Testing QuantExt::InterpolatedSmileSection...");
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
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));
101BOOST_AUTO_TEST_SUITE_END()
103BOOST_AUTO_TEST_SUITE_END()
Black volatility surface based on delta.
BOOST_AUTO_TEST_CASE(testBlackVolSurfaceDeltaConstantVol)
Fixture that can be used at top level.