| 1 | /* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
| 2 | |
| 3 | /* |
| 4 | Copyright (C) 2014 Peter Caspers |
| 5 | |
| 6 | This file is part of QuantLib, a free-software/open-source library |
| 7 | for financial quantitative analysts and developers - http://quantlib.org/ |
| 8 | |
| 9 | QuantLib is free software: you can redistribute it and/or modify it |
| 10 | under the terms of the QuantLib license. You should have received a |
| 11 | copy of the license along with this program; if not, please email |
| 12 | <quantlib-dev@lists.sf.net>. The license is also available online at |
| 13 | <http://quantlib.org/license.shtml>. |
| 14 | |
| 15 | This program is distributed in the hope that it will be useful, but WITHOUT |
| 16 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 17 | FOR A PARTICULAR PURPOSE. See the license for more details. |
| 18 | */ |
| 19 | |
| 20 | #include "zabr.hpp" |
| 21 | #include "utilities.hpp" |
| 22 | #include <ql/termstructures/volatility/sabrsmilesection.hpp> |
| 23 | #include <ql/experimental/volatility/zabrsmilesection.hpp> |
| 24 | |
| 25 | using namespace QuantLib; |
| 26 | using namespace boost::unit_test_framework; |
| 27 | |
| 28 | void ZabrTest::testConsistency() { |
| 29 | BOOST_TEST_MESSAGE("Testing the consistency of ZABR interpolation..." ); |
| 30 | |
| 31 | Real tol = 1E-4; |
| 32 | |
| 33 | Real alpha = 0.08; |
| 34 | Real beta = 0.70; |
| 35 | Real nu = 0.20; |
| 36 | Real rho = -0.30; |
| 37 | Real tau = 5.0; |
| 38 | Real forward = 0.03; |
| 39 | |
| 40 | SabrSmileSection sabr(tau, forward, |
| 41 | {alpha, beta, nu, rho}); |
| 42 | |
| 43 | ZabrSmileSection<ZabrShortMaturityLognormal> zabr0(tau, forward, |
| 44 | {alpha, beta, nu, rho, 1.0}); |
| 45 | |
| 46 | ZabrSmileSection<ZabrShortMaturityNormal> zabr1(tau, forward, |
| 47 | {alpha, beta, nu, rho, 1.0}); |
| 48 | |
| 49 | ZabrSmileSection<ZabrLocalVolatility> zabr2(tau, forward, |
| 50 | {alpha, beta, nu, rho, 1.0}); |
| 51 | |
| 52 | // for full finite prices reduce the number of intermediate points here |
| 53 | // below the recommended value to speed up the test |
| 54 | ZabrSmileSection<ZabrFullFd> zabr3(tau, forward, |
| 55 | {alpha, beta, nu, rho, 1.0}, |
| 56 | std::vector<Real>(), 2); |
| 57 | |
| 58 | Real k = 0.0001; |
| 59 | while (k <= 0.70) { |
| 60 | Real c0 = sabr.optionPrice(strike: k); |
| 61 | Real z0 = zabr0.optionPrice(strike: k); |
| 62 | Real z1 = zabr1.optionPrice(strike: k); |
| 63 | Real z2 = zabr2.optionPrice(strike: k); |
| 64 | Real z3 = zabr3.optionPrice(strike: k); |
| 65 | if (std::fabs(x: z0 - c0) > tol) |
| 66 | BOOST_ERROR("Zabr short maturity lognormal expansion price " |
| 67 | "(" |
| 68 | << z0 << ") deviates from Sabr Hagan 2002 price " |
| 69 | "by " << (z0 - c0)); |
| 70 | if (std::fabs(x: z1 - c0) > tol) |
| 71 | BOOST_ERROR("Zabr short maturity normal expansion price " |
| 72 | "(" |
| 73 | << z1 << ") deviates from Sabr Hagan 2002 price " |
| 74 | "by " << (z1 - c0)); |
| 75 | if (std::fabs(x: z2 - c0) > tol) |
| 76 | BOOST_ERROR("Zabr local volatility price " |
| 77 | "(" |
| 78 | << z2 << ") deviates from Sabr Hagan 2002 price " |
| 79 | "by " << (z2 - c0)); |
| 80 | if (std::fabs(x: z3 - c0) > tol) |
| 81 | BOOST_ERROR("Zabr full finite difference price " |
| 82 | "(" |
| 83 | << z3 << ") deviates from Sabr Hagan 2002 price " |
| 84 | "by " << (z3 - c0)); |
| 85 | k += 0.0001; |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | test_suite *ZabrTest::suite(SpeedLevel speed) { |
| 90 | auto* suite = BOOST_TEST_SUITE("Zabr model tests" ); |
| 91 | |
| 92 | if (speed == Slow) { |
| 93 | suite->add(QUANTLIB_TEST_CASE(&ZabrTest::testConsistency)); |
| 94 | } |
| 95 | |
| 96 | return suite; |
| 97 | } |
| 98 | |