20#include <boost/make_shared.hpp>
21#include <boost/test/unit_test.hpp>
22#include <ql/currencies/america.hpp>
23#include <ql/math/matrix.hpp>
24#include <ql/quotes/simplequote.hpp>
25#include <ql/termstructures/volatility/equityfx/blackvariancesurface.hpp>
26#include <ql/termstructures/yield/flatforward.hpp>
27#include <ql/time/calendars/unitedstates.hpp>
28#include <ql/time/daycounters/actualactual.hpp>
32using namespace boost::unit_test_framework;
39BOOST_AUTO_TEST_SUITE(BlackVolSurfaceProxy)
43 BOOST_TEST_MESSAGE(
"Testing QuantExt::BlackVolSurfaceProxy...");
48 Date today = Date(1, Jan, 2020);
49 DayCounter dc = ActualActual(ActualActual::ISDA);
51 Settings::instance().evaluationDate() = today;
54 dates.push_back(Date(3, Feb, 2020));
55 dates.push_back(Date(2, Mar, 2020));
56 dates.push_back(Date(1, Apr, 2020));
57 dates.push_back(Date(4, Jan, 2021));
64 Matrix vols = Matrix(3, 4);
79 Handle<Quote> indexSpot = Handle<Quote>(QuantLib::ext::shared_ptr<Quote>(
new SimpleQuote(1000)));
80 Handle<Quote> underlyingSpot = Handle<Quote>(QuantLib::ext::shared_ptr<Quote>(
new SimpleQuote(150)));
83 Handle<YieldTermStructure> indexForecast = Handle<YieldTermStructure>(
84 QuantLib::ext::make_shared<FlatForward>(today, Handle<Quote>(QuantLib::ext::make_shared<SimpleQuote>(0.03)), dc));
85 Handle<YieldTermStructure> indexDividend = Handle<YieldTermStructure>(
86 QuantLib::ext::make_shared<FlatForward>(today, Handle<Quote>(QuantLib::ext::make_shared<SimpleQuote>(0.02)), dc));
89 Handle<YieldTermStructure> underlyingForecast = Handle<YieldTermStructure>(
90 QuantLib::ext::make_shared<FlatForward>(today, Handle<Quote>(QuantLib::ext::make_shared<SimpleQuote>(0.02)), dc));
91 Handle<YieldTermStructure> underlyingDividend = Handle<YieldTermStructure>(
92 QuantLib::ext::make_shared<FlatForward>(today, Handle<Quote>(QuantLib::ext::make_shared<SimpleQuote>(0.01)), dc));
95 QuantLib::ext::shared_ptr<EquityIndex2> index = QuantLib::ext::make_shared<EquityIndex2>(
"Index", UnitedStates(UnitedStates::Settlement), USDCurrency(),
96 indexSpot, indexForecast, indexDividend);
97 QuantLib::ext::shared_ptr<EquityIndex2> underlying = QuantLib::ext::make_shared<EquityIndex2>(
98 "Underlying", UnitedStates(UnitedStates::Settlement), USDCurrency(), underlyingSpot, underlyingForecast, underlyingDividend);
101 QuantLib::ext::shared_ptr<BlackVolTermStructure> indexVolSurface =
102 QuantLib::ext::make_shared<BlackVarianceSurface>(today, UnitedStates(UnitedStates::Settlement), dates,
strikes, vols, dc);
105 QuantLib::ext::shared_ptr<BlackVolatilitySurfaceProxy> underlyingVolSurface =
106 QuantLib::ext::make_shared<BlackVolatilitySurfaceProxy>(indexVolSurface, underlying, index);
109 for (
auto d : dates) {
111 Real underlyingF = underlying->fixing(d);
113 Real underlyingVol = underlyingVolSurface->blackVol(d, underlyingF);
116 Real indexF = index->fixing(d);
118 Real indexVol = indexVolSurface->blackVol(d, indexF);
120 BOOST_CHECK_CLOSE(underlyingVol, indexVol, 0.001);
124BOOST_AUTO_TEST_SUITE_END()
126BOOST_AUTO_TEST_SUITE_END()
Wrapper class for a BlackVolTermStructure when using proxy vols.
equity index class for holding equity fixing histories and forwarding.
BOOST_AUTO_TEST_CASE(testBlackVolSurfaceProxy)
Fixture that can be used at top level.