Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
Functions
exactbachelierimpliedvolatility.cpp File Reference
#include "toplevelfixture.hpp"
#include <qle/models/exactbachelierimpliedvolatility.hpp>
#include <ql/pricingengines/blackformula.hpp>
#include <boost/make_shared.hpp>
#include <boost/test/unit_test.hpp>

Go to the source code of this file.

Functions

 BOOST_AUTO_TEST_CASE (testExactBachelierImpliedVolatility)
 

Function Documentation

◆ BOOST_AUTO_TEST_CASE()

BOOST_AUTO_TEST_CASE ( testExactBachelierImpliedVolatility  )

Definition at line 36 of file exactbachelierimpliedvolatility.cpp.

36 {
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}
Real exactBachelierImpliedVolatility(Option::Type optionType, Real strike, Real forward, Real tte, Real bachelierPrice, Real discount)
+ Here is the call graph for this function: