36 {
37
38 BOOST_TEST_MESSAGE("Testing BlackTriangulationATMVol");
39
40 SavedSettings backup;
41
42 Date today(5, Feb, 2019);
43 Settings::instance().evaluationDate() = today;
44 Calendar cal = TARGET();
45 DayCounter dc = ActualActual(ActualActual::ISDA);
46
47
48
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));
51
53
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);
58 }
59 }
60
61
62
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);
71 }
72
73
74
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));
77
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);
85 }
86
87
88
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);
96 }
97 }
98}
Black volatility surface that implies an ATM vol based on triangulation.