Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
blacktriangulationatmvol.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2019 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/*! \file blacktriangulationatmvol.hpp
20 \brief Black volatility surface that implies an ATM vol based on triangulation
21 \ingroup termstructures
22 */
23#pragma once
24
25#include <ql/termstructures/volatility/equityfx/blackvoltermstructure.hpp>
27
28namespace QuantExt {
29using namespace QuantLib;
30
31//! Black volatility surface that implies an ATM vol based on triangulation
32/*! This class is used when one wants to proxy a volatility like XAU/EUR using
33 * XAU/USD, EUR/USD and a correlation. It uses the cosing rule.
34 * The correlation can be implied from a vol (if you had XAU/EUR) or historically estimated.
35 * This class is just ATM, otherwise there is a degree of freedom in selecting strikes.
36 *
37 * One application of this is SIMM sensis, where the vol for XAU/EUR must be broken down
38 * into XAU/USD and EUR/USD.
39 *
40 * Other methods for building a full surface exist, but to keep things simple we just do ATM
41 *
42 * \ingroup termstructures
43 */
44class BlackTriangulationATMVolTermStructure : public BlackVolatilityTermStructure {
45public:
46 //! Constructor takes two BlackVolTermStructure and a correlation
47 /*! Attributes like referenceDate, settlementDays, Calendar, etc are taken from vol1
48 */
49 BlackTriangulationATMVolTermStructure(const Handle<BlackVolTermStructure>& vol1,
50 const Handle<BlackVolTermStructure>& vol2,
51 const Handle<CorrelationTermStructure>& rho, const bool staticVol2 = false)
52 : BlackVolatilityTermStructure(vol1->businessDayConvention(), vol1->dayCounter()), vol1_(vol1), vol2_(vol2),
53 rho_(rho), staticVol2_(staticVol2) {
54 registerWith(vol1_);
55 registerWith(vol2_);
56 registerWith(rho_);
57 enableExtrapolation(vol1_->allowsExtrapolation() && vol2_->allowsExtrapolation());
58 }
59 //! \name TermStructure interface
60 //@{
61 const Date& referenceDate() const override { return vol1_->referenceDate(); }
62 Date maxDate() const override { return std::min(vol1_->maxDate(), vol2_->maxDate()); }
63 Natural settlementDays() const override { return vol1_->settlementDays(); }
64 Calendar calendar() const override { return vol1_->calendar(); }
65 //! \name Observer interface
66 //@{
67 void update() override { notifyObservers(); }
68 //@}
69 //! \name VolatilityTermStructure interface
70 //@{
71 Real minStrike() const override { return 0; }
72 Real maxStrike() const override { return QL_MAX_REAL; }
73 //@}
74 //! \name Visitability
75 //@{
76 virtual void accept(AcyclicVisitor&) override;
77 //@}
78protected:
79 virtual Volatility blackVolImpl(Time t, Real) const override {
80 Real c = rho_->correlation(t);
81 Volatility v1 = vol1_->blackVol(t, Null<Real>());
82 Real v2 = Null<Real>();
83 if (staticVol2_) {
84 if (auto tmp = staticVolCache_.find(t); tmp != staticVolCache_.end()) {
85 v2 = tmp->second;
86 } else {
87 v2 = vol2_->blackVol(t, Null<Real>());
88 staticVolCache_[t] = v2;
89 }
90 } else {
91 v2 = vol2_->blackVol(t, Null<Real>());
92 }
93 return std::sqrt(std::max(0.0, v1 * v1 + v2 * v2 - 2.0 * c * v1 * v2));
94 }
95
96private:
97 Handle<BlackVolTermStructure> vol1_;
98 Handle<BlackVolTermStructure> vol2_;
99 Handle<CorrelationTermStructure> rho_;
101 mutable std::map<double, double> staticVolCache_;
102};
103
104// inline definitions
105inline void BlackTriangulationATMVolTermStructure::accept(AcyclicVisitor& v) {
106 Visitor<BlackTriangulationATMVolTermStructure>* v1 =
107 dynamic_cast<Visitor<BlackTriangulationATMVolTermStructure>*>(&v);
108 if (v1 != 0)
109 v1->visit(*this);
110 else
111 BlackVolatilityTermStructure::accept(v);
112}
113} // namespace QuantExt
Black volatility surface that implies an ATM vol based on triangulation.
virtual Volatility blackVolImpl(Time t, Real) const override
BlackTriangulationATMVolTermStructure(const Handle< BlackVolTermStructure > &vol1, const Handle< BlackVolTermStructure > &vol2, const Handle< CorrelationTermStructure > &rho, const bool staticVol2=false)
Constructor takes two BlackVolTermStructure and a correlation.
virtual void accept(AcyclicVisitor &) override
Term structure of correlations.