Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
Functions
blackvariancecurve.cpp File Reference
#include "toplevelfixture.hpp"
#include <boost/make_shared.hpp>
#include <boost/test/unit_test.hpp>
#include <ql/quotes/simplequote.hpp>
#include <ql/termstructures/volatility/equityfx/blackvariancecurve.hpp>
#include <ql/time/calendars/target.hpp>
#include <ql/time/daycounters/actualactual.hpp>
#include <qle/termstructures/blackvariancecurve3.hpp>

Go to the source code of this file.

Functions

 BOOST_AUTO_TEST_CASE (testBlackVarianceCurve)
 

Function Documentation

◆ BOOST_AUTO_TEST_CASE()

BOOST_AUTO_TEST_CASE ( testBlackVarianceCurve  )

Definition at line 37 of file blackvariancecurve.cpp.

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); // 11% at 1Y, 12% at 2Y
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 // Build a QuantLib::BlackVarianceCurve
70 BlackVarianceCurve bvcBase(today, dates, vols, dc);
71 bvcBase.enableExtrapolation();
72
73 // Build a QuantExt::BlackVarianceCurve3
74 BlackVarianceCurve3 bvcTest(settlementDays, cal, bdc, dc, times, quotes);
75 bvcTest.enableExtrapolation();
76
77 Real strike = 1.0; // this is all ATM so we don't care
78
79 // Check that bvcTest returns the expected values
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 // Now check that they give the same vols (including extrapolation)
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 // Now double the quotes
91 for (Size i = 0; i < simpleQuotes.size(); ++i) {
92 simpleQuotes[i]->setValue(simpleQuotes[i]->value() * 2.0);
93 }
94 // and check again
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.