20#include <boost/test/unit_test.hpp>
21#include <ql/termstructures/volatility/equityfx/blackconstantvol.hpp>
22#include <ql/time/calendars/target.hpp>
23#include <ql/time/daycounters/actualactual.hpp>
30using boost::unit_test_framework::test_suite;
34BOOST_AUTO_TEST_SUITE(BlackTriangulationATMVolTest)
38 BOOST_TEST_MESSAGE(
"Testing BlackTriangulationATMVol");
42 Date today(5, Feb, 2019);
43 Settings::instance().evaluationDate() = today;
44 Calendar cal = TARGET();
45 DayCounter dc = ActualActual(ActualActual::ISDA);
49 Handle<BlackVolTermStructure> constantVol1(QuantLib::ext::make_shared<BlackConstantVol>(today, cal, 0.1, dc));
50 Handle<CorrelationTermStructure> rhoOne(QuantLib::ext::make_shared<FlatCorrelation>(today, 1.0, dc));
54 for (Time t = 0.1; t < 5.0; t += 0.1) {
55 for (Real k = 100; k < 200; k += 10) {
56 Volatility v1 = btavs.blackVol(t, k);
57 BOOST_CHECK_EQUAL(v1, 0.0);
63 Handle<BlackVolTermStructure> constantVol0(QuantLib::ext::make_shared<BlackConstantVol>(today, cal, 0.0, dc));
64 Handle<CorrelationTermStructure> rhoFifty(QuantLib::ext::make_shared<FlatCorrelation>(today, 0.5, dc));
66 for (Time t = 0.1; t < 5.0; t += 0.1) {
67 Real k = Null<Real>();
68 Volatility v1 = constantVol1->blackVol(t, k);
69 Volatility v2 = btavs2.blackVol(t, k);
70 BOOST_CHECK_EQUAL(v1, v2);
75 Handle<BlackVolTermStructure> constantVol2(QuantLib::ext::make_shared<BlackConstantVol>(today, cal, 0.2, dc));
76 Handle<CorrelationTermStructure> rhoZero(QuantLib::ext::make_shared<FlatCorrelation>(today, 0.0, dc));
79 for (Time t = 0.1; t < 5.0; t += 0.1) {
80 Real k = Null<Real>();
81 Volatility v1 = constantVol1->blackVol(t, k);
82 Volatility v2 = constantVol2->blackVol(t, k);
83 Volatility v3 = btavs3.blackVol(t, k);
84 BOOST_CHECK_EQUAL(v1 * v1 + v2 * v2, v3 * v3);
89 Handle<CorrelationTermStructure> rhoEighty(QuantLib::ext::make_shared<FlatCorrelation>(today, 0.8, dc));
91 for (Time t = 0.1; t < 5.0; t += 0.1) {
92 for (Real k = 100; k < 200; k += 10) {
93 Volatility vol = btavs4.blackVol(t, k);
94 Volatility expectedVol = 0.13416407865;
95 BOOST_CHECK_CLOSE(vol, expectedVol, 1E-8);
100BOOST_AUTO_TEST_SUITE_END()
101BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE(testBlackVol)
Black volatility surface that implies an ATM vol based on triangulation.
Black volatility surface that implies an ATM vol based on triangulation.
Term structure of flat correlations.
Fixture that can be used at top level.