Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
blackvolsurfaceproxy.cpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2017 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
20
21using namespace QuantLib;
22
23namespace QuantExt {
24
26 const QuantLib::ext::shared_ptr<BlackVolTermStructure>& proxySurface, const QuantLib::ext::shared_ptr<EqFxIndexBase>& index,
27 const QuantLib::ext::shared_ptr<EqFxIndexBase>& proxyIndex, const QuantLib::ext::shared_ptr<BlackVolTermStructure>& fxSurface,
28 const QuantLib::ext::shared_ptr<FxIndex>& fxIndex, const QuantLib::ext::shared_ptr<CorrelationTermStructure>& correlation)
29 : BlackVolatilityTermStructure(0, proxySurface->calendar(), proxySurface->businessDayConvention(),
30 proxySurface->dayCounter()),
31 proxySurface_(proxySurface), index_(index), proxyIndex_(proxyIndex), fxSurface_(fxSurface),
32 fxIndex_(fxIndex), correlation_(correlation) {
33
34 if (proxySurface->allowsExtrapolation())
35 this->enableExtrapolation();
36
37 registerWith(proxySurface);
38 registerWith(index);
39 registerWith(proxyIndex);
40}
41
42Volatility BlackVolatilitySurfaceProxy::blackVolImpl(Time t, Real strike) const {
43
44 t = std::max(t, 1E-6);
45
46 Volatility vol;
47 if (fxSurface_) {
48 // Get the Fx forward value at time t, and hence the ATM vol
49 Real fxForward = fxIndex_->forecastFixing(t);
50 Volatility fxVol = fxSurface_->blackVol(t, fxForward);
51
52 // Get the ATM vol for the proxy surface
53 Volatility proxyAtmVol = proxySurface_->blackVol(t, proxyIndex_->forecastFixing(t));
54
55 // Convert the atm vol for this surface using sqrt( sigma^2 + sigma_X^2 + 2 rho sigma sigma_X)
56 Volatility atmVol = sqrt(proxyAtmVol * proxyAtmVol + fxVol * fxVol + 2 * correlation_->correlation(t) * proxyAtmVol * fxVol);
57
58 // Get the moneyness in this surface of the strike requested
59 Real forward = index_->forecastFixing(t);
60 Real moneyness = std::log(strike / forward) / (atmVol * sqrt(t));
61
62 // Find the strike in the proxy surface that gives the same moneyness
63 Real proxyForward = proxyIndex_->forecastFixing(t);
64 Real proxyStrike = proxyForward * exp(moneyness * proxyAtmVol * sqrt(t));
65
66 // Look up the vol in the proxy surface for the proxyStrike and convert using sqrt( sigma^2 + sigma_X^2 + 2 rho sigma sigma_X)
67 Volatility proxyVol = proxySurface_->blackVol(t, proxyStrike);
68 vol = sqrt(proxyVol * proxyVol + fxVol * fxVol + 2 * correlation_->correlation(t) * proxyVol * fxVol);
69
70 } else {
71 Real adjustedStrike = strike * proxyIndex_->forecastFixing(t) / index_->forecastFixing(t);
72 vol = proxySurface_->blackVol(t, adjustedStrike);
73 }
74 return vol;
75}
76
78 return proxySurface_->minStrike() * index_->forecastFixing(0.0) / proxyIndex_->forecastFixing(0.0);
79}
80
82 return proxySurface_->maxStrike() * index_->forecastFixing(0.0) / proxyIndex_->forecastFixing(0.0);
83}
84
85} // namespace QuantExt
Wrapper class for a BlackVolTermStructure when using proxy vols.
BlackVolatilitySurfaceProxy(const QuantLib::ext::shared_ptr< BlackVolTermStructure > &proxySurface, const QuantLib::ext::shared_ptr< EqFxIndexBase > &index, const QuantLib::ext::shared_ptr< EqFxIndexBase > &proxyIndex, const QuantLib::ext::shared_ptr< BlackVolTermStructure > &fxSurface=nullptr, const QuantLib::ext::shared_ptr< FxIndex > &fxIndex=nullptr, const QuantLib::ext::shared_ptr< CorrelationTermStructure > &correlation=nullptr)
Constructor. This is a floating term structure (settlement days is zero)
QuantLib::ext::shared_ptr< EqFxIndexBase > index_
QuantLib::ext::shared_ptr< FxIndex > fxIndex_
QuantLib::ext::shared_ptr< BlackVolTermStructure > proxySurface_
QuantLib::ext::shared_ptr< EqFxIndexBase > proxyIndex_
QuantLib::ext::shared_ptr< CorrelationTermStructure > correlation_
QuantLib::ext::shared_ptr< BlackVolTermStructure > fxSurface_
QuantLib::ext::shared_ptr< EqFxIndexBase > proxyIndex() const
Volatility blackVolImpl(Time t, Real strike) const override
QuantLib::ext::shared_ptr< EqFxIndexBase > index() const
QuantLib::ext::shared_ptr< BlackVolTermStructure > proxySurface() const
RandomVariable sqrt(RandomVariable x)
CompiledFormula exp(CompiledFormula x)