Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
Functions
localvol.cpp File Reference
#include <boost/test/unit_test.hpp>
#include <boost/test/data/test_case.hpp>
#include <ored/scripting/scriptengine.hpp>
#include <ored/scripting/models/localvol.hpp>
#include <ored/scripting/staticanalyser.hpp>
#include <ored/scripting/scriptparser.hpp>
#include <ored/scripting/astprinter.hpp>
#include <ored/scripting/models/blackscholes.hpp>
#include <ored/scripting/models/dummymodel.hpp>
#include <oret/toplevelfixture.hpp>
#include <ored/model/localvolmodelbuilder.hpp>
#include <qle/termstructures/flatcorrelation.hpp>
#include <qle/methods/multipathgeneratorbase.hpp>
#include <ql/exercise.hpp>
#include <ql/time/daycounters/actualactual.hpp>
#include <ql/quotes/simplequote.hpp>
#include <ql/instruments/vanillaoption.hpp>
#include <ql/pricingengines/vanilla/analyticeuropeanengine.hpp>
#include <ql/processes/stochasticprocessarray.hpp>
#include <ql/termstructures/yield/flatforward.hpp>
#include <ql/termstructures/volatility/equityfx/blackconstantvol.hpp>
#include <ql/time/calendars/nullcalendar.hpp>
#include <ql/pricingengines/blackformula.hpp>
#include <ql/termstructures/volatility/sabr.hpp>
#include <iomanip>

Go to the source code of this file.

Functions

 BOOST_AUTO_TEST_CASE (testFlatVols)
 
 BOOST_AUTO_TEST_CASE (testSabrVols)
 

Function Documentation

◆ BOOST_AUTO_TEST_CASE() [1/2]

BOOST_AUTO_TEST_CASE ( testFlatVols  )

Definition at line 137 of file localvol.cpp.

137 {
138 BOOST_TEST_MESSAGE("Testing LocalVol with flat input vols...");
139
140 Date ref(7, May, 2019);
141 Settings::instance().evaluationDate() = ref;
142
143 std::vector<Date> expiries{ref + 1 * Months, ref + 3 * Months, ref + 6 * Months, ref + 9 * Months,
144 ref + 1 * Years, ref + 2 * Years, ref + 3 * Years, ref + 4 * Years,
145 ref + 5 * Years, ref + 7 * Years, ref + 10 * Years};
146
147 std::vector<Real> moneyness{-3.0, -2.0, -1.0, 0.0, 1.0, 2.0, 3.0};
148
149 Handle<YieldTermStructure> r(QuantLib::ext::make_shared<FlatForward>(0, NullCalendar(), 0.02, Actual365Fixed()));
150 Handle<YieldTermStructure> q(QuantLib::ext::make_shared<FlatForward>(0, NullCalendar(), 0.03, Actual365Fixed()));
151 Handle<BlackVolTermStructure> vol(QuantLib::ext::make_shared<BlackConstantVol>(0, NullCalendar(), 0.10, Actual365Fixed()));
152 Handle<Quote> spot(QuantLib::ext::make_shared<SimpleQuote>(100.0));
153
154 auto process = QuantLib::ext::make_shared<GeneralizedBlackScholesProcess>(spot, q, r, vol);
155
156 testCalibrationInstrumentRepricing(expiries, moneyness, process, 20, 10000, 0.30);
157}

◆ BOOST_AUTO_TEST_CASE() [2/2]

BOOST_AUTO_TEST_CASE ( testSabrVols  )

Definition at line 159 of file localvol.cpp.

159 {
160 BOOST_TEST_MESSAGE("Testing LocalVol with sabr input vols...");
161
162 Date ref(7, May, 2019);
163 Settings::instance().evaluationDate() = ref;
164
165 std::vector<Date> expiries{ref + 1 * Months, ref + 3 * Months, ref + 6 * Months, ref + 9 * Months,
166 ref + 1 * Years, ref + 2 * Years, ref + 3 * Years, ref + 4 * Years,
167 ref + 5 * Years, ref + 7 * Years, ref + 10 * Years};
168
169 std::vector<Real> moneyness{-3.0, -2.0, -1.0, 0.0, 1.0, 2.0, 3.0};
170
171 Handle<YieldTermStructure> r(QuantLib::ext::make_shared<FlatForward>(0, NullCalendar(), 0.02, Actual365Fixed()));
172 Handle<YieldTermStructure> q(QuantLib::ext::make_shared<FlatForward>(0, NullCalendar(), 0.03, Actual365Fixed()));
173
174 class SabrTestSurface : public BlackVolatilityTermStructure {
175 public:
176 SabrTestSurface(const Handle<Quote>& spot, const Handle<YieldTermStructure>& r,
177 const Handle<YieldTermStructure>& q)
178 : BlackVolatilityTermStructure(0, NullCalendar(), Following, ActualActual(ActualActual::ISDA)), spot_(spot), r_(r), q_(q) {}
179 Date maxDate() const override { return Date::maxDate(); }
180 Real minStrike() const override { return 0.0; }
181 Real maxStrike() const override { return QL_MAX_REAL; }
182
183 private:
184 Real blackVolImpl(Time maturity, Real strike) const override {
185 Real forward = spot_->value() / r_->discount(maturity) * q_->discount(maturity);
186 Real w2 = std::min(maturity, 10.0) / 10.0, w1 = 1.0 - w2;
187 Real alpha = 0.17 * w1 + 0.10 * w2;
188 Real beta = 0.99;
189 Real nu = 0.3 * w1 + 0.05 * w2;
190 Real rho = -0.2;
191 return sabrVolatility(strike, forward, maturity, alpha, beta, nu, rho);
192 }
193 Handle<Quote> spot_;
194 Handle<YieldTermStructure> r_, q_;
195 };
196
197 Handle<Quote> spot(QuantLib::ext::make_shared<SimpleQuote>(100.0));
198 Handle<BlackVolTermStructure> vol(QuantLib::ext::make_shared<SabrTestSurface>(spot, r, q));
199
200 auto process = QuantLib::ext::make_shared<GeneralizedBlackScholesProcess>(spot, q, r, vol);
201
202 testCalibrationInstrumentRepricing(expiries, moneyness, process, 20, 10000, 0.30);
203}
Time maturity
Definition: utilities.cpp:66