20#include <boost/make_shared.hpp>
21#include <boost/test/unit_test.hpp>
22#include <ql/quotes/simplequote.hpp>
23#include <ql/termstructures/volatility/equityfx/blackvariancecurve.hpp>
24#include <ql/time/calendars/target.hpp>
25#include <ql/time/daycounters/actualactual.hpp>
28using namespace boost::unit_test_framework;
35BOOST_AUTO_TEST_SUITE(BlackVarianceCurveTest)
39 BOOST_TEST_MESSAGE(
"Testing QuantExt::BlackVarianceCurve3...");
42 Settings::instance().evaluationDate() = Date(1, Dec, 2015);
43 Date today = Settings::instance().evaluationDate();
45 Natural settlementDays = 0;
46 Calendar cal = TARGET();
47 BusinessDayConvention bdc = Following;
48 DayCounter dc = ActualActual(ActualActual::ISDA);
52 vector<Volatility> vols;
53 vector<QuantLib::ext::shared_ptr<SimpleQuote> > simpleQuotes;
54 vector<Handle<Quote> > quotes;
57 for (Size i = 1; i < numYears; i++) {
59 Volatility vol = 0.1 + (0.01 * i);
62 simpleQuotes.push_back(QuantLib::ext::make_shared<SimpleQuote>(vol));
63 quotes.push_back(Handle<Quote>(simpleQuotes.back()));
65 dates.push_back(Date(1, Dec, today.year() + i));
66 times.push_back(dc.yearFraction(today, dates.back()));
70 BlackVarianceCurve bvcBase(today, dates, vols, dc);
71 bvcBase.enableExtrapolation();
75 bvcTest.enableExtrapolation();
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);
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);
91 for (Size i = 0; i < simpleQuotes.size(); ++i) {
92 simpleQuotes[i]->setValue(simpleQuotes[i]->value() * 2.0);
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);
100BOOST_AUTO_TEST_SUITE_END()
102BOOST_AUTO_TEST_SUITE_END()
Black volatility curve modeled as variance curve.
BOOST_AUTO_TEST_CASE(testBlackVarianceCurve)
Black volatility curve modeled as variance curve.
Fixture that can be used at top level.