Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
exactbachelierimpliedvolatility.cpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2020 Quaternion Risk Management Ltd
3 All rights reserved.
4
5 This file is part of ORE, a free-software/open-source library
6 for transparent pricing and risk analysis - http://opensourcerisk.org
7
8 ORE is free software: you can redistribute it and/or modify it
9 under the terms of the Modified BSD License. You should have received a
10 copy of the license along with this program.
11 The license is also available online at <http://opensourcerisk.org>
12
13 This program is distributed on the basis that it will form a useful
14 contribution to risk analytics and model standardisation, but WITHOUT
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the license for more details.
17*/
18
19#include "toplevelfixture.hpp"
20
22
23#include <ql/pricingengines/blackformula.hpp>
24
25#include <boost/make_shared.hpp>
26#include <boost/test/unit_test.hpp>
27
28using namespace QuantLib;
29using namespace QuantExt;
30using namespace boost::unit_test_framework;
31
32BOOST_FIXTURE_TEST_SUITE(QuantExtTestSuite, qle::test::TopLevelFixture)
33
34BOOST_AUTO_TEST_SUITE(ExactBachelierImpliedVolatilityTest)
35
36BOOST_AUTO_TEST_CASE(testExactBachelierImpliedVolatility) {
37
38 BOOST_TEST_MESSAGE("Testing exact Bachelier implied volatility...");
39
40 Real tolerance = 1E-4; // percent, i.e. we test for 1E-6 relative error
41 Real forward = 0.05; // fix the forward, only the difference forward - strike matters
42
43 for (Real strikeSpread = -0.10; strikeSpread < 0.10 + 1E-5; strikeSpread += 0.001) {
44 Real strike = forward + strikeSpread;
45 for (Real vol = 0.0; vol < 0.02 + 1E-5; vol += 0.001) {
46 for (Real tte = 0.001; tte < 51.0; tte += 0.1) {
47 Real stdDev = std::sqrt(tte) * vol;
48 Real call = bachelierBlackFormula(Option::Call, strike, forward, stdDev);
49 Real put = bachelierBlackFormula(Option::Put, strike, forward, stdDev);
50 if (std::abs(call) < 1E-12 || std::abs(put) < 1E-12)
51 continue;
52 Real impliedVolCall = exactBachelierImpliedVolatility(Option::Call, strike, forward, tte, call);
53 Real impliedVolPut = exactBachelierImpliedVolatility(Option::Put, strike, forward, tte, put);
54 BOOST_CHECK_CLOSE(vol, impliedVolCall, tolerance);
55 BOOST_CHECK_CLOSE(vol, impliedVolPut, tolerance);
56 }
57 }
58 }
59}
60
61BOOST_AUTO_TEST_SUITE_END()
62
63BOOST_AUTO_TEST_SUITE_END()
implied bachelier volatility based on Jaeckel, Implied Normal Volatility, 2017
Real exactBachelierImpliedVolatility(Option::Type optionType, Real strike, Real forward, Real tte, Real bachelierPrice, Real discount)
BOOST_AUTO_TEST_CASE(testExactBachelierImpliedVolatility)
Fixture that can be used at top level.