37 {
38
39 BOOST_TEST_MESSAGE("Testing QuantExt::BlackVarianceCurve3...");
40
41 SavedSettings backup;
42 Settings::instance().evaluationDate() = Date(1, Dec, 2015);
43 Date today = Settings::instance().evaluationDate();
44
45 Natural settlementDays = 0;
46 Calendar cal = TARGET();
47 BusinessDayConvention bdc = Following;
48 DayCounter dc = ActualActual(ActualActual::ISDA);
49
50 vector<Time> times;
51 vector<Date> dates;
52 vector<Volatility> vols;
53 vector<QuantLib::ext::shared_ptr<SimpleQuote> > simpleQuotes;
54 vector<Handle<Quote> > quotes;
55
56 Size numYears = 10;
57 for (Size i = 1; i < numYears; i++) {
58
59 Volatility vol = 0.1 + (0.01 * i);
60 vols.push_back(vol);
61
62 simpleQuotes.push_back(QuantLib::ext::make_shared<SimpleQuote>(vol));
63 quotes.push_back(Handle<Quote>(simpleQuotes.back()));
64
65 dates.push_back(Date(1, Dec, today.year() + i));
66 times.push_back(dc.yearFraction(today, dates.back()));
67 }
68
69
70 BlackVarianceCurve bvcBase(today, dates, vols, dc);
71 bvcBase.enableExtrapolation();
72
73
75 bvcTest.enableExtrapolation();
76
77 Real strike = 1.0;
78
79
80 for (Size i = 0; i < times.size(); ++i) {
81 BOOST_CHECK_CLOSE(bvcTest.blackVol(times[i], strike), vols[i], 1e-12);
82 BOOST_CHECK_CLOSE(bvcTest.blackVol(dates[i], strike), vols[i], 1e-12);
83 }
84
85
86 for (Time t = 0.1; t < numYears + 10.0; t += 0.1) {
87 BOOST_CHECK_CLOSE(bvcBase.blackVol(t, strike), bvcTest.blackVol(t, strike), 1e-12);
88 }
89
90
91 for (Size i = 0; i < simpleQuotes.size(); ++i) {
92 simpleQuotes[i]->setValue(simpleQuotes[i]->value() * 2.0);
93 }
94
95 for (Time t = 0.1; t < numYears + 10.0; t += 0.1) {
96 BOOST_CHECK_CLOSE(bvcBase.blackVol(t, strike), 0.5 * bvcTest.blackVol(t, strike), 1e-12);
97 }
98}
Black volatility curve modeled as variance curve.