Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
blackmonotonevarvoltermstructure.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 blackmonotonevarvoltermstructure.hpp
20 \brief Black volatility surface that monotonises the variance in an existing surface
21 \ingroup termstructures
22*/
23
24#ifndef quantext_black_monotone_var_vol_termstructure_hpp
25#define quantext_black_monotone_var_vol_termstructure_hpp
26
27#include <ql/math/array.hpp>
28#include <ql/math/interpolations/backwardflatinterpolation.hpp>
29#include <ql/math/rounding.hpp>
30#include <ql/termstructures/volatility/equityfx/blackvoltermstructure.hpp>
31
32namespace QuantExt {
33using namespace QuantLib;
34
35//! Black volatility surface that monotonises the variance in an existing surface
36/*! This class is used when monotonic variance is required
37
38 \ingroup termstructures
39*/
41public:
42 //! Constructor takes a BlackVolTermStructure and an array of time points which required monotonic variance
43 /*! This will work with both a floating and fixed reference date underlying surface,
44 since we are reimplementing the reference date and update methods */
45 BlackMonotoneVarVolTermStructure(const Handle<BlackVolTermStructure>& vol, const std::vector<Time>& timePoints)
46 : BlackVolTermStructure(vol->businessDayConvention(), vol->dayCounter()), vol_(vol), timePoints_(timePoints) {
47 registerWith(vol_);
48 }
49
50 //! return the underlying vol surface
51 const Handle<BlackVolTermStructure>& underlyingVol() const { return vol_; }
52
53 //! \name TermStructure interface
54 //@{
55 const Date& referenceDate() const override { return vol_->referenceDate(); }
56 Date maxDate() const override { return vol_->maxDate(); }
57 Natural settlementDays() const override { return vol_->settlementDays(); }
58 Calendar calendar() const override { return vol_->calendar(); }
59 //! \name Observer interface
60 //@{
61 void update() override {
62 monoVars_.clear();
63 notifyObservers();
64 }
65 //@}
66 //! \name VolatilityTermStructure interface
67 //@{
68 Real minStrike() const override { return vol_->minStrike(); }
69 Real maxStrike() const override { return vol_->maxStrike(); }
70 //@}
71 //! \name Visitability
72 //@{
73 virtual void accept(AcyclicVisitor&) override;
74 //@}
75protected:
76 virtual Real blackVarianceImpl(Time t, Real strike) const override { return getMonotoneVar(t, strike); }
77 virtual Volatility blackVolImpl(Time t, Real strike) const override { return std::sqrt(getMonotoneVar(t, strike) / t); }
78
79 void setMonotoneVar(const Real& strike) const {
80 QL_REQUIRE(timePoints_.size() > 0, "timePoints cannot be empty");
81 std::vector<Real> vars(timePoints_.size());
82 vars[0] = vol_->blackVariance(timePoints_[0], strike);
83 for (Size i = 1; i < timePoints_.size(); i++) {
84 Real var = vol_->blackVariance(timePoints_[i], strike);
85 var = std::max(var, vars[i - 1]);
86 vars[i] = var;
87 }
88 monoVars_[strike] = vars;
89 }
90
91 Real getMonotoneVar(const Time& t, const Real& strike) const {
92 if (monoVars_.find(strike) == monoVars_.end())
93 setMonotoneVar(strike);
94 BackwardFlatInterpolation interpolation(timePoints_.begin(), timePoints_.end(), monoVars_[strike].begin());
95 return interpolation(t);
96 }
97
98private:
99 Handle<BlackVolTermStructure> vol_;
100 std::vector<Time> timePoints_;
101
103 public:
104 bool operator()(const double& left, const double& right) const {
105 return left < right && !QuantLib::close_enough(left, right);
106 }
107 };
108
109 mutable std::map<Real, std::vector<Real>, closeDouble> monoVars_;
110};
111
112// inline definitions
113inline void BlackMonotoneVarVolTermStructure::accept(AcyclicVisitor& v) {
114 Visitor<BlackMonotoneVarVolTermStructure>* v1 = dynamic_cast<Visitor<BlackMonotoneVarVolTermStructure>*>(&v);
115 if (v1 != 0)
116 v1->visit(*this);
117 else
119}
120} // namespace QuantExt
121
122#endif
bool operator()(const double &left, const double &right) const
Black volatility surface that monotonises the variance in an existing surface.
BlackMonotoneVarVolTermStructure(const Handle< BlackVolTermStructure > &vol, const std::vector< Time > &timePoints)
Constructor takes a BlackVolTermStructure and an array of time points which required monotonic varian...
const Handle< BlackVolTermStructure > & underlyingVol() const
return the underlying vol surface
std::map< Real, std::vector< Real >, closeDouble > monoVars_
Real getMonotoneVar(const Time &t, const Real &strike) const
virtual Volatility blackVolImpl(Time t, Real strike) const override
virtual Real blackVarianceImpl(Time t, Real strike) const override