Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
blackvariancesurfacemoneyness.hpp
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
19/*! \file blackvariancesurfacemoneyness.hpp
20 \brief Black volatility surface based on forward moneyness
21 \ingroup termstructures
22 */
23
24#ifndef quantext_black_variance_surface_moneyness_hpp
25#define quantext_black_variance_surface_moneyness_hpp
26
27#include <ql/math/interpolation.hpp>
28#include <ql/math/interpolations/interpolation2d.hpp>
29#include <ql/patterns/lazyobject.hpp>
30#include <ql/quote.hpp>
31#include <ql/termstructures/volatility/equityfx/blackvoltermstructure.hpp>
32#include <ql/termstructures/yieldtermstructure.hpp>
33#include <ql/time/daycounters/actual365fixed.hpp>
34
35namespace QuantExt {
36using namespace QuantLib;
37
38//! Abstract Black volatility surface based on moneyness (moneyness defined in subclasses)
39/*! \todo times should not be in the interface here. There should be a Dates based constructor and a Periods
40 based constructor. This would cover the cases of fixed expiry options and options specified in terms
41 of tenors. The times should be calculated internally in the class. What is maxDate() when you use times
42 in the interface?
43
44 \ingroup termstructures
45*/
47public:
48 /*! Moneyness can be defined here as spot moneyness, i.e. K/S
49 * or forward moneyness, ie K/F
50 */
51 BlackVarianceSurfaceMoneyness(const Calendar& cal, const Handle<Quote>& spot, const std::vector<Time>& times,
52 const std::vector<Real>& moneyness,
53 const std::vector<std::vector<Handle<Quote> > >& blackVolMatrix,
54 const DayCounter& dayCounter, bool stickyStrike, bool flatExtrapMoneyness = false);
55
56 //! Moneyness variance surface with a fixed reference date.
57 BlackVarianceSurfaceMoneyness(const Date& referenceDate, const Calendar& cal, const Handle<Quote>& spot,
58 const std::vector<Time>& times, const std::vector<Real>& moneyness,
59 const std::vector<std::vector<Handle<Quote> > >& blackVolMatrix,
60 const DayCounter& dayCounter, bool stickyStrike, bool flatExtrapMoneyness = false);
61
62 //! \name TermStructure interface
63 //@{
64 Date maxDate() const override { return Date::maxDate(); }
65 //@}
66 //! \name VolatilityTermStructure interface
67 //@{
68 Real minStrike() const override { return 0; }
69 Real maxStrike() const override { return QL_MAX_REAL; }
70 //@}
71 //! \name Observer interface
72 //@{
73 void update() override;
74 //@}
75 //! \name LazyObject interface
76 //@{
77 void performCalculations() const override;
78 //@}
79 //! \name Visitability
80 //@{
81 virtual void accept(AcyclicVisitor&) override;
82 //@}
83
84 //! \name Inspectors
85 //@{
86 std::vector<QuantLib::Real> moneyness() const { return moneyness_; }
87 //@}
88
89protected:
90 virtual Real moneyness(Time t, Real strike) const = 0;
92 Handle<Quote> spot_;
93 std::vector<Time> times_;
94 std::vector<Real> moneyness_;
96
97private:
98 // Shared initialisation
99 void init();
100
101 Real blackVarianceMoneyness(Time t, Real moneyness) const;
102 virtual Real blackVarianceImpl(Time t, Real strike) const override;
103 std::vector<std::vector<Handle<Quote> > > quotes_;
104 mutable Matrix variances_;
105 mutable Interpolation2D varianceSurface_;
106};
107
108// inline definitions
109
110inline void BlackVarianceSurfaceMoneyness::accept(AcyclicVisitor& v) {
111 Visitor<BlackVarianceSurfaceMoneyness>* v1 = dynamic_cast<Visitor<BlackVarianceSurfaceMoneyness>*>(&v);
112 if (v1 != 0)
113 v1->visit(*this);
114 else
115 BlackVarianceTermStructure::accept(v);
116}
117
118//! Black volatility surface based on spot moneyness
119//! \ingroup termstructures
121public:
122 /*! Moneyness is defined here as spot moneyness, i.e. K/S */
123
124 BlackVarianceSurfaceMoneynessSpot(const Calendar& cal, const Handle<Quote>& spot, const std::vector<Time>& times,
125 const std::vector<Real>& moneyness,
126 const std::vector<std::vector<Handle<Quote> > >& blackVolMatrix,
127 const DayCounter& dayCounter, bool stickyStrike = false,
128 bool flatExtrapMoneyness = false);
129
130 //! Spot moneyness variance surface with a fixed reference date.
131 BlackVarianceSurfaceMoneynessSpot(const Date& referenceDate, const Calendar& cal, const Handle<Quote>& spot,
132 const std::vector<Time>& times, const std::vector<Real>& moneyness,
133 const std::vector<std::vector<Handle<Quote> > >& blackVolMatrix,
134 const DayCounter& dayCounter, bool stickyStrike = false,
135 bool flatExtrapMoneyness = false);
136
137private:
138 virtual Real moneyness(Time t, Real strike) const override;
139};
140
141//! Black volatility surface based on forward moneyness
142//! \ingroup termstructures
144public:
145 /*! Moneyness is defined here as forward moneyness, ie K/F */
146 BlackVarianceSurfaceMoneynessForward(const Calendar& cal, const Handle<Quote>& spot, const std::vector<Time>& times,
147 const std::vector<Real>& moneyness,
148 const std::vector<std::vector<Handle<Quote> > >& blackVolMatrix,
149 const DayCounter& dayCounter, const Handle<YieldTermStructure>& forTS,
150 const Handle<YieldTermStructure>& domTS, bool stickyStrike = false,
151 bool flatExtrapMoneyness = false);
152
153 //! Forward moneyness variance surface with a fixed reference date.
154 BlackVarianceSurfaceMoneynessForward(const Date& referenceDate, const Calendar& cal, const Handle<Quote>& spot,
155 const std::vector<Time>& times, const std::vector<Real>& moneyness,
156 const std::vector<std::vector<Handle<Quote> > >& blackVolMatrix,
157 const DayCounter& dayCounter, const Handle<YieldTermStructure>& forTS,
158 const Handle<YieldTermStructure>& domTS, bool stickyStrike = false,
159 bool flatExtrapMoneyness = false);
160
161private:
162 // Shared initialisation
163 void init();
164
165 virtual Real moneyness(Time t, Real strike) const override;
166 Handle<YieldTermStructure> forTS_; // calculates fwd if StickyStrike==false
167 Handle<YieldTermStructure> domTS_;
168 std::vector<Real> forwards_; // cache fwd values if StickyStrike==true
169 QuantLib::Interpolation forwardCurve_;
170};
171
172} // namespace QuantExt
173
174#endif
Abstract Black volatility surface based on moneyness (moneyness defined in subclasses)
Real blackVarianceMoneyness(Time t, Real moneyness) const
std::vector< QuantLib::Real > moneyness() const
virtual void accept(AcyclicVisitor &) override
virtual Real blackVarianceImpl(Time t, Real strike) const override
std::vector< std::vector< Handle< Quote > > > quotes_
virtual Real moneyness(Time t, Real strike) const =0